コード例 #1
0
ファイル: command.py プロジェクト: sharpglasses/git-bigfile
    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
ファイル: command.py プロジェクト: beenje/git-bigfile
    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
ファイル: command.py プロジェクト: ashang/git-bigfile
    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
ファイル: command.py プロジェクト: Khan/git-bigfile
    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
ファイル: command.py プロジェクト: sharpglasses/git-bigfile
 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
ファイル: command.py プロジェクト: beenje/git-bigfile
 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
ファイル: command.py プロジェクト: ashang/git-bigfile
 def objects(self):
     if self._objects is None:
         self._objects = util.get_bigfile_dir('objects')
     return self._objects
コード例 #8
0
ファイル: command.py プロジェクト: ashang/git-bigfile
 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
ファイル: command.py プロジェクト: Khan/git-bigfile
 def objects(self):
     if self._objects is None:
         self._objects = util.get_bigfile_dir('objects')
     return self._objects
コード例 #10
0
ファイル: command.py プロジェクト: Khan/git-bigfile
 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)