Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #295 from DeepBlueCLtd/hotfix_static_linters
Browse files Browse the repository at this point in the history
Hotfix static linters
  • Loading branch information
IanMayo committed Aug 3, 2023
2 parents 6543980 + 1dfbd99 commit 06c0c37
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
language_version: python3.10
31 changes: 25 additions & 6 deletions parser/parser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@
import xml.dom.minidom
import os

# package of utility helpers that are not specific to the task of LegacyMan


def delete_directory(path):
if os.path.exists(path):
shutil.rmtree(path)
print('Target directory deleted:' + path)
print("Target directory deleted:" + path)
else:
print('Target directory does not exist')
print("Target directory does not exist")


def create_directory(name):
try:
os.makedirs(name)
print(f'{name} directory created')
print(f"{name} directory created")
except FileExistsError:
print(f'The directory {name} already exists')
print(f"The directory {name} already exists")


def copy_directory(src_folder, dst_folder):
shutil.copytree(src_folder, dst_folder)


def copy_files(source_dir, target_dir, file_names=[]):
# create the target dir if it doesn't exist
if not os.path.exists(target_dir):
Expand All @@ -38,19 +44,32 @@ def copy_files(source_dir, target_dir, file_names=[]):
target_file = os.path.join(target_dir, file_name)
shutil.copy(source_file, target_file)


def prettify_xml(xml_code):
dom = xml.dom.minidom.parseString(xml_code)
return dom.toprettyxml()


def get_files_in_path(path, make_lowercase=False):
entries = os.listdir(path)

# If make_lowercase is True, convert directory names to lowercase
if make_lowercase:
entries = [entry.lower() if os.path.isfile(os.path.join(path, entry)) else entry for entry in entries]
entries = [
entry.lower() if os.path.isfile(os.path.join(path, entry)) else entry
for entry in entries
]

# Get a list of all files in the path
files = [f for f in entries if os.path.isfile(os.path.join(path, f))]
return files

__all__ = ['delete_directory', 'create_directory', 'copy_directory', 'copy_files', 'prettify_xml', 'get_files_in_path']

__all__ = [
"delete_directory",
"create_directory",
"copy_directory",
"copy_files",
"prettify_xml",
"get_files_in_path",
]
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tool.black]
line-length = 100
target-version = ['py310']
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
beautifulsoup4
beautifulsoup4
pre-commit

0 comments on commit 06c0c37

Please sign in to comment.