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.
 
 
 
 
 
 

104 rivejä
2.9 KiB

  1. #!/usr/bin/env python
  2. import os, sys
  3. def print_help():
  4. print "wnframework version control utility"
  5. print
  6. print "Usage:"
  7. print "python lib/wnf.py build : scan all folders and commit versions with latest changes"
  8. print "python lib/wnf.py pull : pull from git"
  9. print "python lib/wnf.py replace txt1 txt2 extn"
  10. print "python lib/wnf.py patch patch1 .. : run patches from patches module if not executed"
  11. print "python lib/wnf.py patch -f patch1 .. : run patches from patches module, force rerun"
  12. """simple replacement script"""
  13. def replace_code(start, txt1, txt2, extn):
  14. """replace all txt1 by txt2 in files with extension (extn)"""
  15. import os, re
  16. for wt in os.walk(start, followlinks=1):
  17. for fn in wt[2]:
  18. if fn.split('.')[-1]==extn:
  19. fpath = os.path.join(wt[0], fn)
  20. with open(fpath, 'r') as f:
  21. content = f.read()
  22. if re.search(txt1, content):
  23. with open(fpath, 'w') as f:
  24. f.write(re.sub(txt1, txt2, content))
  25. print 'updated in %s' % fpath
  26. def run():
  27. sys.path.append('.')
  28. sys.path.append('lib/py')
  29. import webnotes
  30. import webnotes.defs
  31. sys.path.append(webnotes.defs.modules_path)
  32. if len(sys.argv)<2:
  33. print_help()
  34. return
  35. cmd = sys.argv[1]
  36. if cmd=='build':
  37. import build.project
  38. build.project.build()
  39. elif cmd=='clear':
  40. from build.project import increment_version
  41. print "Version:" + str(increment_version())
  42. # replace code
  43. elif cmd=='replace':
  44. replace_code('.', sys.argv[2], sys.argv[3], sys.argv[4])
  45. elif cmd=='patch':
  46. from optparse import OptionParser
  47. parser = OptionParser()
  48. parser.add_option("-l", "--latest",
  49. action="store_true", dest="run_latest", default=False,
  50. help="Apply the latest patches")
  51. parser.add_option("-p", "--patch", dest="patch_list", metavar='PATCH_MODULE.PATCH_FILE',
  52. action="append",
  53. help="Apply patch PATCH_MODULE.PATCH_FILE")
  54. parser.add_option("-f", "--force",
  55. action="store_true", dest="force", default=False,
  56. help="Force Apply all patches specified using option -p or --patch")
  57. parser.add_option("-d", "--db",
  58. dest="db_name",
  59. help="Apply the patches on given db")
  60. parser.add_option('-r', '--reload_doc',help="reload doc, requires module, dt, dn", nargs=3)
  61. (options, args) = parser.parse_args()
  62. from webnotes.db import Database
  63. import webnotes.modules.patch_handler
  64. # connect to db
  65. if options.db_name is not None:
  66. webnotes.connect(options.db_name)
  67. else:
  68. webnotes.connect()
  69. # run individual patches
  70. if options.patch_list:
  71. for patch in options.patch_list:
  72. webnotes.modules.patch_handler.run_single(\
  73. patchmodule = patch, force = options.force)
  74. # reload
  75. elif options.reload_doc:
  76. webnotes.modules.patch_handler.reload_doc(\
  77. {"module":args[0], "dt":args[1], "dn":args[2]})
  78. # run all pending
  79. elif options.run_latest:
  80. webnotes.modules.patch_handler.run_all()
  81. print '\n'.join(webnotes.modules.patch_handler.log_list)
  82. if __name__=='__main__':
  83. run()