def get_start_dir():
    _start_dir = CFG.get('general', 'base_directory')
    if _start_dir == 'cfg_dir':
        _start_dir = pathmaker(os.path.dirname(os.getenv('AS_INDEX_CFG_FILE')))
    else:
        _start_dir = pathmaker(_start_dir)
    return _start_dir
Exemple #2
0
 def __init__(self, bot):
     self.bot = bot
     self.number = '1'
     self.save_file = pathmaker(THIS_FILE_DIR, 'link_test.json')
     self.applicable_channels = [
         self.channel_settings(
             'Suggestions', 645930607683174401,
             pathmaker(THIS_FILE_DIR, 'saved_suggestions.json'))
     ]
Exemple #3
0
 def __init__(self,
              in_cwd,
              in_db_name,
              in_db_loc,
              in_sql_script_loc,
              in_pragma=None):
     self.db_name = in_db_name
     self.db_loc = gif.pathmaker(in_cwd, in_db_loc)
     self.db = gif.pathmaker(in_cwd, self.db_loc, self.db_name)
     self.pragma = () if in_pragma is None else in_pragma
     self.tables = []
     self.sql_script_loc = in_sql_script_loc
     self.db_status = ''
def find_filter_files():
    _start_dir = get_start_dir()
    _exclude_folder = CFG.getlist('fixed_lists', 'exclude_folders')
    _exclude_files = CFG.getlist('fixed_lists', 'exclude_files')
    for dirname, folderlist, filelist in os.walk(_start_dir):
        if all(_ex_folder not in pathmaker(dirname).split('/')
               for _ex_folder in _exclude_folder):
            for _file in filelist:
                if _file not in _exclude_files and _file.casefold(
                ) != os.path.basename(os.getenv('AS_INDEX_CFG_FILE')).casefold(
                ) and _file not in _exclude_output_files():
                    yield ASFile(_file, pathmaker(dirname),
                                 pathmaker(dirname, _file))
Exemple #5
0
 def __init__(self,
              config_name,
              config_loc,
              auto_convert_list=False,
              list_delim=', '):
     self.cfg_handle = configparser.ConfigParser()
     self.config_name = config_name
     self.config_location = gif.pathmaker(
         'cwd',
         'config') if config_loc == 'default' else gif.pathmaker(config_loc)
     self.config = gif.pathmaker(self.config_location, self.config_name)
     self.cfg_sections = self.read_config()
     self.convert_list = auto_convert_list
     self.list_delim = list_delim
Exemple #6
0
def rename_persisting_placeholders(start_dir=None):
    start_dir = pathmaker(start_dir) if start_dir is not None else "../../."
    for dirname, folderlist, filelist in os.walk(start_dir):
        for _file in filelist:
            if '$XC$' in _file:
                _old_name = pathmaker(dirname, _file)
                _new_name = _old_name.replace('$XC$', PROJECT_NAME)
                os.rename(_old_name, _new_name)
                print(f"renamed file '{_old_name}' to --> '{_new_name}'")
        for _folder in folderlist:
            if '$XC$' in _folder:
                _old_name = pathmaker(dirname, _folder)
                _new_name = _old_name.replace('$XC$', PROJECT_NAME)
                os.rename(_old_name, _new_name)
                print(f"renamed folder '{_old_name}' to --> '{_new_name}'")
def std_get_relative_folder_path(in_file: ASFile):
    _out = pathmaker(in_file.directory).replace(get_start_dir(), '').strip()
    if _out == '':
        _out = 'ROOT'
    else:
        _out = _out.lstrip('/')
    return _out
Exemple #8
0
 def __init__(self, in_cfg_loc='default', in_db_class=GidSQLiteDatabaser):
     self.cfg_loc = pathmaker(
         'cwd',
         'config/db_config.ini') if in_cfg_loc == 'default' else in_cfg_loc
     self.cfg_tool = configparser.ConfigParser()
     self.cfg_tool.read(self.cfg_loc)
     self.make_database(in_db_class)
