Exemplo n.º 1
0
def archive(src, zippath, exclude=None, ziptype="ZIP"):
    logger.info("archive: src=[%s], zippath=[%s], exclude=[%s], type=[%s]", src, zippath, exclude, ziptype)
    
    dirpath = os.path.dirname(zippath)
    if not os.path.exists(dirpath):
        fs.mkpath(dirpath)
    
    if ziptype == "ZIP":
        zipobj = zipfile.ZipFile(zippath, "w")
        if os.path.isdir(src):
            for found in fs.find(src, exclude=exclude):
                logger.debug("found: %s", found)
                relname = os.path.relpath(found, src)
                if relname != ".":
                    relname = relname.replace("\\", "/")
                    if os.path.isdir(found):
                        relname += "/"
                    zipobj.write(found, relname)
        else:
            zipobj.write(src, os.path.basename(src))
        zipobj.close()
    elif ziptype == "GZ" or ziptype == "BZ2":
        raise
    else:
        raise Exception("unsupported archive type")
Exemplo n.º 2
0
 def bak(disk, dirpath, dst):
     File.mkpath(dirpath)
     OS.linux.mount(disk, dirpath, "ext4")
     File.copy(dirpath, "%s.cache" % dirpath)
     
     zipfile = "%s%s.zip" % (dst, dirpath)
     if os.path.exists(zip):
         logger.debug("backup zip file '%s' exist, skip to backup", zipfile)
     else:
         logger.debug("backup zip file '%s' not exist, do the backup", zipfile)
         Zip.archive("%s.cache" % dirpath, zip)
Exemplo n.º 3
0
 def getdir(rsrc, ldst, exclude):
     fs.mkpath(ldst)
     for name in self.listdir(rsrc):
         rsrcname = posixpath.join(rsrc, name)
         if exclude and exclude.search(rsrcname):
             logger.info("scp get: skip %s", rsrcname)
             continue
         ldstname = os.path.join(ldst, name)
         if self._isdir(rsrcname):
             getdir(rsrcname, ldstname, exclude)
         else:
             logger.debug("scp get: %s -> %s", rsrcname, ldstname)
             self.get(rsrcname, ldstname)
Exemplo n.º 4
0
 def _adjustTestCaseLogPath(self, test):
     newlogdir = None
     if test.record.status == test.record.FAILED:
         newlogdir = os.path.join(self.logdir, "failed")
     elif test.record.status == test.record.ERRONEOUS:
         newlogdir = os.path.join(self.logdir, "erroneous")
     elif test.record.status == test.record.WARNING:
         newlogdir = os.path.join(self.logdir, "warning")
     else:
         pass
     if newlogdir is not None:
         fs.mkpath(newlogdir)
         test.logdir = newlogdir
         fs.move(test.logname, newlogdir)
         test.logname = os.path.join(newlogdir, os.path.basename(test.logname))
         for index in range(len(test.extlognames)):
             extlogname = test.extlognames[index]
             fs.move(extlogname, newlogdir)
             test.extlognames[index] = os.path.join(newlogdir, os.path.basename(extlogname))
Exemplo n.º 5
0
    def run(self, result, debug=False):
        context = TestContextManager().getCurrentContext()
        context.curtsuite = self
        if self.logdir is None:
            self.logdir = os.path.join(context.logdir, self.name)
        fs.mkpath(self.logdir)

        self._toplevel = False
        if getattr(result, '_testRunEntered', False) is False:
            result._testRunEntered = self._toplevel = True

        self._runTests(result, debug)

        if self._toplevel:
            self._tearDownPreviousClass(None, result)
            self._handleModuleTearDown(result)
            result._testRunEntered = False

            result.suiteRecords.append(self.record)
        return result
Exemplo n.º 6
0
    def scp_get(self, rsrc, ldst, exclude=None):
        logger.info("scp get: rsrc=%s, ldst=%s, exclude=%s", rsrc, ldst, exclude)

        if exclude is not None and not isinstance(exclude, re._pattern_type):
            exclude = re.compile(exclude)

        def getdir(rsrc, ldst, exclude):
            fs.mkpath(ldst)
            for name in self.listdir(rsrc):
                rsrcname = posixpath.join(rsrc, name)
                if exclude and exclude.search(rsrcname):
                    logger.info("scp get: skip %s", rsrcname)
                    continue
                ldstname = os.path.join(ldst, name)
                if self._isdir(rsrcname):
                    getdir(rsrcname, ldstname, exclude)
                else:
                    logger.debug("scp get: %s -> %s", rsrcname, ldstname)
                    self.get(rsrcname, ldstname)
                                
        if self._isdir(rsrc):
            getdir(rsrc, ldst, exclude)
        else:
            ldstpath = None
            name = os.path.basename(rsrc)
            if os.path.exists(ldst):
                if os.path.isdir(ldst):
                    ldstpath = posixpath.join(ldst, name)
                else:
                    ldstpath = ldst
            else:
                if ldst.endswith("\\") or ldst.endswith("/"):
                    fs.mkpath(ldst)
                    ldstpath = posixpath.join(ldst, name)
                else:
                    fs.mkpath(os.path.dirname(ldst))
                    ldstpath = ldst
            logger.debug("scp get: %s -> %s", rsrc, ldstpath)
            self.get(rsrc, ldstpath)