Skip to content

Commit

Permalink
updated load_files to omit the path to workspace if specified (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
flowstate authored Jan 24, 2025
1 parent 0f39e43 commit 7f00f40
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion socketdev/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


__author__ = "socket.dev"
__version__ = "1.0.14"
__version__ = "1.0.15"
__all__ = ["socketdev"]


Expand Down
4 changes: 2 additions & 2 deletions socketdev/fullscans/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def get(org_slug: str, params: dict) -> dict:
return result

@staticmethod
def post(files: list, params: dict) -> dict:
def post(files: list, params: dict, workspace: str = None) -> dict:
loaded_files = []
loaded_files = load_files(files, loaded_files)
loaded_files = load_files(files, loaded_files, workspace)

params_arg = FullScans.create_params_string(params)

Expand Down
18 changes: 16 additions & 2 deletions socketdev/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,29 @@ def fix_file_path(files) -> list:
fixed_files.append(file)
return fixed_files



def load_files(files: list, loaded_files: list) -> list:

def load_files(files: list, loaded_files: list, workspace: str = None) -> list:
for file in files:
if platform.system() == "Windows":
file = file.replace("\\", "/")
if "/" in file:
path, name = file.rsplit("/", 1)
else:
path = "."
name = file
full_path = f"{path}/{name}"
payload = (full_path, (name, open(full_path, "rb")))

# Calculate key based on workspace if provided
if workspace and full_path.startswith(workspace):
key = full_path[len(workspace):]
key = key.lstrip("/")
key = key.lstrip("./")
else:
key = full_path

payload = (key, (name, open(full_path, "rb")))
loaded_files.append(payload)
return loaded_files

Expand Down

0 comments on commit 7f00f40

Please sign in to comment.