25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

103 lines
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. if len(sys.argv)<2:
  32. print_help()
  33. return
  34. cmd = sys.argv[1]
  35. if cmd=='build':
  36. from build.project import Project
  37. Project().build()
  38. elif cmd=='clear':
  39. from build.project import Project
  40. Project().render_templates()
  41. # replace code
  42. elif cmd=='replace':
  43. replace_code('.', sys.argv[2], sys.argv[3], sys.argv[4])
  44. elif cmd=='patch':
  45. from optparse import OptionParser
  46. parser = OptionParser()
  47. parser.add_option("-l", "--latest",
  48. action="store_true", dest="run_latest", default=False,
  49. help="Apply the latest patches")
  50. parser.add_option("-p", "--patch", dest="patch_list", metavar='PATCH_MODULE.PATCH_FILE',
  51. action="append",
  52. help="Apply patch PATCH_MODULE.PATCH_FILE")
  53. parser.add_option("-f", "--force",
  54. action="store_true", dest="force", default=False,
  55. help="Force Apply all patches specified using option -p or --patch")
  56. parser.add_option("-d", "--db",
  57. dest="db_name",
  58. help="Apply the patches on given db")
  59. parser.add_option('-r', '--reload_doc',help="reload doc, requires module, dt, dn", nargs=3)
  60. (options, args) = parser.parse_args()
  61. from webnotes.db import Database
  62. import webnotes.modules.patch_handler
  63. # connect to db
  64. if options.db_name is not None:
  65. webnotes.connect(options.db_name)
  66. else:
  67. webnotes.connect()
  68. # run individual patches
  69. if options.patch_list:
  70. for patch in options.patch_list:
  71. webnotes.modules.patch_handler.run_single(\
  72. patchmodule = patch, force = options.force)
  73. # reload
  74. elif options.reload_doc:
  75. webnotes.modules.patch_handler.reload_doc(\
  76. {"module":args[0], "dt":args[1], "dn":args[2]})
  77. # run all pending
  78. elif options.run_latest:
  79. webnotes.modules.patch_handler.run_all()
  80. print '\n'.join(webnotes.modules.patch_handler.log_list)
  81. if __name__=='__main__':
  82. run()