forked from tcecspectator/mytcecgui
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c804240
commit 4e04e4d
Showing
5 changed files
with
217 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
# coding: utf-8 | ||
# @author octopoulo <[email protected]> | ||
# @version 2021-01-05 | ||
|
||
""" | ||
Init | ||
|
@@ -12,4 +14,5 @@ | |
'download_json', | ||
'inspector', | ||
'sync', | ||
'util', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# coding: utf-8 | ||
# @author octopoulo <[email protected]> | ||
# @version 2020-09-07 | ||
# @version 2021-01-05 | ||
|
||
""" | ||
Main | ||
|
@@ -10,39 +10,40 @@ | |
import os | ||
from time import time | ||
|
||
from commoner import create_group | ||
from download_json import download_json | ||
from sync import Sync | ||
from sync import add_arguments_sync, main_sync | ||
from util import add_arguments_util, main_util | ||
|
||
|
||
def main(): | ||
"""Main | ||
""" | ||
parser = ArgumentParser(description='Sync', prog='python __main__.py') | ||
add = parser.add_argument | ||
parser = ArgumentParser(description='TCEC', prog='python __main__.py') | ||
|
||
add('--clean', action='store_true', help='delete all .gz files') | ||
add('--console-debug', nargs='?', default='INFO', help='console debug level', | ||
choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']) | ||
add('--debug', nargs='?', default=0, const=1, type=int, help="keep debug code from the javascript") | ||
add = create_group(parser, 'tcec') | ||
add('--download', action='store_true', help='download JSON files') | ||
add('--host', nargs='?', default='/', help='host, ex: /seriv/') | ||
add('--inspector', nargs='?', default=0, const=1, type=int, help='run the inspector') | ||
add('--no-process', nargs='?', default=0, const=1, type=int, help="don't process the images") | ||
add('--zip', action='store_true', help='create .gz files') | ||
|
||
add_arguments_util(parser) | ||
add_arguments_sync(parser) | ||
|
||
# configure args | ||
args = parser.parse_args() | ||
args_dict = vars(args) | ||
args_set = set(item for item, value in args_dict.items() if value) | ||
|
||
if args.download: | ||
download_json() | ||
# utils | ||
if args_set & {'inspector'}: | ||
main_util(parser) | ||
elif args.inspector: | ||
from inspector import Inspect | ||
inspector = Inspect() | ||
inspector.go() | ||
else: | ||
sync = Sync(**args_dict) | ||
sync.synchronise() | ||
# sync | ||
elif args.sync: | ||
main_sync(parser) | ||
|
||
|
||
if __name__ == '__main__': | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,41 @@ | ||
# coding: utf-8 | ||
# @author octopoulo <[email protected]> | ||
# @version 2020-04-13 | ||
# @version 2021-01-05 | ||
|
||
""" | ||
Common functions | ||
""" | ||
|
||
from argparse import ArgumentParser | ||
import errno | ||
import logging | ||
import os | ||
|
||
|
||
def create_group(parser: ArgumentParser, group: str) -> callable: | ||
group = parser.add_argument_group(group) | ||
return group.add_argument | ||
|
||
|
||
def default_int(value: int or str, default: int=None, origin: str=None, log: bool=False) -> int or None: | ||
"""Convert a value to an int, on exception, return a default value | ||
""" | ||
if isinstance(value, int): | ||
return value | ||
if value is None: | ||
return default | ||
|
||
try: | ||
value = int(float(value)) | ||
except (TypeError, ValueError): | ||
if log: | ||
logging.warning({ | ||
'status': 'default_int__cannot_convert', 'value': value, 'default': default, 'origin': origin}) | ||
value = default | ||
|
||
return value | ||
|
||
|
||
def makedirs_safe(folder: str) -> bool: | ||
"""Create a folder recursively + handle errors | ||
:return: True if the folder has been created or existed already, False otherwise | ||
|
@@ -28,6 +53,9 @@ def makedirs_safe(folder: str) -> bool: | |
return False | ||
|
||
|
||
pinfo = print | ||
|
||
|
||
def read_text_safe(filename: str, locked: bool=False, want_bytes: bool=False) -> str or bytes or None: | ||
"""Read the content of a file and convert it to utf-8 | ||
""" | ||
|
Oops, something went wrong.