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
0674346
commit 41a1e9e
Showing
8 changed files
with
998 additions
and
10 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
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
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<!-- BEGIN --> | ||
<script src="js/common.js"></script> | ||
<script src="js/engine.js"></script> | ||
<script src="js/global.js"></script> | ||
<script src="dist/js/themes.js"></script> | ||
<script src="js/3d.js"></script> | ||
<script src="js/board.js"></script> | ||
<script src="js/script.js"></script> | ||
<link href="css/common.css" rel="stylesheet"> | ||
<!-- END --> | ||
<!-- {SCRIPT} --> | ||
<!-- {STYLE} --> | ||
</head> | ||
<body> | ||
<vert></vert> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# coding: utf-8 | ||
# @author octopoulo <[email protected]> | ||
# @version 2020-04-13 | ||
|
||
""" | ||
Main | ||
""" | ||
|
||
from argparse import ArgumentParser | ||
import os | ||
from time import time | ||
|
||
from download_json import download_json | ||
from sync import Sync | ||
|
||
|
||
def main(): | ||
"""Main | ||
""" | ||
start = time() | ||
|
||
parser = ArgumentParser(description='Sync', prog='python __main__.py') | ||
add = parser.add_argument | ||
|
||
add('--console-debug', nargs='?', default='INFO', help='console debug level', | ||
choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']) | ||
add('--download', action='store_true', help='download JSON files') | ||
add('--host', nargs='?', default='/', help='host, ex: /seriv/') | ||
add('--no-debug', nargs='?', default=0, const=1, type=int, help="remove debug code from the javascript") | ||
add('--no-process', nargs='?', default=0, const=1, type=int, help="don't process the images") | ||
|
||
args = parser.parse_args() | ||
args_dict = vars(args) | ||
|
||
if args.download: | ||
download_json() | ||
else: | ||
sync = Sync(**args_dict) | ||
sync.synchronise() | ||
|
||
end = time() | ||
print(f'\nELAPSED: {end-start:.3f} seconds') | ||
|
||
|
||
if __name__ == '__main__': | ||
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# coding: utf-8 | ||
# @author octopoulo <[email protected]> | ||
# @version 2020-04-13 | ||
|
||
""" | ||
Common functions | ||
""" | ||
|
||
import errno | ||
import logging | ||
import os | ||
|
||
|
||
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 | ||
""" | ||
if not folder: | ||
return True | ||
|
||
try: | ||
os.makedirs(folder) | ||
return True | ||
except Exception as e: | ||
if isinstance(e, OSError) and e.errno == errno.EEXIST: | ||
return True | ||
logging.error({'status': 'makedirs_safe__error', 'error': e, 'folder': folder}) | ||
return False | ||
|
||
|
||
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 | ||
""" | ||
if not filename or not os.path.isfile(filename): | ||
return None | ||
|
||
try: | ||
open_func = open # locked_open if locked else open | ||
with open_func(filename, 'rb') as file: | ||
data = file.read() | ||
return data if want_bytes else data.decode('utf-8-sig') | ||
except OSError as e: | ||
logging.error({'status': 'read_text_safe__error', 'error': e, 'filename': filename}) | ||
return None | ||
|
||
|
||
def utc_time() -> float: | ||
"""Utility to return the utc timestamp | ||
""" | ||
return datetime.now(tz=timezone.utc).timestamp() | ||
|
||
|
||
def write_text_safe( | ||
filename: str, | ||
data: str or bytes, | ||
mode: str='wb', | ||
locked: bool=False, | ||
convert_newlines: bool=False, # convert \n to \r\n on windows | ||
) -> bool: | ||
"""Save text or binary to a file | ||
""" | ||
if not filename or '?' in filename: | ||
return False | ||
|
||
# windows support | ||
if convert_newlines and isinstance(data, str) and system() == 'Windows' and '\r\n' not in data: | ||
data = data.replace('\n', '\r\n') | ||
|
||
# save | ||
path = os.path.dirname(filename) | ||
if not makedirs_safe(path): | ||
return False | ||
|
||
try: | ||
open_func = locked_open if locked else open | ||
with open_func(filename, mode) as file: | ||
if data: | ||
file.write(data.encode('utf-8') if isinstance(data, str) else data) | ||
return True | ||
except OSError as e: | ||
logging.error({'status': 'write_text_safe__error', 'error': e, 'filename': filename}) | ||
return False |
Oops, something went wrong.