コード例 #1
0
def cleanse_caches():
    # TODO: clean up .latexmkrc entries; not the whole file
    cache_dir = sg.configuration[sg.C_CACHE_DIR]
    if os.path.isdir(cache_dir):
        LOGGER.info("Cleaning all the caches... (" + cache_dir + ")")
        # avoids deleting the cache dir itself
        for root, folder_dirs, folder_files in os.walk(cache_dir):
            for name in folder_files:
                f = os.path.join(root, name)
                if not should_be_excluded(str(f)) and should_be_included(str(f)):
                    os.remove(f)
            for name in folder_dirs:
                f = os.path.join(root, name)
                if not should_be_excluded(str(f)) and should_be_included(str(f)):
                    shutil.rmtree(os.path.join(root, name))
    else:
        LOGGER.warning("No caches \"" + cache_dir +
                       "\" were found. Skipping...")
コード例 #2
0
def cmd_cleanse():
    sc.assure_dirs()
    # Delete all current log files
    # TODO: make this dry. avoid specifying the log files signature multiple times (see Recipe)
    LOGGER.info("Cleaning local logs...")
    clean_patterns = ['sltx-log-*.tar.gz',
                      'sltx-log-*.zip', 'sltx-drivers.log', '*.sltx-log']
    for clean_pattern in clean_patterns:
        for f in Path(".").glob(clean_pattern):
            if should_be_excluded(str(f)) or not should_be_included(str(f)):
                LOGGER.info("File " + str(f) + " excluded.")
            else:
                f.unlink()
    if sg.args.cleanse_all:
        texmf_home = su.get_sltx_tex_home()
        if os.path.isdir(texmf_home):
            LOGGER.error("Cleaning sltx-texmf-tree... (" + texmf_home + ")")
            shutil.rmtree(texmf_home)
        else:
            LOGGER.warning("The local sltx-texmf tree in \"" +
                           texmf_home + "\" was not found. Skipping...")

    if sg.args.cleanse_all or sg.args.cleanse_cache:
        cleanse_caches()
コード例 #3
0
ファイル: docker_mg.py プロジェクト: EagleoutIce/sltx
 def run_in_container(self, root: bool, profile: str, command: str):
     if profile.startswith(":"):
         target = profile[1:]
     else:
         target = DOCKER_URL.format(**locals())
     LOGGER.info("Launching container based on image: " + target)
     if root:
         LOGGER.warning(
             "Using root configuration. This might lead to permission errors in the future. "
             + target)
     # TODO: this must be expanded better and safer, this way only '~' might be used which is bad
     wd = sg.configuration[sg.C_WORKING_DIR].replace(
         os.path.expanduser('~'), '/root')
     LOGGER.info("  - Note: Working-Dir bound to: %s for %s", wd,
                 sg.configuration[sg.C_WORKING_DIR])
     LOGGER.info("  - Note: Main-Dir bound to: /root/data for " +
                 os.getcwd())
     volumes = {
         os.getcwd(): {
             'bind': '/root/data',
             'mount': 'rw'
         },
         sg.configuration[sg.C_WORKING_DIR]: {
             'bind': wd,
             'mount': 'rw'
         }
     }
     if sg.args.local_texmf:
         target_mount = "/usr/share/sltx/texmf"
         LOGGER.info("  - Note: Mounting local txmf-tree (%s) to %s",
                     su.get_tex_home(), target_mount)
         volumes[su.get_tex_home()] = {'bind': target_mount, 'mount': 'rw'}
     run = self.client.containers.run(
         target,
         command=command,
         detach=True,
         remove=False,
         working_dir='/root/data',
         tty=True,
         network_mode='bridge',
         user='******' if root else 'lithie-user',
         volumes=volumes)
     # We need a buffer in case a multibyte unicode sequence
     # will be broken at line end
     buffer = b''
     for l in run.logs(stdout=True,
                       stderr=True,
                       stream=True,
                       timestamps=True):
         try:
             LOGGER.info('\u0001' + (buffer + l).decode('utf-8'))
             buffer = b''
         except UnicodeDecodeError as ex:
             buffer += l
     LOGGER.info("Container completed.")
     feedback = run.wait()
     run.remove()
     if 'StatusCode' in feedback and feedback['StatusCode'] != 0:
         code = feedback['StatusCode']
         LOGGER.error("Command failed with: " + str(code))
         sys.exit(code)