2 # -*- coding: utf-8 -*-
4 from atexit
import register
as atexit_register
6 from logging
import info
, warning
, basicConfig
, INFO
, WARN
, getLogRecordFactory
, setLogRecordFactory
7 from os
import makedirs
, path
8 from shutil
import rmtree
10 from .cli
.args
import get_cli_arguments
12 from .meta
import version
13 from .fs
import get_temp_path
, root_path
14 from .base_classes
.web_driver
import get_display
, get_driver
15 from .default_config
import dump_init_content
16 from .default_config
.actions
import load_config
18 from .fs
import get_info
20 from .info
import Info
21 import better_exceptions
22 better_exceptions
.hook()
26 def before_shutdown():
27 get_display() and get_display().stop()
28 get_driver() and get_driver().close()
29 temp_dir
= get_temp_path()
30 path
.isdir(temp_dir
) and rmtree(temp_dir
)
42 Cli(args
, _info
).start()
44 if args
.get('print_json', False):
55 def _update_all(args
):
56 parse_args
= args
.parse_args()
60 dst
= parse_args
.destination
61 json_info
= get_info(dst
)
64 parse_args
.manga_name
= i
['manga_name']
65 parse_args
.url
= i
['url']
66 _info
= _run_util(args
)
67 multi_info
[i
['directory']] = _info
68 parse_args
.quiet
or (parse_args
.print_json
and print(multi_info
))
78 temp_path
= get_temp_path()
79 path
.isdir(temp_path
) or makedirs(temp_path
)
82 _info
= _run_util(args
)
83 args
.get('quiet', False) or (args
.get('print_json', False) and print(_info
))
85 except KeyboardInterrupt:
86 warning('\nUser interrupt')
90 __root
= len(root_path())
91 __old_factory
= getLogRecordFactory()
94 def __log_factory(*args
, **kwargs
):
95 record
= __old_factory(*args
, **kwargs
)
96 record
.my_pathname
= record
.pathname
[__root
:]
97 record
.custom_attribute
= "my-attr"
104 args_
= get_cli_arguments()
106 args
= args_
.parse_args().__dict
__
107 setLogRecordFactory(__log_factory
)
109 default_config
= load_config().get_all()
112 if k
not in default_config
:
115 if args
[k
] == args_
.get_default(k
):
116 args
[k
] = default_config
[k
]
118 log_format
= '"%(levelname)s:%(my_pathname)s:%(lineno)s:%(asctime)s:%(message)s"'
119 basicConfig(level
=(INFO
if args
.get('debug', False) else WARN
), format
=log_format
)
121 if ~version
.find('alpha'):
122 warning('Alpha release! There may be errors!')
127 if __name__
== '__main__':