Пример #1
0
def backuptardir(directorypath, arcname=None, recursive_subfolders=True, compress=None):
    """
    Returns file descriptor for process that makes tar archive.

    In other words executes a child process and create a Pipe to
    communicate with it.
    """
    if not bpio.pathIsDir(directorypath):
        lg.out(1, 'backup_tar.backuptar ERROR %s not found' % directorypath)
        return None
    subdirs = 'subdirs'
    if not recursive_subfolders:
        subdirs = 'nosubdirs'
    if compress is None:
        compress = 'none'
    if arcname is None:
        arcname = strng.to_text(os.path.basename(directorypath))
    # lg.out(14, "backup_tar.backuptar %s %s compress=%s" % (directorypath, subdirs, compress))
    if bpio.Windows():
        if bpio.isFrozen():
            commandpath = "bppipe.exe"
            cmdargs = [commandpath, subdirs, compress, directorypath, arcname]
        else:
            commandpath = "bppipe.py"
            cmdargs = [sys.executable, commandpath, subdirs, compress, directorypath, arcname]
    else:
        commandpath = "bppipe.py"
        cmdargs = [sys.executable, commandpath, subdirs, compress, directorypath, arcname]
    if not os.path.isfile(commandpath):
        lg.out(1, 'backup_tar.backuptar ERROR %s not found' % commandpath)
        return None
    # lg.out(14, "backup_tar.backuptar going to execute %s" % str(cmdargs))
    # p = child_process.run('bppipe', cmdargs[2:])
    p = child_process.pipe(cmdargs)
    return p
Пример #2
0
def backuptarfile(filepath, arcname=None, compress=None):
    """
    Almost same - returns file descriptor for process that makes tar archive.
    But tar archive is created from single file, not folder.
    """
    if not os.path.isfile(filepath):
        lg.out(1, 'backup_tar.backuptarfile ERROR %s not found' % filepath)
        return None
    if compress is None:
        compress = 'none'
    if arcname is None:
        arcname = strng.to_text(os.path.basename(filepath))
    # lg.out(14, "backup_tar.backuptarfile %s compress=%s" % (filepath, compress))
    if bpio.Windows():
        if bpio.isFrozen():
            commandpath = "bppipe.exe"
            cmdargs = [commandpath, 'nosubdirs', compress, filepath, arcname]
        else:
            commandpath = "bppipe.py"
            cmdargs = [sys.executable, commandpath, 'nosubdirs', compress, filepath, arcname]
    else:
        commandpath = "bppipe.py"
        cmdargs = [sys.executable, commandpath, 'nosubdirs', compress, filepath, arcname]
    if not os.path.isfile(commandpath):
        lg.out(1, 'backup_tar.backuptarfile ERROR %s not found' % commandpath)
        return None
    # lg.out(12, "backup_tar.backuptarfile going to execute %s" % str(cmdargs))
    # p = run(cmdargs)
    p = child_process.pipe(cmdargs)
    return p
Пример #3
0
def extracttar(tarfile, outdir):
    """
    Opposite method, run bppipe to extract files and folders from ".tar" file.
    """
    if not os.path.isfile(tarfile):
        lg.out(1, 'backup_tar.extracttar ERROR %s not found' % tarfile)
        return None
    lg.out(6, "backup_tar.extracttar %s %s" % (tarfile, outdir))
    if bpio.Windows():
        if bpio.isFrozen():
            commandpath = 'bppipe.exe'
            cmdargs = [commandpath, 'extract', tarfile, outdir]
        else:
            commandpath = "bppipe.py"
            cmdargs = [sys.executable, commandpath, 'extract', tarfile, outdir]
    else:
        commandpath = "bppipe.py"
        cmdargs = [sys.executable, commandpath, 'extract', tarfile, outdir]
    if not os.path.isfile(commandpath):
        lg.out(1, 'backup_tar.extracttar ERROR %s is not found' % commandpath)
        return None
    # p = run(cmdargs)
    cmdargs = [strng.to_text(a) for a in cmdargs]
    p = child_process.pipe(cmdargs)
    return p
