You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wnf.py 4.1 KiB

14 years ago
14 years ago
14 years ago
14 years ago
13 years ago
14 years ago
14 years ago
13 years ago
14 years ago
14 years ago
14 years ago
13 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
13 years ago
14 years ago
13 years ago
14 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #!/usr/bin/env python
  2. import os, sys
  3. from py.build import version
  4. version.verbose = True
  5. def print_help():
  6. print "wnframework version control utility"
  7. print
  8. print "Usage:"
  9. print "python lib/wnf.py build : scan all folders and commit versions with latest changes"
  10. print "python lib/wnf.py setup : setup the local system (from master or fresh)"
  11. print "python lib/wnf.py merge : merge from local into master"
  12. print "python lib/wnf.py log : list last 10 commits"
  13. print "python lib/wnf.py pull : pull from git"
  14. print "python lib/wnf.py replace txt1 txt2 extn"
  15. print "python lib/wnf.py patch patch1 .. : run patches from patches module if not executed"
  16. print "python lib/wnf.py patch -f patch1 .. : run patches from patches module, force rerun"
  17. def setup():
  18. import os, sys
  19. if not os.path.exists('versions-local.db'):
  20. if os.path.exists('versions-master.db'):
  21. import shutil
  22. shutil.copyfile('versions-master.db', 'versions-local.db')
  23. print "created versions-local.db from versions-master.db"
  24. else:
  25. vc = version.VersionControl()
  26. vc.repo.setup()
  27. vc.close()
  28. print "created fresh versions-local.db"
  29. else:
  30. if len(sys.argv)==3 and sys.argv[2]=='master':
  31. import shutil
  32. shutil.copyfile('versions-local.db', 'versions-master.db')
  33. print "created versions-master.db from versions-local.db"
  34. else:
  35. print "versions-local.db already exists. Nothing to do."
  36. """simple replacement script"""
  37. def replace_code(start, txt1, txt2, extn):
  38. """replace all txt1 by txt2 in files with extension (extn)"""
  39. import os, re
  40. for wt in os.walk(start, followlinks=1):
  41. for fn in wt[2]:
  42. if fn.split('.')[-1]==extn:
  43. fpath = os.path.join(wt[0], fn)
  44. f = open(fpath, 'r')
  45. content = f.read()
  46. f.close()
  47. if re.search(txt1, content):
  48. f = open(fpath, 'w')
  49. f.write(re.sub(txt1, txt2, content))
  50. f.close()
  51. print 'updated in %s' % fpath
  52. def run():
  53. sys.path.append('lib')
  54. sys.path.append('lib/py')
  55. import webnotes
  56. import webnotes.defs
  57. sys.path.append(webnotes.defs.modules_path)
  58. if len(sys.argv)<2:
  59. print_help()
  60. return
  61. cmd = sys.argv[1]
  62. if cmd=='watch':
  63. from py import build
  64. import time
  65. while True:
  66. build.run()
  67. vc = version.VersionControl()
  68. print 'version %s' % vc.repo.get_value('last_version_number')
  69. time.sleep(5)
  70. elif cmd=='build':
  71. from py import build
  72. build.run()
  73. vc = version.VersionControl()
  74. print 'version %s' % vc.repo.get_value('last_version_number')
  75. elif cmd=='merge':
  76. vc = version.VersionControl()
  77. vc.setup_master()
  78. vc.merge(vc.repo, vc.master)
  79. vc.close()
  80. elif cmd=='merge-local':
  81. vc = version.VersionControl()
  82. vc.setup_master()
  83. vc.merge(vc.master, vc.repo)
  84. vc.close()
  85. elif cmd=='setup':
  86. setup()
  87. elif cmd=='clear_startup':
  88. # experimental
  89. from webnotes import startup
  90. startup.clear_info('all')
  91. vc = version.VersionControl()
  92. print 'version %s' % vc.repo.get_value('last_version_number')
  93. elif cmd=='log':
  94. vc = version.VersionControl()
  95. for l in vc.repo.sql("select * from log order by rowid desc limit 10 ", as_dict =1):
  96. print 'file:'+ l['fname'] + ' | version: ' + l['version']
  97. print 'version %s' % vc.repo.get_value('last_version_number')
  98. vc.close()
  99. elif cmd=='files':
  100. vc = version.VersionControl()
  101. for f in vc.repo.sql("select fname from files where fname like ?", ((sys.argv[2] + '%'),)):
  102. print f[0]
  103. vc.close()
  104. # pull from remote and merge with local
  105. elif cmd=='gitpull':
  106. branch = 'master'
  107. if len(sys.argv)>2:
  108. branch = sys.argv[2]
  109. print "pulling erpnext"
  110. os.system('git pull origin %s' % branch)
  111. vc = version.VersionControl()
  112. vc.setup_master()
  113. vc.merge(vc.master, vc.repo)
  114. vc.close()
  115. print "pulling framework"
  116. os.chdir('lib')
  117. os.system('git pull origin %s' % branch)
  118. # replace code
  119. elif cmd=='replace':
  120. replace_code('.', sys.argv[2], sys.argv[3], sys.argv[4])
  121. elif cmd=='patch':
  122. from webnotes.modules.patch_handler import run
  123. if len(sys.argv)>2 and sys.argv[2]=='-f':
  124. # force patch
  125. run(patch_list = sys.argv[3:], overwrite=1, log_exception=0)
  126. else:
  127. # run patch once
  128. run(patch_list = sys.argv[2:], log_exception=0)
  129. if __name__=='__main__':
  130. run()