本文整理汇总了Python中git.repo.Repo.add_header方法的典型用法代码示例。如果您正苦于以下问题:Python Repo.add_header方法的具体用法?Python Repo.add_header怎么用?Python Repo.add_header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.repo.Repo
的用法示例。
在下文中一共展示了Repo.add_header方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from git.repo import Repo [as 别名]
# 或者: from git.repo.Repo import add_header [as 别名]
def main():
from argparse import ArgumentParser
parser = ArgumentParser(description=__doc__)
parser.add_argument('anr_repo', help='Path to the OCTN ANR plugin repository.')
parser.add_argument('cards_path', help="Path to store cards metadata in.")
args = parser.parse_args()
try:
mkdir(args.cards_path)
except OSError as e:
if e.errno != 17: #17 is file exists
raise
now = time()
r = Repo(args.anr_repo)
r.remotes.origin.pull()
octgn_sha = r.head.commit.hexsha
r = Request(NETRUNNERCARDS_URL)
try:
with open(join(args.cards_path, 'cards.json'), 'r') as f:
data = json_load(f)
if 'octgn_sha' in data and data['octgn_sha'] == octgn_sha:
r.add_header("If-Modified-Since", format_date_time(json_load(f)['modified_since']))
except IOError as e:
if e.errno != 2:
raise
try:
cards = json_loads(urlopen(r).read())
except HTTPError as e:
if e.code != 304:
raise
card_sets_path = join(args.anr_repo, 'o8g', 'Sets')
card_octgn_data = {}
for path in walk(card_sets_path):
if len(path[-1]) > 0 and path[-1][0] == 'set.xml' and not path[0].endswith('Markers'):
set_data = octgnSetToDict(join(card_sets_path, path[0], path[-1][0]))
for card in set_data['cards'].values():
card['set_id'] = set_data['id']
card['game_id'] = set_data['gameid']
card_octgn_data.update(set_data['cards'])
for card in cards:
renameCardKeys(card)
print card['name'].encode('utf8')
octgn_card = None
try:
octgn_card = card_octgn_data[card['card_id']]
except KeyError as e:
print 'EE', card['card_id'], card['set_name']
continue
card['set_id'] = octgn_card['set_id']
card['game_id'] = octgn_card['game_id']
card['id'] = octgn_card['id']
card_image_path = join(args.cards_path, split(card['imagesrc'])[-1])
if not exists(card_image_path):
try:
image_src = urlopen(NETRUNNERCARDS_BASE + card['imagesrc'])
with open(card_image_path, 'w') as f:
f.write(image_src.read())
except HTTPError as e:
print 'ERROR: image missing for card #', card['id']
cards = {'modified_since': now, 'octgn_sha': octgn_sha, 'cards': cards}
with open(join(args.cards_path, 'cards.json'), 'w') as f:
json_dump(cards, f)