Example #1
0
    def unpack_file_cond(self, pred, target_dir, archive_root = ''):
        """Unpack/Extract files according to predicate function
        pred: filename -> bool
        unpacks stuff into target_dir and only extracts files
        from archive_root, treating it as the archive root"""
        zip_obj = self.zip_obj
        for info in zip_obj.infolist():
            if pred(info.filename):   # check if condition holds

                # below code removes that, so we find it here
                is_dir = info.filename.endswith('/')

                # calculate output file name
                if archive_root == '':
                    outpath = info.filename
                else:
                    # change archive_root
                    if util.subpath(archive_root, info.filename):
                        outpath = util.removepathprefix(archive_root,
                                                        info.filename)
                    else:
                        continue        # don't extract if not under

                ofile = os.path.join(target_dir, outpath)

                if is_dir:               # this is a directory
                    if not os.path.isdir(ofile):
                        os.makedirs(ofile)
                        perm = info.external_attr
                        perm &= 0xFFFF0000
                        perm >>= 16
                        perm |= 0x00000100
                        os.chmod(ofile, perm)
                    continue

                # check that output dir is present
                util.check_dir(os.path.dirname(ofile))

                # remove output file we might be overwriting.
                # (also check for islink? for broken symlinks...)
                if os.path.isfile(ofile) or os.path.islink(ofile):
                    os.remove(ofile)

                if info.external_attr == self.symmagic:
                    if os.path.isdir(ofile):
                        shutil.rmtree(ofile) # a rare case, the file used to be a dir, now it is a symlink!
                    target = zip_obj.read(info.filename)
                    os.symlink(target, ofile)
                else:
                    perm = info.external_attr
                    perm &= 0x08FF0000
                    perm >>= 16
                    perm |= 0x00000100

                    if sys.version_info[:2] < (2, 6):
                        zip_obj.decompressToFile(info.filename, ofile)
                    else:
                        info.filename = outpath
                        zip_obj.extract(info, target_dir)
                    os.chmod(ofile, perm)
Example #2
0
    def unpack_file_cond(self, pred, target_dir, archive_root=''):
        """Unpack/Extract files according to predicate function
        pred: filename -> bool
        unpacks stuff into target_dir and only extracts files
        from archive_root, treating it as the archive root"""
        zip_obj = self.zip_obj
        for info in zip_obj.infolist():
            if pred(info.filename):  # check if condition holds

                # below code removes that, so we find it here
                is_dir = info.filename.endswith('/')

                # calculate output file name
                if archive_root == '':
                    outpath = info.filename
                else:
                    # change archive_root
                    if util.subpath(archive_root, info.filename):
                        outpath = util.removepathprefix(
                            archive_root, info.filename)
                    else:
                        continue  # don't extract if not under

                ofile = os.path.join(target_dir, outpath)

                if is_dir:  # this is a directory
                    d = os.path.join(target_dir, outpath)
                    if not os.path.isdir(d):
                        os.makedirs(d)
                        perm = info.external_attr
                        perm &= 0xFFFF0000
                        perm >>= 16
                        perm |= 0x00000100
                        os.chmod(d, perm)
                    continue

                # check that output dir is present
                util.check_dir(os.path.dirname(ofile))

                # remove output file we might be overwriting.
                # (also check for islink? for broken symlinks...)
                if os.path.isfile(ofile) or os.path.islink(ofile):
                    os.remove(ofile)

                if info.external_attr == self.symmagic:
                    if os.path.isdir(ofile):
                        shutil.rmtree(
                            ofile
                        )  # a rare case, the file used to be a dir, now it is a symlink!
                    target = zip_obj.read(info.filename)
                    os.symlink(target, ofile)
                else:
                    perm = info.external_attr
                    perm &= 0x08FF0000
                    perm >>= 16
                    perm |= 0x00000100
                    zip_obj.decompressToFile(info.filename, ofile)
                    os.chmod(ofile, perm)
Example #3
0
    def unpack_file_cond(self, pred, target_dir, archive_root = ''):
        """Unpack/Extract files according to predicate function
        pred: filename -> bool 
        unpacks stuff into target_dir and only extracts files
        from archive_root, treating it as the archive root"""
        zip_obj = self.zip_obj
        for info in zip_obj.infolist():
            if pred(info.filename):   # check if condition holds

                # below code removes that, so we find it here
                is_dir = info.filename.endswith('/')
                
                # calculate output file name
                if archive_root == '':
                    outpath = info.filename
                else:
                    # change archive_root
                    if util.subpath(archive_root, info.filename):
                        outpath = util.removepathprefix(archive_root,
                                                        info.filename)
                    else:
                        continue        # don't extract if not under

                ofile = os.path.join(target_dir, outpath)

                if is_dir:               # this is a directory
                    d = os.path.join(target_dir, outpath)
                    if not os.path.isdir(d):
                        os.makedirs(d)
                        perm = info.external_attr
                        perm &= 0xFFFF0000
                        perm >>= 16
                        perm |= 0x00000100
                        os.chmod(d, perm)
                    continue

                # check that output dir is present
                util.check_dir(os.path.dirname(ofile))

                # remove output file we might be overwriting.
                # (also check for islink? for broken symlinks...)
                if os.path.exists(ofile) or os.path.islink(ofile):
                    os.remove(ofile)
 
                if info.external_attr == self.symmagic:
                    target = zip_obj.read(info.filename)
                    os.symlink(target, ofile)
                else:
                    perm = info.external_attr
                    perm &= 0x08FF0000
                    perm >>= 16
                    perm |= 0x00000100
                    buff = open (ofile, 'wb')
                    file_content = zip_obj.read(info.filename)
                    buff.write(file_content)
                    buff.close()
                    os.chmod(ofile, perm)
