当前位置: 首页>>代码示例>>Python>>正文


Python Index.write_to_file方法代码示例

本文整理汇总了Python中index.Index.write_to_file方法的典型用法代码示例。如果您正苦于以下问题:Python Index.write_to_file方法的具体用法?Python Index.write_to_file怎么用?Python Index.write_to_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在index.Index的用法示例。


在下文中一共展示了Index.write_to_file方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Repository

# 需要导入模块: from index import Index [as 别名]
# 或者: from index.Index import write_to_file [as 别名]
class Repository(object):
    '''
    The git repository
    '''

    GIT_DIR = '.git'
    
    INIT_DIR = [
        'branches',
        'hooks',
        'info',
        'objects',
        'objects/info',
        'objects/pack',
        'refs',
        'refs/heads',
        'refs/tags',
    ]
    
    INIT_FILE = [
        ['HEAD', 'ref: refs/heads/master'],
        ['description', 'Unnamed repository'],
        ['info/exclude', ''],
    ]
    
    
    def __init__(self, workspace):
        self.workspace = workspace
        self.index = Index(os.path.join(workspace, '.git', 'index'))
        self.config = Config(workspace)
        self.head_path = self._get_head_path()
        self.head_tree = None
        if os.path.exists(self.head_path):
            self.head_tree = read_file(self.head_path).strip()
    
    def _get_head_path(self):
        branch_name = read_file(os.path.join(self.workspace, '.git', 'HEAD')).strip('\n').rsplit('/', 1)[-1]
        return os.path.join(self.workspace, '.git', 'refs', 'heads', branch_name)
        
    def stage(self, files):
        try:
            for file in files:
                content = read_file(file)
                blob = Blob(self.workspace, content)
                if not os.path.exists(blob.path):
                    write_object_to_file(blob.path, blob.content)
                stat = os.stat(os.path.join(self.workspace, file))
                self.index.add_entry(file, ctime=stat.st_ctime, mtime=stat.st_mtime, dev=stat.st_dev, ino=stat.st_ino, mode=cal_mode(stat.st_mode), \
                       uid=stat.st_uid, gid=stat.st_gid, size=stat.st_size,sha1=blob.sha1, flags=0)
            self.index.write_to_file()
                    
        except Exception, e:
            print 'stage file %s error: %s' % (file, e)
开发者ID:bearxwbyr,项目名称:git-in-python,代码行数:55,代码来源:repository.py

示例2: Repository

# 需要导入模块: from index import Index [as 别名]
# 或者: from index.Index import write_to_file [as 别名]
class Repository(object):
    """
    The git repository
    """

    GIT_DIR = ".git"

    INIT_DIR = [
        "branches",
        "hooks",
        "info",
        "objects",
        "objects/info",
        "objects/pack",
        "refs",
        "refs/heads",
        "refs/tags",
    ]

    INIT_FILE = [["HEAD", "ref: refs/heads/master"], ["description", "Unnamed repository"], ["info/exclude", ""]]

    def __init__(self, workspace):
        self.workspace = workspace
        self.index = Index(os.path.join(workspace, ".git", "index"))
        self.config = Config(workspace)

    def stage(self, files):
        try:
            for file in files:
                content = read_file(file)
                blob = Blob(self.workspace, content)
                if not os.path.exists(blob.path):
                    write_object_to_file(blob.path, blob.content)
                stat = os.stat(os.path.join(self.workspace, file))
                self.index.add_entry(
                    file,
                    ctime=stat.st_ctime,
                    mtime=stat.st_mtime,
                    dev=stat.st_dev,
                    ino=stat.st_ino,
                    mode=cal_mode(stat.st_mode),
                    uid=stat.st_uid,
                    gid=stat.st_gid,
                    size=stat.st_size,
                    sha1=blob.sha1,
                    flags=0,
                )
            self.index.write_to_file()

        except Exception, e:
            print "stage file %s error: %s" % (file, e)
开发者ID:ningg,项目名称:git-in-python,代码行数:53,代码来源:repository.py


注:本文中的index.Index.write_to_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。