Beispiel #1
0
 def git_remove_path(path):
     global git_bin, local_db
     # only recommended for intermediate files!
     inner_cmd = [git_bin, "rm", "-r", "--cached", "--ignore-unmatch", path]
     inner_cmd_str = ' '.join(inner_cmd)
     cmd_line = PersistentPath.git_command() + \
         ['filter-branch', '--index-filter', inner_cmd_str, 'HEAD']
     debug_print('executing', cmd_line)
     result, output, errs = execute_cmdline2(cmd_line)
     debug_print('result:', result)
     debug_print('stdout:', type(output), output)
     debug_print('stderr:', type(errs), errs)
     debug_print('***')
     shutil.rmtree(os.path.join(local_db, ".git", "refs", "original"))
     cmd_line = PersistentPath.git_command() + ["reflog", "expire", "--all"]
     debug_print('executing', cmd_line)
     result, output, errs = execute_cmdline2(cmd_line)
     debug_print('result:', result)
     debug_print('stdout:', type(output), output)
     debug_print('stderr:', type(errs), errs)
     debug_print('***')
     cmd_line = PersistentPath.git_command() + [
         "gc", "--aggressive", "--prune"
     ]
     debug_print('executing', cmd_line)
     result, output, errs = execute_cmdline2(cmd_line)
     debug_print('result:', result)
     debug_print('stdout:', type(output), output)
     debug_print('stderr:', type(errs), errs)
     debug_print('***')
 def git_remove_path(path):
     global git_bin, local_db
     # only recommended for intermediate files!
     inner_cmd = [git_bin, "rm", "-r", "--cached", "--ignore-unmatch",path]
     inner_cmd_str = ' '.join(inner_cmd)
     cmd_line = PersistentPath.git_command() + \
         ['filter-branch', '--index-filter', inner_cmd_str, 'HEAD']
     debug_print('executing', cmd_line)
     result, output, errs = execute_cmdline2(cmd_line)
     debug_print('result:', result)
     debug_print('stdout:', type(output), output)
     debug_print('stderr:', type(errs), errs)
     debug_print('***')
     shutil.rmtree(os.path.join(local_db, ".git", "refs", "original"))
     cmd_line = PersistentPath.git_command() + ["reflog", "expire","--all"]
     debug_print('executing', cmd_line)
     result, output, errs = execute_cmdline2(cmd_line)
     debug_print('result:', result)
     debug_print('stdout:', type(output), output)
     debug_print('stderr:', type(errs), errs)
     debug_print('***')
     cmd_line = PersistentPath.git_command() + ["gc", "--aggressive",
                                                "--prune"]
     debug_print('executing', cmd_line)
     result, output, errs = execute_cmdline2(cmd_line)
     debug_print('result:', result)
     debug_print('stdout:', type(output), output)
     debug_print('stderr:', type(errs), errs)
     debug_print('***')
    def git_add_commit(filename):
        cmd_line = PersistentPath.git_command() + ['add', filename]
        debug_print('executing', cmd_line)
        result, output, errs = execute_cmdline2(cmd_line)
        debug_print(output)
        debug_print('***')

        cmd_line = PersistentPath.git_command() + ['commit', '-q', '-m', 
                                         'Updated %s' % filename]
        debug_print('executing', cmd_line)
        result, output, errs = execute_cmdline2(cmd_line)
        debug_print('result:', result)
        debug_print('stdout:', type(output), output)
        debug_print('stderr:', type(errs), errs)
        debug_print('***')

        if len(output) > 1:
            # failed b/c file is the same
            # return 
            debug_print('got unexpected output')
            return None

        cmd_line = PersistentPath.git_command() + ['log', '-1']
        debug_print('executing', cmd_line)
        result, output, errs = execute_cmdline2(cmd_line)
        debug_print(output)
        debug_print('***')

        if output.startswith('commit'):
            return output.split(None, 2)[1]
        return None
