Beispiel #1
0
    def check_resources(self, hint: Optional[str]) -> None:
        self._register_check(hint)

        if not self._validate_size():
            self._error("memory usage increased from %s to %s, exiting" % (
                render.fmt_bytes(self.memory_usage()),
                render.fmt_bytes(self._vm_size()),
            ))
            sys.exit(14)
Beispiel #2
0
 def _dump(self, header: str, sizes: Dict[str, int],
           limit: Optional[int]) -> None:
     self._warning("=== %s ====" % header)
     for varname, size_bytes in sorted(sizes.items(),
                                       key=lambda x: x[1],
                                       reverse=True)[:limit]:
         self._warning("%10s %s" % (render.fmt_bytes(size_bytes), varname))
Beispiel #3
0
def do_backup(tarname):
    console.verbose("Creating backup file '%s'...\n", tarname)
    tar = tarfile.open(tarname, "w:gz")

    for name, path, canonical_name, descr, is_dir, in backup_paths():

        absdir = os.path.abspath(path)
        if os.path.exists(path):
            if is_dir:
                subtarname = name + ".tar"
                subfile = StringIO.StringIO()
                subtar = tarfile.open(mode="w", fileobj=subfile, dereference=True)
                subtar.add(path, arcname=".")
                subdata = subfile.getvalue()
            else:
                subtarname = canonical_name
                subdata = open(absdir).read()

            info = tarfile.TarInfo(subtarname)
            info.mtime = time.time()
            info.uid = 0
            info.gid = 0
            info.size = len(subdata)
            info.mode = 0o644
            info.type = tarfile.REGTYPE
            info.name = subtarname
            console.verbose("  Added %s (%s) with a size of %s\n", descr, absdir,
                            render.fmt_bytes(info.size))
            tar.addfile(info, StringIO.StringIO(subdata))

    tar.close()
    console.verbose("Successfully created backup.\n")