From 95296db53ff36d069fd31a55f108daa7a21eb9de Mon Sep 17 00:00:00 2001 From: beaconborn Date: Fri, 18 Feb 2022 01:34:56 +0300 Subject: [PATCH] bug fixes --- prepare.py | 56 ++++++++++++++++++++++++------------------------------ test.py | 9 --------- 2 files changed, 25 insertions(+), 40 deletions(-) delete mode 100644 test.py diff --git a/prepare.py b/prepare.py index b531be7..45046f0 100755 --- a/prepare.py +++ b/prepare.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python import random import os import pathlib @@ -12,17 +12,12 @@ import configparser from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip from pymediainfo import MediaInfo + +if not os.path.isdir(os.path.dirname(__file__) + 'log'): + os.makedirs(os.path.dirname(__file__) + 'log') threading.current_thread().name = "main" -if not os.path.isdir('log'): - os.makedir('log') - print('Create log dir') -else: - print('log dir exist') - -a = 'log/' + str(time.strftime("%Y-%m-%d %H:%M:%S")) + '.log' -print(a) -f = open(a, 'w') +a = os.path.dirname(__file__) + '/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') @@ -43,8 +38,14 @@ class Args: class Config: - config = configparser.ConfigParser() + conf_file = os.path.dirname(__file__) + '/' + Args.args.config + @staticmethod + def write(config, conf_file): + with open(conf_file, 'w') as configfile: + config.write(configfile) + + config = configparser.ConfigParser() config.add_section('Output') config.set('Output', 'Dir', str(pathlib.Path.home()) + '/sample/') @@ -57,31 +58,25 @@ class Config: logging.error("Creation of the directory config failed") else: logging.info("Successfully created the config directory") + time.sleep(0.5) - with open(Args.args.config, 'w') as conf: - config.write(conf) - time.sleep(0.5) - - if os.path.isfile(Args.args.config): + if os.path.isfile(conf_file): logging.info("Config is exist") config2 = configparser.ConfigParser() - config2.read(Args.args.config) + config2.read(conf_file) for section in config.sections(): if config2.has_section(section): - print(f'{section} is exist') for option in config.options(section): - if config2.has_option(section, option): - print(f'{option} in {section} is exist') - else: - print(f'{option} in {section} isn`t exist') + if not config2.has_option(section, option): config.set(section, option, config.get(section, option)) + write(config, conf_file) else: config.add_section(section) - print(f'{section} isn`t exist') + write(config, conf_file) + else: logging.info("Creating Config") - with open(Args.args.config, 'w') as configfile: - config.write(configfile) + write(config, conf_file) class Head: @@ -90,15 +85,14 @@ class Head: """ def __init__(self): + if not Args.args.screens and not Args.args.sample and not Args.args.mediainfo: + Args.args.screens = Args.args.sample = Args.args.mediainfo = 1 + config = configparser.ConfigParser() - config.read(Args.args.config) + config.read(os.path.dirname(__file__) + '/' + 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 diff --git a/test.py b/test.py deleted file mode 100644 index e6368eb..0000000 --- a/test.py +++ /dev/null @@ -1,9 +0,0 @@ -import time -import os - -if os.path.isdir('log'): - print('log dir exist') - -a = 'log/' + str(time.strftime("%Y-%m-%d %H:%M:%S")) + '.log' -print(a) -f = open(a, 'w')