Beispiel #4
0
    def git_add_commit(filename):
        cmd_line = PersistentPath.git_command() + ['add', filename]
        debug_print('executing', cmd_line)
        result, output, errs = execute_cmdline2(cmd_line)
        debug_print(output)
        debug_print('***')

        cmd_line = PersistentPath.git_command() + [
            'commit', '-q', '-m',
            'Updated %s' % filename
        ]
        debug_print('executing', cmd_line)
        result, output, errs = execute_cmdline2(cmd_line)
        debug_print('result:', result)
        debug_print('stdout:', type(output), output)
        debug_print('stderr:', type(errs), errs)
        debug_print('***')

        if len(output) > 1:
            # failed b/c file is the same
            # return
            debug_print('got unexpected output')
            return None

        cmd_line = PersistentPath.git_command() + ['log', '-1']
        debug_print('executing', cmd_line)
        result, output, errs = execute_cmdline2(cmd_line)
        debug_print(output)
        debug_print('***')

        if output.startswith('commit'):
            return output.split(None, 2)[1]
        return None
 def git_get_latest_version(filename):
     cmd_line = PersistentPath.git_command() + ['log', '-1', filename]
     debug_print('executing', cmd_line)
     result, output, errs = execute_cmdline2(cmd_line)
     debug_print(output)
     if output.startswith('commit'):
         return output.split(None, 2)[1]
     return None
Beispiel #6
0
 def git_get_latest_version(filename):
     cmd_line = PersistentPath.git_command() + ['log', '-1', filename]
     debug_print('executing', cmd_line)
     result, output, errs = execute_cmdline2(cmd_line)
     debug_print(output)
     if output.startswith('commit'):
         return output.split(None, 2)[1]
     return None
def git_init(dir):
    global git_bin
    if systemType == "Windows":
        cmd = ["%s:" % dir[0], "&&", "cd", "%s" % dir, "&&", git_bin, "init"]
    else:
        cmd = ["cd", "%s" % dir, "&&", git_bin, "init"]
    debug_print('cmd:', cmd)
    result, output, errs = execute_cmdline2(cmd)
    debug_print('init result', result)
    debug_print('init output', output)
Beispiel #8
0
def git_init(dir):
    global git_bin
    if systemType == "Windows":
        cmd = ["%s:" % dir[0], "&&", "cd", "%s" % dir, "&&", git_bin, "init"]
    else:
        cmd = ["cd", "%s" % dir, "&&", git_bin, "init"]
    debug_print('cmd:', cmd)
    result, output, errs = execute_cmdline2(cmd)
    debug_print('init result', result)
    debug_print('init output', output)
