add autocheck config for added new section/options in script
This commit is contained in:
42
prepare.py
42
prepare.py
@@ -14,7 +14,6 @@ from pymediainfo import MediaInfo
|
||||
|
||||
threading.current_thread().name = "main"
|
||||
|
||||
|
||||
if not os.path.isdir('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',
|
||||
level='INFO')
|
||||
|
||||
logging.warning('Test warn')
|
||||
|
||||
class Args:
|
||||
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('-m', action='store_true', dest='mediainfo', help='create mediainfo')
|
||||
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('-i', action='store', dest='input', help="input file", type=str, required=True)
|
||||
args = parser.parse_args()
|
||||
@@ -45,8 +43,11 @@ class Config:
|
||||
config.add_section('Output')
|
||||
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'):
|
||||
logging.info("Config dir is exist" )
|
||||
logging.info("Config dir is exist")
|
||||
else:
|
||||
try:
|
||||
os.makedirs('config')
|
||||
@@ -56,11 +57,22 @@ class Config:
|
||||
logging.info("Successfully created the config directory")
|
||||
|
||||
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:
|
||||
logging.info("Creating Config" )
|
||||
with open(Args.args.config, 'w') as configfile:
|
||||
config.write(configfile)
|
||||
logging.info("Creating Config")
|
||||
with open(Args.args.config, 'w') as configfile:
|
||||
config.write(configfile)
|
||||
|
||||
|
||||
class Head:
|
||||
@@ -73,8 +85,14 @@ class Head:
|
||||
config.read(Args.args.config)
|
||||
output = config["Output"]
|
||||
save_dir = output["dir"]
|
||||
|
||||
if config.has_section('testt'):
|
||||
testt = output["testt"]
|
||||
print(testt)
|
||||
else:
|
||||
print(config.options("Output"))
|
||||
procs = []
|
||||
self.num_screen = 0
|
||||
self.num_screen: int
|
||||
self.bname: str
|
||||
|
||||
self.bname = os.path.basename(Args.args.input)
|
||||
@@ -95,7 +113,7 @@ class Head:
|
||||
self.max_time = round(MediaInfo.parse(Args.args.input).tracks[0].duration / 1000)
|
||||
|
||||
if Args.args.sample:
|
||||
thread = threading.Thread(name="sample", target=Head.sample, args=(self, ),
|
||||
thread = threading.Thread(name="sample", target=Head.sample, args=(self,),
|
||||
kwargs={'fold': self.fold,
|
||||
'bname': self.bname,
|
||||
'max_time': self.max_time})
|
||||
@@ -107,7 +125,7 @@ class Head:
|
||||
logging.info("Creating %s screenshots" % Args.args.count)
|
||||
|
||||
for self.num_screen in range(Args.args.count):
|
||||
thread = threading.Thread(name="screen_" + str(self.num_screen + 1), target=Head.screens, args=(self, ),
|
||||
thread = threading.Thread(name="screen_" + str(self.num_screen + 1), target=Head.screens, args=(self,),
|
||||
kwargs={'fold': self.fold,
|
||||
'max_time': self.max_time,
|
||||
'num_screen': self.num_screen})
|
||||
@@ -157,7 +175,7 @@ class Head:
|
||||
scr_cr.save_frame(self.fold + "/" + str(sec) + ".png", t=sec)
|
||||
scr_cr.audio.reader.close_proc()
|
||||
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__':
|
||||
|
||||
Reference in New Issue
Block a user