Пример #4
0
def backuptarfile(filepath, compress=None):
    """
    Almost same - returns file descriptor for process that makes tar archive.
    But tar archive is created from single file, not folder.
    """
    if not os.path.isfile(filepath):
        lg.out(1, 'backup_tar.backuptarfile ERROR %s not found' % filepath)
        return None
    if compress is None:
        compress = 'none'
    # lg.out(14, "backup_tar.backuptarfile %s compress=%s" % (filepath, compress))
    if bpio.Windows():
        if bpio.isFrozen():
            commandpath = "bppipe.exe"
            cmdargs = [commandpath, 'nosubdirs', compress, filepath]
        else:
            commandpath = "bppipe.py"
            cmdargs = [sys.executable, commandpath, 'nosubdirs', compress, filepath]
    else:
        commandpath = "bppipe.py"
        cmdargs = [sys.executable, commandpath, 'nosubdirs', compress, filepath]
    if not os.path.isfile(commandpath):
        lg.out(1, 'backup_tar.backuptarfile ERROR %s not found' % commandpath)
        return None
    # lg.out(12, "backup_tar.backuptarfile going to execute %s" % str(cmdargs))
    # p = run(cmdargs)
    p = child_process.pipe(cmdargs)
    return p
Пример #5
0
def backuptar(directorypath, recursive_subfolders=True, compress=None):
    """
    Returns file descriptor for process that makes tar archive.

    In other words executes a child process and create a Pipe to
    communicate with it.
    """
    if not bpio.pathIsDir(directorypath):
        lg.out(1, 'backup_tar.backuptar ERROR %s not found' % directorypath)
        return None
    subdirs = 'subdirs'
    if not recursive_subfolders:
        subdirs = 'nosubdirs'
    if compress is None:
        compress = 'none'
    # lg.out(14, "backup_tar.backuptar %s %s compress=%s" % (directorypath, subdirs, compress))
    if bpio.Windows():
        if bpio.isFrozen():
            commandpath = "bppipe.exe"
            cmdargs = [commandpath, subdirs, compress, directorypath]
        else:
            commandpath = "bppipe.py"
            cmdargs = [sys.executable, commandpath, subdirs, compress, directorypath]
    else:
        commandpath = "bppipe.py"
        cmdargs = [sys.executable, commandpath, subdirs, compress, directorypath]
    if not os.path.isfile(commandpath):
        lg.out(1, 'backup_tar.backuptar ERROR %s not found' % commandpath)
        return None
    # lg.out(14, "backup_tar.backuptar going to execute %s" % str(cmdargs))
    # p = child_process.run('bppipe', cmdargs[2:])
    p = child_process.pipe(cmdargs)
    return p
Пример #6
0
def extracttar(tarfile, outdir):
    """
    Opposite method, run bppipe to extract files and folders from ".tar" file.
    """
    if not os.path.isfile(tarfile):
        lg.out(1, 'backup_tar.extracttar ERROR %s not found' % tarfile)
        return None
    lg.out(6, "backup_tar.extracttar %s %s" % (tarfile, outdir))
    if bpio.Windows():
        if bpio.isFrozen():
            commandpath = 'bppipe.exe'
            cmdargs = [commandpath, 'extract', tarfile, outdir]
        else:
            commandpath = "bppipe.py"
            cmdargs = [sys.executable, commandpath, 'extract', tarfile, outdir]
    else:
        commandpath = "bppipe.py"
        cmdargs = [sys.executable, commandpath, 'extract', tarfile, outdir]
    if not os.path.isfile(commandpath):
        lg.out(1, 'backup_tar.extracttar ERROR %s is not found' % commandpath)
        return None
    # p = run(cmdargs)
    p = child_process.pipe(cmdargs)
    return p