3 Commits

Author SHA1 Message Date
53712f76ce Added HEADLESS loglevel 2023-03-28 22:52:25 +02:00
d5fad2beb6 Bump version 2023-03-28 01:03:53 +02:00
4e4ada293e Merge commit '1e48aa144ec3f0ab1c4126a35de473bb4d8d8207' 2023-03-28 00:59:30 +02:00
5 changed files with 22 additions and 5 deletions

View File

@@ -53,7 +53,7 @@ options:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-l LOGLEVEL, --loglevel LOGLEVEL
set log level, possible options: CRITICAL, ERROR, WARNING, INFO, DEBUG
set log level, possible options: HEADLESS, CRITICAL, ERROR, WARNING, INFO, DEBUG
-n, --dry-run do not modify files, only show log
-F, --force overwrite even if the files are older
-b, --backup create a backup for updated files
@@ -68,6 +68,7 @@ dynamo options, only for processing Dynamo graphs:
The script by default overwrites older files with newer files.
Do not move the source Dynamo graphs, or update won't work with them later.
Multiple sources are supported, separate them by spaces.
HEADLESS loglevel only prints modified filenames.
```
#### Examples

View File

@@ -45,6 +45,7 @@ def __command_line() -> None:
The script by default overwrites older files with newer files.
Do not move the source Dynamo graphs, or update won't work with them later.
Multiple sources are supported, separate them by spaces.
HEADLESS loglevel only prints modified filenames.
""")
)
@@ -117,8 +118,13 @@ def run(options: Options) -> None:
from_command_line = bool(inspect.stack()[1].function == "__command_line")
# Set up logging:
if options.loglevel == "HEADLESS":
loglevel = "CRITICAL"
else:
loglevel = options.loglevel
logging.basicConfig(format='%(levelname)s: %(message)s',
level=options.loglevel)
level=loglevel)
logging.debug(f"Run options: {vars(options)}")
# Set up sources:
@@ -197,4 +203,7 @@ def run(options: Options) -> None:
# Write files at the end:
for f in DynamoFile.open_files | PythonFile.open_files:
f.write(options)
try:
f.write(options)
except FileNotFoundError:
logging.error(f"Cannot save file! {f.filepath}")

View File

@@ -120,6 +120,7 @@ class File():
Raises:
TypeError: If called on a File object
FileNotFoundError: Target folder does not exist
"""
if not options:
@@ -140,14 +141,20 @@ class File():
backup_path = self.dirpath.joinpath(backup_filename)
logging.info(f"Creating backup to {backup_path}")
self.filepath.rename(backup_path)
if options.loglevel == "HEADLESS":
print(backup_path)
# Call filetype specific methods:
if options.dry_run:
logging.info(
f"Should write file, but it's a dry-run: {self.filepath}")
else:
if not self.dirpath.exists():
raise FileNotFoundError("File dir does not exist!")
logging.info(f"Writing file: {self.filepath}")
self._write_file()
if options.loglevel == "HEADLESS":
print(self.filepath)
def _write_file(self):
"""Should be implemented in subclasses

View File

@@ -3,7 +3,7 @@ import argparse
import pathlib
LOGLEVELS = ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"]
LOGLEVELS = ["HEADLESS", "CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"]
DEFAULT_LOGLEVEL = "INFO"
FILTERS = ["py", "dyn"]

View File

@@ -1,6 +1,6 @@
[project]
name = "dyn2py"
version = "0.3.2"
version = "0.3.3"
description = "Extract python code from Dynamo graphs"
readme = "README.md"
requires-python = ">=3.8"