Chinaunix首页 | 论坛 | 博客
  • 博客访问: 257368
  • 博文数量: 42
  • 博客积分: 2245
  • 博客等级: 大尉
  • 技术积分: 466
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-20 13:02
文章分类

全部博文(42)

文章存档

2012年(4)

2011年(6)

2010年(2)

2009年(6)

2008年(24)

我的朋友

分类: Delphi

2011-10-08 17:27:12

hg的版本提交分两步

1. hg commit

2. hg push

但有些时候,我们需要一步完成,即在hg commit后,自动做 hg push

配置如下:

.hg/hgrc
[hooks]
commit.autopush = hg push

Python 自动更改

  1.  
  2. # -*- coding:utf-8 -*-
  3.  
  4. import sys
  5. import os
  6. import configparser
  7.  
  8. # global various
  9. BASEDIR=""
  10.  
  11. def usage():
  12.     print("Autopush for HG")
  13.     print("Copyright (C) 2011 Liu Yugang ")
  14.     print("autopush ")
  15.  
  16. def FixAutoPush(hgrcfile):
  17.     config = configparser.ConfigParser()
  18.     try :
  19.         config.read(hgrcfile)
  20.         if(not config.has_section("hooks")):
  21.             config.add_section("hooks")
  22.         if(config.has_option("hooks","commit.autopush")):
  23.             if(config["hooks"]["commit.autopush"]=="hg push"):
  24.                 print("Find \"commit.autopush\" in \""+hgrcfile+"\", skip.")
  25.                 return
  26.         config["hooks"]["commit.autopush"]="hg push"
  27.         with open(hgrcfile,"w") as configfile:
  28.             config.write(configfile)
  29.         print("Fix \""+hgrcfile+"\"")
  30.     except configparser.Error as err:
  31.         print(err)
  32.    
  33. def main():
  34.     if(len(sys.argv)<2):
  35.         usage()
  36.         exit()
  37.     BASEDIR=os.path.abspath(sys.argv[1])
  38.  
  39.     fixautopush=False
  40.     hgrcfile=os.path.join(BASEDIR,".hg","hgrc")
  41.     if(os.path.isfile(hgrcfile)):
  42.         FixAutoPush(hgrcfile)
  43.         exit()
  44.  
  45.     for hg_dir in os.listdir(BASEDIR):
  46.         hgrcfile=os.path.join(BASEDIR,hg_dir,".hg","hgrc")
  47.         if(os.path.isfile(hgrcfile)):
  48.             FixAutoPush(hgrcfile)
  49.             fixautopush=True
  50.     if(not fixautopush) :
  51.         print("Can't find \""+hgrcfile+'" file.')
  52.    
  53. if __name__ == "__main__":
  54.     main()
阅读(2338) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~