Exemple #9
0
 def make_database(self, in_db_class):
     _pragmas = self.cfg_tool.get('db_parameter',
                                  'pragmas').replace(',', ';')
     _db_loc = pathmaker('cwd', self.cfg_tool.get('db_parameter', 'db_loc'))
     _backup_loc = self.cfg_tool.get('db_parameter', 'archive_loc')
     _script_folder = pathmaker(
         'cwd', self.cfg_tool.get('db_parameter', 'sql_script_folder'))
     _executor = GidSQLiteExecutor(_db_loc, _pragmas)
     _scripter = GidSQLScripter(_script_folder)
     _startup_dict = {
         'overwrite':
         self.cfg_tool.getboolean('db_startup_parameter', 'overwrite'),
         'in_max_backup':
         self.cfg_tool.getint('db_startup_parameter', 'max_backups')
     }
     GidSQLBuilder.database = in_db_class(_executor, _scripter, _backup_loc,
                                          _startup_dict)
Exemple #10
0
def pylisterer(in_file, in_list_name='LIST_1', in_out_file='default'):
    _output = pathmaker(
        r"D:\Dropbox\hobby\Modding\Ressources\assorted\pyListerer_output.py"
    ) if in_out_file == 'default' else in_out_file
    _lines = readit(in_file, per_lines=True, strip_n=True)
    writeit(_output, f"\n\n{in_list_name.upper()} = " + "[\n", append=True)
    for line in _lines:
        writeit(_output, f"        '{line}',\n", append=True)
    writeit(_output, "    ]\n\n", append=True)
Exemple #11
0
    def get_config(cls):
        if cls.cfg_object is None:
            try:
                _cfg = ConfigHandler(config_file=pathmaker(
                    os.getenv('AS_INDEX_CFG_FILE')),
                                     interpolation=ExtendedInterpolation())
            except Exception as error:
                log.error(
                    "Error while trying to create configreader from provided stdin filepath, error: %s",
                    error)
                log.error('Trying again with standard config')
                _old_cwd = os.getcwd()
                os.chdir(THIS_FILE_DIR)
                _cfg = ConfigHandler(
                    config_file=pathmaker(r"..\src\data\exp.ini"),
                    interpolation=ExtendedInterpolation())
                os.chdir(_old_cwd)
            cls.cfg_object = _cfg

        return cls.cfg_object
Exemple #12
0
    def delete_db_if_exist(self, backup=False, in_num_backups=2):
        self.db_exist()
        if self.db_status == 'EXISTING':
            if backup is True:
                _archive_path = gif.pathmaker(self.default_keys['main_dir'],
                                              self.db_parameter['archive_loc'])
                _db_archive_loc = gif.pathmaker(_archive_path, self.db_name)
                gif.limit_amount_of_files(gif.ext_splitter(self.db_name),
                                          _archive_path, in_num_backups)
                if os.path.exists(_db_archive_loc) is True:
                    _round = 1
                    _db_archive_loc = gif.number_rename(
                        gif.pathmaker(_db_archive_loc), _round)
                    log.debug(f" Backing up db as {_db_archive_loc}")

                shutil.copy(self.db, _db_archive_loc)

                log.info(f"copied db as backup to {_db_archive_loc}")

            os.remove(self.db)
            log.warning(f"removed {self.db_name}")
Exemple #13
0
 def __init__(self,
              in_executor,
              in_scripter,
              in_backup_folder,
              in_startup_dict=None):
     self.backup_folder = pathmaker('cwd', in_backup_folder)
     self.executor = in_executor
     self.scripter = in_scripter
     self.startup_dict = {
         'overwrite': False,
         'in_max_backup': 3
     } if in_startup_dict is None else in_startup_dict
     self.phrasers = {}
Exemple #14
0
def output_location(extension: str, suffix=None):
    _suffix = '' if suffix is None else f'_{suffix}'
    _name = CFG.get('general', 'output_file_name') + _suffix + '.' + extension
    _path = CFG.get_path('general', 'output_location').replace(
        'cfg_dir', os.path.dirname(os.getenv('AS_INDEX_CFG_FILE')))
    if os.path.exists(_path) is False:
        if '.' not in os.path.basename(_path):
            os.makedirs(_path)
        else:
            raise AttributeError(
                'path to create is not an folder but an file -- as it contains a "." in the name'
            )

    return pathmaker(_path, _name)
