Пример #1
0
    def filter_clean(self):
        """The clean filter is run when a bigfile is staged.

        It replaces the bigfile received on stdin with its SHA.
        """
        data, sha = self._check_stdin()
        # if data is a sha, just output (this is an unexpanded bigfile)
        # otherwise read in buffered chunks of the data
        # calculating the SHA and copying to a temporary file
        if sha is None:
            temp = tempfile.NamedTemporaryFile(dir=util.get_bigfile_dir('tmp'),
                                               delete=False)
            hashfunc = hashlib.sha1()
            while True:
                hashfunc.update(data)
                temp.write(data)
                data = sys.stdin.read(4096)
                if not data:
                    break
            # Calculate the SHA of the data
            sha = hashfunc.hexdigest()
            # Rename the temporary file
            temp.close()
            bigfile = os.path.join(self._objects, sha)
            os.rename(temp.name, bigfile)
            sys.stderr.write('Saving bigfile: %s\n' % sha)
        print sha
Пример #2
0
    def filter_clean(self):
        """The clean filter is run when a bigfile is staged.

        It replaces the bigfile received on stdin with its SHA.
        """
        data, sha = self._check_stdin()
        # if data is a sha, just output (this is an unexpanded bigfile)
        # otherwise read in buffered chunks of the data
        # calculating the SHA and copying to a temporary file
        if sha is None:
            temp = tempfile.NamedTemporaryFile(dir=util.get_bigfile_dir('tmp'), delete=False)
            hashfunc = hashlib.sha1()
            while True:
                hashfunc.update(data)
                temp.write(data)
                data = sys.stdin.read(4096)
                if not data:
                    break
            # Calculate the SHA of the data
            sha = hashfunc.hexdigest()
            # Rename the temporary file
            temp.close()
            bigfile = os.path.join(self._objects, sha)
            os.rename(temp.name, bigfile)
            sys.stderr.write('Saving bigfile: %s\n' % sha)
        print sha
Пример #3
0
    def clear(self):
        """Remove pushed files from cache"""
        # TODO(csilvers): short-circuit if self.objects() is the empty dir.
        pushed_files = self.transport().pushed()
        for sha in pushed_files:
            cache_file = os.path.join(self.objects(), sha)
            try:
                os.unlink(cache_file)
                print 'Removing %s from cache' % sha[:8]
            except OSError as e:
                if e.errno == errno.ENOENT:
                    pass
                else:
                    raise

        # We can also delete the entire tmp dir, which should be empty.
        temp_dir = util.get_bigfile_dir('tmp')
        temp_files = os.listdir(temp_dir)
        if temp_files:
            print 'Removing %s objects from the temp-dir' % len(temp_files)
            for filename in temp_files:
                os.unlink(os.path.join(temp_dir, filename))
Пример #4
0
    def clear(self):
        """Remove pushed files from cache"""
        # TODO(csilvers): short-circuit if self.objects() is the empty dir.
        pushed_files = self.transport().pushed()
        for sha in pushed_files:
            cache_file = os.path.join(self.objects(), sha)
            try:
                os.unlink(cache_file)
                print 'Removing %s from cache' % sha[:8]
            except OSError as e:
                if e.errno == errno.ENOENT:
                    pass
                else:
                    raise

        # We can also delete the entire tmp dir, which should be empty.
        temp_dir = util.get_bigfile_dir('tmp')
        temp_files = os.listdir(temp_dir)
        if temp_files:
            print 'Removing %s objects from the temp-dir' % len(temp_files)
            for filename in temp_files:
                os.unlink(os.path.join(temp_dir, filename))
Пример #5
0
 def __init__(self):
     self._objects = util.get_bigfile_dir('objects')
     self._repo_path = util.get_repo_dir()
     self._config = util.get_git_config()
     self._transport = self._get_transport()
Пример #6
0
 def __init__(self):
     self._objects = util.get_bigfile_dir('objects')
     self._repo_path = util.get_repo_dir()
     self._config = util.get_git_config()
     self._transport = self._get_transport()
Пример #7
0
 def objects(self):
     if self._objects is None:
         self._objects = util.get_bigfile_dir('objects')
     return self._objects
Пример #8
0
 def _get_tempfile(self):
     """Return a File object of a temporary file. It is not auto-deleted."""
     return tempfile.NamedTemporaryFile(dir=util.get_bigfile_dir('tmp'),
                                        delete=False)
Пример #9
0
 def objects(self):
     if self._objects is None:
         self._objects = util.get_bigfile_dir('objects')
     return self._objects
Пример #10
0
 def _get_tempfile(self):
     """Return a File object of a temporary file. It is not auto-deleted."""
     return tempfile.NamedTemporaryFile(dir=util.get_bigfile_dir('tmp'),
                                        delete=False)