Example #4
0
    def __init__(self, url, dest):
        if not isinstance(url, URI):
            url = URI(url)
 
        self.url = url
        self.filedest = dest
        util.check_dir(self.filedest)
        self.percent = 0
        self.rate = 0.0
        self.progress = None
Example #5
0
    def extract_file_synced(self, path, outdir):
        """Extract file with path to outdir"""
        data = self.impl.read_file(path)
        fpath = util.join_path(outdir, path)
        util.check_dir(os.path.dirname(fpath))

        with open(fpath, "wb") as f:
            f.write(data)
            f.flush()
            os.fsync(f.fileno())
Example #6
0
 def __init__(self, id):
     util.check_dir(ctx.config.db_dir())
     self.fname = os.path.join(ctx.config.db_dir(), 'package-%s.bdb' % id )
     self.fname2 = os.path.join(ctx.config.db_dir(), 'revdep-%s.bdb'  % id )
     self.lockfile = file(self.fname + '.lock', 'w')
     try:
         fcntl.flock(self.lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
     except IOError, e:
          import sys
          ctx.ui.error("PackageDB: %s" % e)
          sys.exit(1)
Example #7
0
    def __init__(self, url, dest):
        if not isinstance(url, URI):
            url = URI(url)
 
        self.scheme = url.scheme()
        self.url = url
        self.filedest = dest
        util.check_dir(self.filedest)
        self.eta = '??:??:??'
        self.percent = 0
        self.rate = 0.0
        self.progress = None
        self.existsize = 0
Example #8
0
    def __init__(self, url, destdir):
        if not isinstance(url, pisi.uri.URI):
            url = pisi.uri.URI(url)

        if ctx.config.get_option("authinfo"):
            url.set_auth_info(ctx.config.get_option("authinfo"))

        self.url      = url
        self.destdir  = destdir
        self.archive_file = os.path.join(self.destdir, self.url.filename())
        self.partial_file = self.archive_file + '.part'
        self.progress = None

        util.check_dir(self.destdir)
Example #9
0
    def __init__(self, url, destdir):
        if not isinstance(url, pisi.uri.URI):
            url = pisi.uri.URI(url)

        if ctx.config.get_option("authinfo"):
            url.set_auth_info(ctx.config.get_option("authinfo"))

        self.url = url
        self.destdir = destdir
        self.archive_file = os.path.join(self.destdir, self.url.filename())
        self.partial_file = self.archive_file + '.part'
        self.progress = None

        util.check_dir(self.destdir)
Example #10
0
    def __init__(self, url, destdir, resume = True):
        if not isinstance(url, URI):
            url = URI(url)
 
        self.resume = resume
        self.scheme = url.scheme()
        self.url = url
        self.destdir = destdir
        util.check_dir(self.destdir)
        self.eta = '??:??:??'
        self.percent = 0
        self.rate = 0.0
        self.progress = None
        self.exist_size = 0
Example #11
0
    def __init__(self, url, destdir, resume = True):
        if not isinstance(url, URI):
            url = URI(url)
 
        if ctx.config.get_option("authinfo"):
            url.set_auth_info(ctx.config.get_option("authinfo"))

        self.resume = resume
        self.scheme = url.scheme()
        self.url = url
        self.destdir = destdir
        util.check_dir(self.destdir)
        self.eta = '??:??:??'
        self.percent = 0
        self.rate = 0.0
        self.progress = None
        self.exist_size = 0
Example #12
0
    def __init__(self, url, destdir, resume=True):
        if not isinstance(url, URI):
            url = URI(url)

        if ctx.config.get_option("authinfo"):
            url.set_auth_info(ctx.config.get_option("authinfo"))

        self.resume = resume
        self.scheme = url.scheme()
        self.url = url
        self.destdir = destdir
        util.check_dir(self.destdir)
        self.eta = '??:??:??'
        self.percent = 0
        self.rate = 0.0
        self.progress = None
        self.exist_size = 0
Example #13
0
 def testCopy(self):
     self.spec.read("tests/popt/pspec.xml")
     util.check_dir(ctx.config.tmp_dir())
     self.spec.write(os.path.join(ctx.config.tmp_dir(), 'popt-copy.pspec.xml'))
Example #14
0
 def __init__(self):
     util.check_dir(ctx.config.db_dir())
     self.filename = os.path.join(ctx.config.db_dir(), 'source.bdb')
     self.d = shelve.open(self.filename)
     self.fdummy = file(self.filename + '.lock', 'w')
     fcntl.flock(self.fdummy, fcntl.LOCK_EX)