Skip to content

Commit

Permalink
move code to dedicated files
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan6419846 committed Dec 8, 2023
1 parent c26fd00 commit ca30948
Show file tree
Hide file tree
Showing 12 changed files with 1,469 additions and 927 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Development version

* Move code to dedicated files.

# Version 0.4.0 - 2023-11-21

* Switch to *mypy* strict mode.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Example: To see the licenses of a specific *joblib* package version, use somethi
python -m license_tools --package "joblib==1.2.0"
```

If you want to use the package as a library, have a look at the `license_tools.scancode_tools.run` method for example to see how everything interacts.
If you want to use the package as a library, have a look at the `license_tools.retrieval.run` method for example to see how everything interacts.

## License

Expand Down
68 changes: 54 additions & 14 deletions license_tools/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import argparse

from license_tools import scancode_tools
from license_tools import retrieval


def main() -> None:
Expand All @@ -16,38 +16,78 @@ def main() -> None:

source_group = parser.add_argument_group("Artifact source")
source_group = source_group.add_mutually_exclusive_group(required=False)
source_group.add_argument("--directory", action="store", type=str, help="Directory to work on.")
source_group.add_argument("--file", action="store", type=str, help="File to work on.")
source_group.add_argument("--archive", action="store", type=str, help="Archive file to work on.")
source_group.add_argument("--package", action="store", type=str, help="Package specification to use.")
source_group.add_argument("--url", action="store", type=str, help="Download URL to use.")
source_group.add_argument(
"--directory", action="store", type=str, help="Directory to work on."
)
source_group.add_argument(
"--file", action="store", type=str, help="File to work on."
)
source_group.add_argument(
"--archive", action="store", type=str, help="Archive file to work on."
)
source_group.add_argument(
"--package", action="store", type=str, help="Package specification to use."
)
source_group.add_argument(
"--url", action="store", type=str, help="Download URL to use."
)

parser.add_argument(
"--index-url", action="store", type=str, required=False, default="", help="PyPI index URL to use."
"--index-url",
action="store",
type=str,
required=False,
default="",
help="PyPI index URL to use.",
)
parser.add_argument(
"--jobs", action="store", type=int, required=False, default=4, help="Parallel jobs to use."
"--jobs",
action="store",
type=int,
required=False,
default=4,
help="Parallel jobs to use.",
)

parser.add_argument(
"--retrieve-copyrights", action="store_true", required=False, default=False, help="Retrieve copyrights."
"--retrieve-copyrights",
action="store_true",
required=False,
default=False,
help="Retrieve copyrights.",
)
parser.add_argument(
"--retrieve-emails", action="store_true", required=False, default=False, help="Retrieve e-mails."
"--retrieve-emails",
action="store_true",
required=False,
default=False,
help="Retrieve e-mails.",
)
parser.add_argument(
"--retrieve-file-info", action="store_true", required=False, default=False, help="Retrieve file information."
"--retrieve-file-info",
action="store_true",
required=False,
default=False,
help="Retrieve file information.",
)
parser.add_argument(
"--retrieve-urls", action="store_true", required=False, default=False, help="Retrieve URLs."
"--retrieve-urls",
action="store_true",
required=False,
default=False,
help="Retrieve URLs.",
)
parser.add_argument(
"--retrieve-ldd-data", action="store_true", required=False, default=False, help="Retrieve shared object linking data."
"--retrieve-ldd-data",
action="store_true",
required=False,
default=False,
help="Retrieve shared object linking data.",
)

arguments = parser.parse_args()

scancode_tools.run(
retrieval.run(
directory=arguments.directory,
file_path=arguments.file,
archive_path=arguments.archive,
Expand Down
1 change: 1 addition & 0 deletions license_tools/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NOT_REQUESTED = object()
26 changes: 26 additions & 0 deletions license_tools/linking_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (c) stefan6419846. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.

"""
Tools related to binary linking.
"""

from __future__ import annotations

import subprocess
from pathlib import Path


def check_shared_objects(path: Path) -> str | None:
"""
Check which other shared objects a shared object links to.
:param path: The file path to analyze.
:return: The analysis results if the path points to a shared object, `None` otherwise.
"""
# TODO: Handle binary files here as well (like `/usr/bin/bc`).
if path.suffix != ".so" and not (path.suffixes and path.suffixes[0] == ".so"):
return None
output = subprocess.check_output(["ldd", path], stderr=subprocess.PIPE)
return output.decode("UTF-8")
Loading

0 comments on commit ca30948

Please sign in to comment.