def create(cls, fileobj, dest): try: mode = int(fileobj.permission(), 8) # in octal, e.g. 0755 os.makedirs(dest, mode) except OSError, e: # It may be OK, ex. !root user cannot set perms. logging.debug( "Failed (may be ignorable): os.makedirs, dest=%s, mode=%o" % \ (dest, mode) ) logging.warn(e) logging.info("Skipped: " + dest) if not os.path.exists(dest): run("mkdir -p " + dest)
def copy_impl(cls, fileobj, dest): """ Copy the file of fileobj to dest. Two steps needed to keep the content and metadata of the original file: 1. Copy itself and its some metadata (owner, mode, etc.) 2. Copy extra metadata not copyable with the above. "cp -a" (cp in GNU coreutils) does the above operations at once and might be suited for most cases, I think. @fileobj FileObjects instance @dest str Destination path to copy to """ run("cp -a %s %s" % (fileobj.src, dest))
def shell(self, cmd_s, workdir=None, **kwargs): """ Run shell command. """ if workdir is None: workdir = self.workdir return S.run(cmd_s, workdir=workdir, **kwargs)
def copy_impl(cls, fileobj, dest): if cls.link_instead_of_copy: cls.create(fileobj, dest) else: run("cp -a %s %s" % (fileobj.path, dest))