Example #1
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 os.path.isdir(directorypath):
        dhnio.Dprint(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'
    # dhnio.Dprint(14, "backup_tar.backuptar %s %s compress=%s" % (directorypath, subdirs, compress))
    if dhnio.Windows():
        if dhnio.isFrozen():
            commandpath = "dhnbackup.exe"
            cmdargs = [commandpath, subdirs, compress, directorypath]
        else:
            commandpath = "dhnbackup.py"
            cmdargs = [sys.executable, commandpath, subdirs, compress, directorypath]
    else:
        commandpath = "dhnbackup.py"
        cmdargs = [sys.executable, commandpath, subdirs, compress, directorypath]
    if not os.path.isfile(commandpath):
        dhnio.Dprint(1, 'backup_tar.backuptar ERROR %s not found' % commandpath)
        return None
    # dhnio.Dprint(14, "backup_tar.backuptar going to execute %s" % str(cmdargs))
    # p = run(cmdargs)
    p = child_process.pipe(cmdargs)
    return p
Example #2
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):
        dhnio.Dprint(1, 'backup_tar.backuptarfile ERROR %s not found' % filepath)
        return None
    if compress is None:
        compress = 'none'
    # dhnio.Dprint(14, "backup_tar.backuptarfile %s compress=%s" % (filepath, compress))
    if dhnio.Windows():
        if dhnio.isFrozen():
            commandpath = "dhnbackup.exe"
            cmdargs = [commandpath, 'nosubdirs', compress, filepath]
        else:
            commandpath = "dhnbackup.py"
            cmdargs = [sys.executable, commandpath, 'nosubdirs', compress, filepath]
    else:
        commandpath = "dhnbackup.py"
        cmdargs = [sys.executable, commandpath, 'nosubdirs', compress, filepath]
    if not os.path.isfile(commandpath):
        dhnio.Dprint(1, 'backup_tar.backuptarfile ERROR %s not found' % commandpath)
        return None
    # dhnio.Dprint(12, "backup_tar.backuptarfile going to execute %s" % str(cmdargs))
    # p = run(cmdargs)
    p = child_process.pipe(cmdargs)
    return p
Example #3
0
def extracttar(tarfile, outdir):
    """
    Opposite method, run dhnbackup to extract files and folders from ".tar" file.
    """
    if not os.path.isfile(tarfile):
        dhnio.Dprint(1, 'backup_tar.extracttar ERROR %s not found' % tarfile)
        return None
    # dhnio.Dprint(12, "backup_tar.extracttar %s %s" % (tarfile, outdir))
    if dhnio.Windows():
        if dhnio.isFrozen():
            commandpath = 'dhnbackup.exe'
            cmdargs = [commandpath, 'extract', tarfile, outdir]
        else:
            commandpath = "dhnbackup.py"
            cmdargs = [sys.executable, commandpath, 'extract', tarfile, outdir]
    else:
        commandpath = "dhnbackup.py"
        cmdargs = [sys.executable, commandpath, 'extract', tarfile, outdir]
    if not os.path.isfile(commandpath):
        dhnio.Dprint(1, 'backup_tar.extracttar ERROR %s is not found' % commandpath)
        return None
    # p = run(cmdargs)
    p = child_process.pipe(cmdargs)
    return p