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


Python Object.new方法代码示例

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


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

示例1: _create

# 需要导入模块: from objects import Object [as 别名]
# 或者: from objects.Object import new [as 别名]
 def _create(cls, repo, path, resolve, reference, force):
     """internal method used to create a new symbolic reference.
     If resolve is False,, the reference will be taken as is, creating 
     a proper symbolic reference. Otherwise it will be resolved to the 
     corresponding object and a detached symbolic reference will be created
     instead"""
     full_ref_path = cls.to_full_path(path)
     abs_ref_path = os.path.join(repo.git_dir, full_ref_path)
     
     # figure out target data
     target = reference
     if resolve:
         target = Object.new(repo, reference)
         
     if not force and os.path.isfile(abs_ref_path):
         target_data = str(target)
         if isinstance(target, SymbolicReference):
             target_data = target.path
         if not resolve:
             target_data = "ref: " + target_data
         if open(abs_ref_path, 'rb').read().strip() != target_data:
             raise OSError("Reference at %s does already exist" % full_ref_path)
     # END no force handling
     
     ref = cls(repo, full_ref_path)
     ref.reference = target
     return ref
开发者ID:asavonic,项目名称:moldynam,代码行数:29,代码来源:refs.py

示例2: _get_object

# 需要导入模块: from objects import Object [as 别名]
# 或者: from objects.Object import new [as 别名]
 def _get_object(self):
     """
     Returns
         The object our ref currently refers to. Refs can be cached, they will 
         always point to the actual object as it gets re-created on each query
     """
     # have to be dynamic here as we may be a tag which can point to anything
     # Our path will be resolved to the hexsha which will be used accordingly
     return Object.new(self.repo, self.path)
开发者ID:asavonic,项目名称:moldynam,代码行数:11,代码来源:refs.py

示例3: _set_reference

# 需要导入模块: from objects import Object [as 别名]
# 或者: from objects.Object import new [as 别名]
 def _set_reference(self, ref):
     """
     Set ourselves to the given ref. It will stay a symbol if the ref is a Reference.
     Otherwise we try to get a commit from it using our interface.
     
     Strings are allowed but will be checked to be sure we have a commit
     """
     write_value = None
     if isinstance(ref, SymbolicReference):
         write_value = "ref: %s" % ref.path
     elif isinstance(ref, Commit):
         write_value = ref.sha
     else:
         try:
             write_value = ref.commit.sha
         except AttributeError:
             sha = str(ref)
             try:
                 obj = Object.new(self.repo, sha)
                 if obj.type != "commit":
                     raise TypeError("Invalid object type behind sha: %s" % sha)
                 write_value = obj.sha
             except Exception:
                 raise ValueError("Could not extract object from %s" % ref)
         # END end try string  
     # END try commit attribute
     
     # if we are writing a ref, use symbolic ref to get the reflog and more
     # checking
     # Otherwise we detach it and have to do it manually
     if write_value.startswith('ref:'):
         self.repo.git.symbolic_ref(self.path, write_value[5:])
         return 
     # END non-detached handling
     
     path = self._get_path()
     directory = os.path.dirname(path)
     if not os.path.isdir(directory):
         os.makedirs(directory)
     
     fp = open(path, "wb")
     try:
         fp.write(write_value)
     finally:
         fp.close()
开发者ID:asavonic,项目名称:moldynam,代码行数:47,代码来源:refs.py


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