Skip to content

Commit 161c551

Browse files
authored
Changes to use black Python formatter (#671)
1 parent b099433 commit 161c551

26 files changed

Lines changed: 2935 additions & 2704 deletions

.github/workflows/lint.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Check source.
2+
name: lint
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
permissions: read-all
11+
jobs:
12+
black:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v6
16+
- name: Check format of Python code
17+
uses: psf/black@stable
18+
with:
19+
options: "--check"
20+
src: "."
21+
pylint:
22+
runs-on: ubuntu-latest
23+
strategy:
24+
matrix:
25+
python-version: ['3.14']
26+
container:
27+
image: ubuntu:26.04
28+
steps:
29+
- uses: actions/checkout@v6
30+
- name: Set up container
31+
env:
32+
DEBIAN_FRONTEND: noninteractive
33+
run: |
34+
apt-get update -q
35+
apt-get install -y libterm-readline-gnu-perl locales software-properties-common
36+
locale-gen en_US.UTF-8
37+
ln -f -s /usr/share/zoneinfo/UTC /etc/localtime
38+
- name: Install dependencies
39+
env:
40+
DEBIAN_FRONTEND: noninteractive
41+
run: |
42+
add-apt-repository -y universe
43+
add-apt-repository -y ppa:deadsnakes/ppa
44+
add-apt-repository -y ppa:gift/dev
45+
apt-get update -q
46+
apt-get install -y build-essential git pkg-config python${{ matrix.python-version }} python${{ matrix.python-version }}-dev python${{ matrix.python-version }}-venv python3-pip python3-setuptools python3-yaml tox
47+
- name: Run linter
48+
env:
49+
LANG: en_US.UTF-8
50+
run: |
51+
tox -e pylint
52+
yamllint:
53+
runs-on: ubuntu-latest
54+
strategy:
55+
matrix:
56+
python-version: ['3.12']
57+
steps:
58+
- uses: actions/checkout@v6
59+
- name: Set up Python ${{ matrix.python-version }}
60+
uses: actions/setup-python@v6
61+
with:
62+
python-version: ${{ matrix.python-version }}
63+
- name: Install tox
64+
run: |
65+
python -m pip install tox
66+
- name: Run linter
67+
run: |
68+
tox -e yamllint

.github/workflows/test_tox.yml

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -85,34 +85,3 @@ jobs:
8585
uses: codecov/codecov-action@v6
8686
with:
8787
token: ${{ secrets.CODECOV_TOKEN }}
88-
lint:
89-
runs-on: ubuntu-latest
90-
strategy:
91-
matrix:
92-
python-version: ['3.14']
93-
container:
94-
image: ubuntu:26.04
95-
steps:
96-
- uses: actions/checkout@v6
97-
- name: Set up container
98-
env:
99-
DEBIAN_FRONTEND: noninteractive
100-
run: |
101-
apt-get update -q
102-
apt-get install -y libterm-readline-gnu-perl locales software-properties-common
103-
locale-gen en_US.UTF-8
104-
ln -f -s /usr/share/zoneinfo/UTC /etc/localtime
105-
- name: Install dependencies
106-
env:
107-
DEBIAN_FRONTEND: noninteractive
108-
run: |
109-
add-apt-repository -y universe
110-
add-apt-repository -y ppa:deadsnakes/ppa
111-
add-apt-repository -y ppa:gift/dev
112-
apt-get update -q
113-
apt-get install -y build-essential git pkg-config python${{ matrix.python-version }} python${{ matrix.python-version }}-dev python${{ matrix.python-version }}-venv python3-pip python3-setuptools python3-yaml tox
114-
- name: Run linter
115-
env:
116-
LANG: en_US.UTF-8
117-
run: |
118-
tox -e lint

.pylintrc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,11 @@ indent-after-paren=4
358358

359359
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
360360
# tab).
361-
# indent-string=' '
362-
indent-string=' '
361+
indent-string=' '
363362

364363
# Maximum number of characters on a single line.
365364
# max-line-length=100
366-
max-line-length=80
365+
max-line-length=88
367366

368367
# Maximum number of lines in a module.
369368
max-module-lines=1000
@@ -599,7 +598,7 @@ spelling-store-unknown-words=no
599598

600599
# This flag controls whether inconsistent-quotes generates a warning when the
601600
# character used as a quote delimiter is used inconsistently within a module.
602-
check-quote-consistency=no
601+
check-quote-consistency=yes
603602

604603
# This flag controls whether the implicit-str-concat should generate a warning
605604
# on implicit string concatenation in sequences defined over several lines.

artifacts/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""ForensicArtifacts.com Artifact Repository."""
22

3-
__version__ = '20260501'
3+
__version__ = "20260501"

artifacts/artifact.py

Lines changed: 88 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -5,91 +5,95 @@
55

66

77
class ArtifactDefinition:
8-
"""Artifact definition interface.
8+
"""Artifact definition interface.
99
10-
Attributes:
11-
aliases (list[str]): aliases that identify the artifact definition.
12-
description (str): description.
13-
name (str): name that uniquely identifiers the artifact definition.
14-
sources (list[SourceType]): sources.
15-
supported_os (list[str]): supported operating systems.
16-
urls (list[str]): URLs with more information about the artifact definition.
17-
"""
18-
19-
def __init__(self, name, aliases=None, description=None):
20-
"""Initializes an artifact definition.
21-
22-
Args:
10+
Attributes:
11+
aliases (list[str]): aliases that identify the artifact definition.
12+
description (str): description.
2313
name (str): name that uniquely identifiers the artifact definition.
24-
aliases (Optional[str]): aliases that identify the artifact definition.
25-
description (Optional[str]): description of the artifact definition.
14+
sources (list[SourceType]): sources.
15+
supported_os (list[str]): supported operating systems.
16+
urls (list[str]): URLs with more information about the artifact definition.
2617
"""
27-
super().__init__()
28-
self.aliases = aliases or []
29-
self.description = description
30-
self.name = name
31-
self.sources = []
32-
self.supported_os = []
33-
self.urls = []
34-
35-
def AppendSource(self, type_indicator, attributes):
36-
"""Appends a source.
37-
38-
If you want to implement your own source type you should create a subclass
39-
in source_type.py and change the AppendSource method to handle the new
40-
subclass. This function raises FormatError if an unsupported source type
41-
indicator is encountered.
42-
43-
Args:
44-
type_indicator (str): source type indicator.
45-
attributes (dict[str, object]): source attributes.
46-
47-
Returns:
48-
SourceType: a source type.
49-
50-
Raises:
51-
FormatError: if the type indicator is not set or unsupported,
52-
or if required attributes are missing.
53-
"""
54-
if not type_indicator:
55-
raise errors.FormatError('Missing type indicator.')
56-
57-
try:
58-
source_object = registry.ArtifactDefinitionsRegistry.CreateSourceType(
59-
type_indicator, attributes)
60-
except (AttributeError, TypeError) as exception:
61-
raise errors.FormatError((
62-
f'Unable to create source type: {type_indicator:s} for artifact '
63-
f'definition: {self.name:s} with error: {exception!s}'))
6418

65-
self.sources.append(source_object)
66-
return source_object
67-
68-
def AsDict(self):
69-
"""Represents an artifact as a dictionary.
70-
71-
Returns:
72-
dict[str, object]: artifact attributes.
73-
"""
74-
sources = []
75-
for source in self.sources:
76-
source_definition = {
77-
'type': source.type_indicator,
78-
'attributes': source.AsDict()
79-
}
80-
if source.supported_os:
81-
source_definition['supported_os'] = source.supported_os
82-
sources.append(source_definition)
83-
84-
artifact_definition = {
85-
'name': self.name,
86-
'doc': self.description,
87-
'sources': sources,
88-
}
89-
if self.aliases:
90-
artifact_definition['aliases'] = self.aliases
91-
if self.supported_os:
92-
artifact_definition['supported_os'] = self.supported_os
93-
if self.urls:
94-
artifact_definition['urls'] = self.urls
95-
return artifact_definition
19+
def __init__(self, name, aliases=None, description=None):
20+
"""Initializes an artifact definition.
21+
22+
Args:
23+
name (str): name that uniquely identifiers the artifact definition.
24+
aliases (Optional[str]): aliases that identify the artifact definition.
25+
description (Optional[str]): description of the artifact definition.
26+
"""
27+
super().__init__()
28+
self.aliases = aliases or []
29+
self.description = description
30+
self.name = name
31+
self.sources = []
32+
self.supported_os = []
33+
self.urls = []
34+
35+
def AppendSource(self, type_indicator, attributes):
36+
"""Appends a source.
37+
38+
If you want to implement your own source type you should create a subclass
39+
in source_type.py and change the AppendSource method to handle the new
40+
subclass. This function raises FormatError if an unsupported source type
41+
indicator is encountered.
42+
43+
Args:
44+
type_indicator (str): source type indicator.
45+
attributes (dict[str, object]): source attributes.
46+
47+
Returns:
48+
SourceType: a source type.
49+
50+
Raises:
51+
FormatError: if the type indicator is not set or unsupported,
52+
or if required attributes are missing.
53+
"""
54+
if not type_indicator:
55+
raise errors.FormatError("Missing type indicator.")
56+
57+
try:
58+
source_object = registry.ArtifactDefinitionsRegistry.CreateSourceType(
59+
type_indicator, attributes
60+
)
61+
except (AttributeError, TypeError) as exception:
62+
raise errors.FormatError(
63+
(
64+
f"Unable to create source type: {type_indicator:s} for artifact "
65+
f"definition: {self.name:s} with error: {exception!s}"
66+
)
67+
)
68+
69+
self.sources.append(source_object)
70+
return source_object
71+
72+
def AsDict(self):
73+
"""Represents an artifact as a dictionary.
74+
75+
Returns:
76+
dict[str, object]: artifact attributes.
77+
"""
78+
sources = []
79+
for source in self.sources:
80+
source_definition = {
81+
"type": source.type_indicator,
82+
"attributes": source.AsDict(),
83+
}
84+
if source.supported_os:
85+
source_definition["supported_os"] = source.supported_os
86+
sources.append(source_definition)
87+
88+
artifact_definition = {
89+
"name": self.name,
90+
"doc": self.description,
91+
"sources": sources,
92+
}
93+
if self.aliases:
94+
artifact_definition["aliases"] = self.aliases
95+
if self.supported_os:
96+
artifact_definition["supported_os"] = self.supported_os
97+
if self.urls:
98+
artifact_definition["urls"] = self.urls
99+
return artifact_definition

artifacts/definitions.py

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,45 @@
11
"""Constants and definitions."""
22

3-
TYPE_INDICATOR_ARTIFACT_GROUP = 'ARTIFACT_GROUP'
4-
TYPE_INDICATOR_COMMAND = 'COMMAND'
5-
TYPE_INDICATOR_DIRECTORY = 'DIRECTORY' # deprecated use PATH instead.
6-
TYPE_INDICATOR_FILE = 'FILE'
7-
TYPE_INDICATOR_PATH = 'PATH'
8-
TYPE_INDICATOR_WINDOWS_REGISTRY_KEY = 'REGISTRY_KEY'
9-
TYPE_INDICATOR_WINDOWS_REGISTRY_VALUE = 'REGISTRY_VALUE'
10-
TYPE_INDICATOR_WMI_QUERY = 'WMI'
3+
TYPE_INDICATOR_ARTIFACT_GROUP = "ARTIFACT_GROUP"
4+
TYPE_INDICATOR_COMMAND = "COMMAND"
5+
TYPE_INDICATOR_DIRECTORY = "DIRECTORY" # deprecated use PATH instead.
6+
TYPE_INDICATOR_FILE = "FILE"
7+
TYPE_INDICATOR_PATH = "PATH"
8+
TYPE_INDICATOR_WINDOWS_REGISTRY_KEY = "REGISTRY_KEY"
9+
TYPE_INDICATOR_WINDOWS_REGISTRY_VALUE = "REGISTRY_VALUE"
10+
TYPE_INDICATOR_WMI_QUERY = "WMI"
1111

12-
SUPPORTED_OS_ANDROID = 'Android'
13-
SUPPORTED_OS_DARWIN = 'Darwin'
14-
SUPPORTED_OS_ESXI = 'ESXi'
15-
SUPPORTED_OD_IOS = 'iOS'
16-
SUPPORTED_OS_LINUX = 'Linux'
17-
SUPPORTED_OS_WINDOWS = 'Windows'
12+
SUPPORTED_OS_ANDROID = "Android"
13+
SUPPORTED_OS_DARWIN = "Darwin"
14+
SUPPORTED_OS_ESXI = "ESXi"
15+
SUPPORTED_OD_IOS = "iOS"
16+
SUPPORTED_OS_LINUX = "Linux"
17+
SUPPORTED_OS_WINDOWS = "Windows"
1818

19-
SUPPORTED_OS = frozenset([
20-
SUPPORTED_OS_ANDROID,
21-
SUPPORTED_OS_DARWIN,
22-
SUPPORTED_OS_ESXI,
23-
SUPPORTED_OD_IOS,
24-
SUPPORTED_OS_LINUX,
25-
SUPPORTED_OS_WINDOWS])
19+
SUPPORTED_OS = frozenset(
20+
[
21+
SUPPORTED_OS_ANDROID,
22+
SUPPORTED_OS_DARWIN,
23+
SUPPORTED_OS_ESXI,
24+
SUPPORTED_OD_IOS,
25+
SUPPORTED_OS_LINUX,
26+
SUPPORTED_OS_WINDOWS,
27+
]
28+
)
2629

27-
TOP_LEVEL_KEYS = frozenset([
28-
'aliases',
29-
# conditions have been deprecated as of version 20220710.
30-
'conditions',
31-
'doc',
32-
# labels have been deprecated as of version 20220311.
33-
'labels',
34-
'name',
35-
# provides have been deprecated as of version 20240210.
36-
'provides',
37-
'sources',
38-
'supported_os',
39-
'urls'])
30+
TOP_LEVEL_KEYS = frozenset(
31+
[
32+
"aliases",
33+
# conditions have been deprecated as of version 20220710.
34+
"conditions",
35+
"doc",
36+
# labels have been deprecated as of version 20220311.
37+
"labels",
38+
"name",
39+
# provides have been deprecated as of version 20240210.
40+
"provides",
41+
"sources",
42+
"supported_os",
43+
"urls",
44+
]
45+
)

0 commit comments

Comments
 (0)