Beispiel #9
0
    def git_compute_tree_hash(dirname):
        lines = []
        for file in os.listdir(dirname):
            fname = os.path.join(dirname, file)
            if os.path.isdir(fname):
                hash = PersistentPath.git_compute_tree_hash(fname)
                lines.append("040000 tree " + hash + '\t' + file)
            elif os.path.isfile(fname):
                hash = PersistentPath.git_compute_file_hash(fname)
                lines.append("100644 blob " + hash + '\t' + file)

        (fd, tree_fname) = tempfile.mkstemp(prefix='vt_persist')
        os.close(fd)

        tree_f = open(tree_fname, 'w')
        for line in lines:
            print >> tree_f, line
        tree_f.close()

        cmd_line = PersistentPath.git_command() + [
            'mktree', '--missing', '<', tree_fname
        ]
        debug_print('executing', cmd_line)
        result, output, errs = execute_cmdline2(cmd_line)
        debug_print('result:', result)
        debug_print(output)
        debug_print('***')
        os.remove(tree_fname)
        if result != 0:
            raise ModuleError(self,
                              "Error retrieving file '%s'\n" % dirname + errs)
        tree_hash = output.rsplit(None, 1)[-1].strip()
        debug_print('hash:', tree_hash)

        cmd_line = PersistentPath.git_command() + ['prune']
        debug_print('executing', cmd_line)
        result, output, errs = execute_cmdline2(cmd_line)
        debug_print('result:', result)
        debug_print(output)
        debug_print('***')

        return tree_hash
    def git_compute_tree_hash(dirname):
        lines = []
        for file in os.listdir(dirname):
            fname = os.path.join(dirname, file)
            if os.path.isdir(fname):
                hash = PersistentPath.git_compute_tree_hash(fname)
                lines.append("040000 tree " + hash + '\t' + file)
            elif os.path.isfile(fname):
                hash = PersistentPath.git_compute_file_hash(fname)
                lines.append("100644 blob " + hash + '\t' + file)

        (fd, tree_fname) = tempfile.mkstemp(prefix='vt_persist')
        os.close(fd)
        
        tree_f = open(tree_fname, 'w')
        for line in lines:
            print >>tree_f, line
        tree_f.close()

        cmd_line = PersistentPath.git_command() + ['mktree', '--missing',
                                                   '<', tree_fname]
        debug_print('executing', cmd_line)
        result, output, errs = execute_cmdline2(cmd_line)
        debug_print('result:', result)
        debug_print(output)
        debug_print('***')
        os.remove(tree_fname)
        if result != 0:
            raise ModuleError(self, "Error retrieving file '%s'\n" % dirname +
                              errs)
        tree_hash = output.rsplit(None, 1)[-1].strip()
        debug_print('hash:', tree_hash)

        cmd_line = PersistentPath.git_command() + ['prune']
        debug_print('executing', cmd_line)
        result, output, errs = execute_cmdline2(cmd_line)
        debug_print('result:', result)
        debug_print(output)
        debug_print('***')
        
        return tree_hash
    def git_compute_file_hash(filename):
        # run git hash-object filename
        cmd_line = PersistentPath.git_command() + ['hash-object', filename]
        debug_print('executing', cmd_line)
        result, output, errs = execute_cmdline2(cmd_line)
        debug_print('result:', result)
        debug_print('stdout:', type(output), output)
        debug_print('stderr:', type(errs), errs)
        debug_print('***')

        if result != 0:
            raise ModuleError(None, "Error retrieving file '%s'\n" % filename +
                              errs)
        return output.strip()
Beispiel #12
0
    def git_compute_file_hash(filename):
        # run git hash-object filename
        cmd_line = PersistentPath.git_command() + ['hash-object', filename]
        debug_print('executing', cmd_line)
        result, output, errs = execute_cmdline2(cmd_line)
        debug_print('result:', result)
        debug_print('stdout:', type(output), output)
        debug_print('stderr:', type(errs), errs)
        debug_print('***')

        if result != 0:
            raise ModuleError(None,
                              "Error retrieving file '%s'\n" % filename + errs)
        return output.strip()
 def git_get_file(name, version="HEAD", out_fname=None, out_suffix=''):
     global temp_persist_files
     if out_fname is None:
         # create a temporary file
         (fd, out_fname) = tempfile.mkstemp(suffix=out_suffix,
                                            prefix='vt_persist')
         os.close(fd)
         temp_persist_files.append(out_fname)
         
     cmd_line =  PersistentPath.git_command() + ["show",
                                                 str(version + ':' + name),
                                                 '>', out_fname]
     debug_print('executing command', cmd_line)
     result, output, errs = execute_cmdline2(cmd_line)
     debug_print('stdout:', type(output), output)
     debug_print('stderr:', type(errs), errs)
     if result != 0:
         # check output for error messages
         raise ModuleError(self, "Error retrieving file '%s'\n" % name +
                           errs)
     return out_fname
Beispiel #14
0
    def git_get_file(name, version="HEAD", out_fname=None, out_suffix=''):
        global temp_persist_files
        if out_fname is None:
            # create a temporary file
            (fd, out_fname) = tempfile.mkstemp(suffix=out_suffix,
                                               prefix='vt_persist')
            os.close(fd)
            temp_persist_files.append(out_fname)

        cmd_line = PersistentPath.git_command() + [
            "show", str(version + ':' + name), '>', out_fname
        ]
        debug_print('executing command', cmd_line)
        result, output, errs = execute_cmdline2(cmd_line)
        debug_print('stdout:', type(output), output)
        debug_print('stderr:', type(errs), errs)
        if result != 0:
            # check output for error messages
            raise ModuleError(self,
                              "Error retrieving file '%s'\n" % name + errs)
        return out_fname