Beispiel #1
0
 def copy(self):
     try:
         if not os.path.isdir(util.unix_dirname(self.dst)):
             os.makedirs(util.unix_dirname(self.dst))
         if os.path.isfile(self.dst):
             if not os.access(self.dst, os.W_OK):
                 os.remove(self.dst)
         if os.path.islink(self.src):
             self.copysymlink(self.src, self.dst)
         else:
             self.copyfile(self.src, self.dst)
             shutil.copystat(self.src, self.dst)
     except Exception as e:
         message.exception(e)
         raise FilectrlCancel("Exception occurred while copying")
Beispiel #2
0
    def chdir(self, path):
        parpath = util.unix_dirname(self.path)
        parfile = util.unix_basename(self.path)
        newpath = util.abspath(util.expanduser(path), self.path)
        if newpath == self.path:
            return

        self.list = None
        self.list_title = None
        if self.finder.active:
            self.finder.finish()
        self.mark_clear()

        try:
            os.chdir(newpath)
        except Exception as e:
            return message.exception(e)
        self.history.update(newpath)
        self.path = newpath
        self.diskread()
        self.sort()
        if self.path == parpath:
            self.setcursor(self.get_index(parfile))
        else:
            self.setcursor(0)
Beispiel #3
0
    def extract_file(self, myzip, zipinfo):
        fname = zipinfo.filename
        ufname = util.force_decode(fname)
        path = os.path.join(self.dstdir, ufname)

        if stat.S_ISDIR(zipinfo.external_attr >> 16):
            dirpath = os.path.join(self.dstdir, ufname)
            if not os.path.exists(dirpath):
                os.makedirs(dirpath)
            self.dirlist.append(fname)
        else:
            dirpath = os.path.join(self.dstdir, util.unix_dirname(ufname))
            if not os.path.exists(dirpath):
                os.makedirs(dirpath)
            source = myzip.open(fname)
            try:
                target = open(path, "wb")
                self.update("Inflating: {0}".format(ufname))
                shutil.copyfileobj(source, target)
                self.notify("Inflated: {0}".format(ufname))
                source.close()
                target.close()
                self.copy_external_attr(myzip, fname)
            except IOError as e:
                if e[0] == errno.EISDIR:
                    self.dirlist.append(fname)
Beispiel #4
0
 def move(self):
     try:
         if not os.path.isdir(util.unix_dirname(self.dst)):
             os.makedirs(util.unix_dirname(self.dst))
         if os.path.isfile(self.dst):
             if not os.access(self.dst, os.W_OK):
                 os.remove(self.dst)
         os.rename(self.src, self.dst)
     except Exception as e:
         if errno.EXDEV == e[0]:
             self.copy()
             try:
                 os.remove(self.src)
             except Exception as e:
                 message.exception(e)
                 raise FilectrlCancel("Exception occurred while removing")
         else:
             message.exception(e)
             raise FilectrlCancel("Exception occurred while moving")
Beispiel #5
0
 def savefile(self, path):
     path = os.path.expanduser(path)
     dirname = util.unix_dirname(path)
     try:
         os.makedirs(dirname)
     except OSError:
         pass
     try:
         with open(path, "w") as f:
             f.write("\n".join(self.clip))
     except IOError:
         return
Beispiel #6
0
 def __init__(self, src, dst, wrap=""):
     JobThread.__init__(self)
     if not dst.endswith(".zip"):
         dst += ".zip"
     self.dst = util.abspath(dst)
     if isinstance(src, list):
         self.title = "Zip: mark files -> {0}".format(dst)
         self.src = [util.abspath(f) for f in src]
         self.src_dirname = util.U(os.getcwd()) + os.sep
     else:
         self.title = "Zip: {0} -> {1}".format(src, dst)
         self.src = [util.abspath(src)]
         self.src_dirname = util.unix_dirname(self.src[0]) + os.sep
     self.wrap = wrap
Beispiel #7
0
 def __init__(self, src, dst, tarmode="gzip", wrap=""):
     JobThread.__init__(self)
     self.update("Reading...")
     ext = self.tarexts[tarmode]
     if not dst.endswith(ext):
         dst += ext
     self.dst = util.abspath(dst)
     if isinstance(src, list):
         self.title = "Tar: mark files -> {0}".format(dst)
         self.src = [util.abspath(f) for f in src]
         self.src_dirname = util.U(os.getcwd()) + os.sep
     else:
         self.title = "Tar: {0} -> {1}".format(src, dst)
         self.src = [util.abspath(src)]
         self.src_dirname = util.unix_dirname(self.src[0]) + os.sep
     self.tarmode = tarmode
     self.wrap = wrap
Beispiel #8
0
    def generate(self, src, dst, moving, join=False):
        def _checkfile(src, dst):
            ret = self.check_override(src, dst)
            if ret == "Cancel":
                raise FilectrlCancel("Filejob canceled: {0} -> {1}".format(src, dst))
            if ret == "Yes":
                return FileJob(src, dst)

        def _checkdir(src, dst):
            copypair = None
            if not os.path.isdir(dst):
                copypair = (os.stat(src), dst)

            for f in os.listdir(src):
                ssub = os.path.join(src, f)
                dsub = os.path.join(dst, f)
                if os.path.isdir(ssub) and not os.path.islink(ssub):
                    for checked in _checkdir(ssub, dsub):
                        yield checked
                else:
                    yield _checkfile(ssub, dsub)
            if copypair:
                self.copydir(copypair)
            if moving:
                self.removedir(src)

        if join or os.path.isdir(dst) or dst.endswith(os.sep):
            dst = os.path.join(dst, util.unix_basename(src))

        if util.unix_dirname(dst).startswith(src):
            raise FilectrlCancel("Cannot copy/move a directory, `{0}', into itself, `{1}'".format(src, dst))

        if os.path.isdir(src) and not os.path.islink(src):
            for checked in _checkdir(src, dst):
                yield checked
        else:
            yield _checkfile(src, dst)