add autocheck config for added new section/options in script
This commit is contained in:
28
prepare.py
28
prepare.py
@@ -14,7 +14,6 @@ from pymediainfo import MediaInfo
|
|||||||
|
|
||||||
threading.current_thread().name = "main"
|
threading.current_thread().name = "main"
|
||||||
|
|
||||||
|
|
||||||
if not os.path.isdir('log'):
|
if not os.path.isdir('log'):
|
||||||
os.makedirs('log')
|
os.makedirs('log')
|
||||||
|
|
||||||
@@ -22,7 +21,6 @@ a = 'log/' + str(time.strftime("%Y-%m-%d %H:%M:%S")) + '.log'
|
|||||||
logging.basicConfig(filename=a, filemode='w', format='%(asctime)s - %(threadName)s - %(levelname)s - %(message)s',
|
logging.basicConfig(filename=a, filemode='w', format='%(asctime)s - %(threadName)s - %(levelname)s - %(message)s',
|
||||||
level='INFO')
|
level='INFO')
|
||||||
|
|
||||||
logging.warning('Test warn')
|
|
||||||
|
|
||||||
class Args:
|
class Args:
|
||||||
parser = ArgumentParser = argparse.ArgumentParser(
|
parser = ArgumentParser = argparse.ArgumentParser(
|
||||||
@@ -31,7 +29,7 @@ class Args:
|
|||||||
parser.add_argument('-S', action='store_true', dest='sample', help="extract sample")
|
parser.add_argument('-S', action='store_true', dest='sample', help="extract sample")
|
||||||
parser.add_argument('-m', action='store_true', dest='mediainfo', help='create mediainfo')
|
parser.add_argument('-m', action='store_true', dest='mediainfo', help='create mediainfo')
|
||||||
parser.add_argument('-n', action='store', dest="count", default=10,
|
parser.add_argument('-n', action='store', dest="count", default=10,
|
||||||
help="number of smcreenshots, default 10", type=int)
|
help="number of screenshots, default 10", type=int)
|
||||||
parser.add_argument('-c', action='store', dest='config', help='config file', default='config/config.ini', type=str)
|
parser.add_argument('-c', action='store', dest='config', help='config file', default='config/config.ini', type=str)
|
||||||
parser.add_argument('-i', action='store', dest='input', help="input file", type=str, required=True)
|
parser.add_argument('-i', action='store', dest='input', help="input file", type=str, required=True)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
@@ -45,6 +43,9 @@ class Config:
|
|||||||
config.add_section('Output')
|
config.add_section('Output')
|
||||||
config.set('Output', 'Dir', str(pathlib.Path.home()) + '/sample/')
|
config.set('Output', 'Dir', str(pathlib.Path.home()) + '/sample/')
|
||||||
|
|
||||||
|
with open(Args.args.config, 'w') as configfile:
|
||||||
|
config.write(configfile)
|
||||||
|
|
||||||
if os.path.isdir('config'):
|
if os.path.isdir('config'):
|
||||||
logging.info("Config dir is exist")
|
logging.info("Config dir is exist")
|
||||||
else:
|
else:
|
||||||
@@ -57,6 +58,17 @@ class Config:
|
|||||||
|
|
||||||
if os.path.isfile(Args.args.config):
|
if os.path.isfile(Args.args.config):
|
||||||
logging.info("Config is exist")
|
logging.info("Config is exist")
|
||||||
|
config2 = configparser.ConfigParser()
|
||||||
|
config2.read(Args.args.config)
|
||||||
|
for section in config.sections():
|
||||||
|
if config2.has_section(section):
|
||||||
|
for option in config.options(section):
|
||||||
|
if config2.has_option(section, option):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
config.set(section, option, config.get(section, option))
|
||||||
|
else:
|
||||||
|
config.add_section(section)
|
||||||
else:
|
else:
|
||||||
logging.info("Creating Config")
|
logging.info("Creating Config")
|
||||||
with open(Args.args.config, 'w') as configfile:
|
with open(Args.args.config, 'w') as configfile:
|
||||||
@@ -73,8 +85,14 @@ class Head:
|
|||||||
config.read(Args.args.config)
|
config.read(Args.args.config)
|
||||||
output = config["Output"]
|
output = config["Output"]
|
||||||
save_dir = output["dir"]
|
save_dir = output["dir"]
|
||||||
|
if config.has_section('testt'):
|
||||||
|
testt = output["testt"]
|
||||||
|
print(testt)
|
||||||
|
else:
|
||||||
|
print(config.options("Output"))
|
||||||
procs = []
|
procs = []
|
||||||
|
self.num_screen = 0
|
||||||
|
self.num_screen: int
|
||||||
self.bname: str
|
self.bname: str
|
||||||
|
|
||||||
self.bname = os.path.basename(Args.args.input)
|
self.bname = os.path.basename(Args.args.input)
|
||||||
@@ -157,7 +175,7 @@ class Head:
|
|||||||
scr_cr.save_frame(self.fold + "/" + str(sec) + ".png", t=sec)
|
scr_cr.save_frame(self.fold + "/" + str(sec) + ".png", t=sec)
|
||||||
scr_cr.audio.reader.close_proc()
|
scr_cr.audio.reader.close_proc()
|
||||||
scr_cr.reader.close()
|
scr_cr.reader.close()
|
||||||
logging.info(f"{self.num_screen + 1}st screen screated")
|
logging.info(f"{self.num_screen + 1}st screen created")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user