def compress_files(files, archive, path=None, overwrite=True):
    """Compress `files` into an `archive` file

    Parameters
    ----------
    files : list of str
    archive : str
    path : str
      Alternative directory under which compressor will be invoked, to e.g.
      take into account relative paths of files and/or archive
    overwrite : bool
      Whether to allow overwriting the target archive file if one already exists
    """
    with swallow_outputs() as cmo:
        with chpwd(path):
            if not overwrite:
                patoolib.util.check_new_filename(archive)
            patoolib.util.check_archive_filelist(files)
            # Call protected one to avoid the checks on existence on unixified path
            patoolib._create_archive(unixify_path(archive),
                                     [unixify_path(f) for f in files],
                                     verbosity=100)
        if cmo.out:
            lgr.debug("patool gave stdout:\n%s", cmo.out)
        if cmo.err:
            lgr.debug("patool gave stderr:\n%s", cmo.err)
Пример #2
0
def compress_files(files, archive, path=None, overwrite=True):
    """Compress `files` into an `archive` file

    Parameters
    ----------
    files : list of str
    archive : str
    path : str
      Alternative directory under which compressor will be invoked, to e.g.
      take into account relative paths of files and/or archive
    overwrite : bool
      Whether to allow overwriting the target archive file if one already exists
    """
    with swallow_outputs() as cmo:
        with chpwd(path):
            if not overwrite:
                patoolib.util.check_new_filename(archive)
            patoolib.util.check_archive_filelist(files)
            # Call protected one to avoid the checks on existence on unixified path
            patoolib._create_archive(unixify_path(archive),
                                     [unixify_path(f) for f in files],
                                     verbosity=100)
        if cmo.out:
            lgr.debug("patool gave stdout:\n%s" % cmo.out)
        if cmo.err:
            lgr.debug("patool gave stderr:\n%s" % cmo.err)
Пример #3
0
def compress_files(files, archive, path=None, overwrite=True):
    """Compress `files` into an `archive` file

    Parameters
    ----------
    files : list of str
    archive : str
    path : str
      Alternative directory under which compressor will be invoked, to e.g.
      take into account relative paths of files and/or archive
    overwrite : bool
      Either to allow overwriting the target archive file if one already exists
    """

    with swallow_outputs() as cmo:
        # to test filenames, if path is not None, we should join:
        if path:
            opj_path = lambda p: opj(path, p)
        else:
            opj_path = lambda p: p
        if not overwrite:
            patoolib.util.check_new_filename(opj_path(archive))
        patoolib.util.check_archive_filelist([opj_path(f) for f in files])

        # ugly but what can you do? ;-) we might wrap it all into a class
        # at some point. TODO
        old_cwd = _runner.cwd
        if path is not None:
            _runner.cwd = path
        try:
            # Call protected one to avoid the checks on existence on unixified path
            patoolib._create_archive(unixify_path(archive),
                                     [unixify_path(f) for f in files],
                                     verbosity=100)
        finally:
            _runner.cwd = old_cwd

        if cmo.out:
            lgr.debug("patool gave stdout:\n%s" % cmo.out)
        if cmo.err:
            lgr.debug("patool gave stderr:\n%s" % cmo.err)
Пример #4
0
def compress_files(files, archive, path=None, overwrite=True):
    """Compress `files` into an `archive` file

    Parameters
    ----------
    files : list of str
    archive : str
    path : str
      Alternative directory under which compressor will be invoked, to e.g.
      take into account relative paths of files and/or archive
    overwrite : bool
      Either to allow overwriting the target archive file if one already exists
    """

    with swallow_outputs() as cmo:
        # to test filenames, if path is not None, we should join:
        if path:
            opj_path = lambda p: opj(path, p)
        else:
            opj_path = lambda p: p
        if not overwrite:
            patoolib.util.check_new_filename(opj_path(archive))
        patoolib.util.check_archive_filelist([opj_path(f) for f in files])

        # ugly but what can you do? ;-) we might wrap it all into a class
        # at some point. TODO
        old_cwd = _runner.cwd
        if path is not None:
            _runner.cwd = path
        try:
            # Call protected one to avoid the checks on existence on unixified path
            patoolib._create_archive(unixify_path(archive),
                                     [unixify_path(f) for f in files],
                                     verbosity=100)
        finally:
            _runner.cwd = old_cwd

        if cmo.out:
            lgr.debug("patool gave stdout:\n%s" % cmo.out)
        if cmo.err:
            lgr.debug("patool gave stderr:\n%s" % cmo.err)
Пример #5
0
def Archiver(input_file, output_dir, archive_int):
    while True:
        global sched_var
        print('Archiver: now looking at file:', input_file)
        time.sleep(archive_int * 60)  ## time sleep is in seconds
        input_name = os.path.basename(input_file)  ## extract name of file
        main_dir = os.path.dirname(input_file)  ## extract directory of file
        if not os.path.exists(main_dir + '/temp'):
            os.mkdir(main_dir + '/temp')
        shutil.copy(input_file, os.path.join(main_dir, 'temp'))
        tempfiledir = os.path.join(main_dir + '/temp/' + input_name)
        archName = input_name + "_" + time.strftime(
            "%H%M_%d%m%Y") + '.rar'  ##input name in correct format
        outputarch = os.path.join(output_dir + '/' +
                                  archName)  ## archived file in output dir
        patoolib._create_archive(
            resource_path(archName),
            (tempfiledir, ),
        )
        shutil.move(resource_path(archName), outputarch)
        if sched_var == False:
            print('Archiving off, sched_var is:', sched_var)
            break