def find_path(path_fragment):
    """
    finds absolute path, to folder or file.


    Args:
        path_fragment (str): the fragment to find

    Returns:
        str: absolute path to the fragment
    """
    _main_dir = os.getenv('MAIN_DIR')
    with work_in(_main_dir):
        return pathmaker(os.path.abspath(list(iglob(f"**/{path_fragment}", recursive=bool))[0]))
Exemple #16
0
def pydicterer(in_file, in_dict_name='DICT_1', in_out_file='default'):
    _output = pathmaker(
        r"D:\Dropbox\hobby\Modding\Ressources\assorted\pyDicterer_output.py"
    ) if in_out_file == 'default' else in_out_file
    _lines = readit(in_file, per_lines=True, strip_n=True)
    writeit(_output, f"\n\n{in_dict_name.upper()} = " + "{\n", append=True)
    for line in _lines:
        try:
            key, value = line.split(';')
            writeit(_output,
                    f"        '{key}': '{str(value)}',\n",
                    append=True)
        except ValueError:
            log.debug(f"ValueError with line '{line}")
    writeit(_output, "    }\n\n", append=True)
Exemple #17
0
 def _backup_db(self, in_max_backup):
     if os.path.isdir(self.backup_folder) is False:
         os.makedirs(self.backup_folder)
     if os.path.isfile(self.executor.db_loc):
         _db_name = splitoff(self.executor.db_loc)[1]
         if os.path.isfile(pathmaker(self.backup_folder, _db_name)) is True:
             shutil.copy(
                 self.executor.db_loc,
                 cascade_rename(_db_name, self.backup_folder,
                                in_max_backup))
         else:
             shutil.copy(self.executor.db_loc, self.backup_folder)
         log.info(
             f"Database backup from '{self.executor.db_loc}' to {self.backup_folder} was completed"
         )
Exemple #18
0
 def __init__(self,
              in_config_loc='default',
              in_pragma=None,
              in_change_loc=False):
     GidConfigMaster.__init__(self,
                              config_name='db_config.ini',
                              config_loc=in_config_loc)
     self.change_loc = in_change_loc
     if self.change_loc is True:
         self.target_dir = gif.path_part_remove(self.config_location)
         with gif.work_in(self.target_dir):
             self.sections_as_attributes()
     else:
         self.sections_as_attributes()
     log.debug(f"cwd is [{self.default_keys['main_dir']}]")
     log.debug(f"database location is [{self.db_parameter['db_loc']}]")
     log.debug(f"database name  is [{self.db_parameter['db_name']}]")
     GiDataBaseMaster.__init__(self,
                               self.default_keys['main_dir'],
                               self.db_parameter['db_name'],
                               self.db_parameter['db_loc'],
                               gif.pathmaker(
                                   self.db_parameter['sql_script_folder']),
                               in_pragma=in_pragma)
Exemple #19
0
from gidtools.gidconfig import ConfigHandler

# endregion[Imports]

__updated__ = '2020-11-08 12:50:11'

# region [AppUserData]

# endregion [AppUserData]

# region [Logging]

log = glog.aux_logger(__name__)
log.info(glog.imported(__name__))

# endregion[Logging]

# region [Constants]

THIS_FILE_DIR = os.path.abspath(os.path.dirname(__file__))
BASE_CONFIG = ConfigHandler(pathmaker(THIS_FILE_DIR, "base_config.ini"))
COGS_CONFIG = ConfigHandler(pathmaker(THIS_FILE_DIR, 'cogs_config.ini'))
# endregion[Constants]

# region[Main_Exec]

if __name__ == '__main__':
    pass

# endregion[Main_Exec]
Exemple #20
0
 def from_fullpath(cls, full_path):
     cfile = gif.pathmaker(full_path)
     cfile = gif.splitoff(cfile)[1]
     cpath = gif.pathmaker(full_path)
     cpath = gif.splitoff(cpath)[0]
     return cls(cfile, cpath)
Exemple #21
0
def provide_prototype_config(in_path):
    with open(pathmaker(in_path, 'as_index.ini'), 'w') as protocfg:
        protocfg.write(PROTOTYPE_CONFIG)