PageRenderTime 27ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/scripts/make_min_web2py.py

https://code.google.com/p/web2py/
Python | 97 lines | 97 code | 0 blank | 0 comment | 0 complexity | bd13d7b05022375df4b524609de69b98 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, MIT, BSD-3-Clause, Apache-2.0
  1. USAGE = """
  2. from web2py main folder
  3. python scripts/make_min_web2py.py /path/to/minweb2py
  4. it will mkdir minweb2py and build a minimal web2py installation
  5. - no admin, no examples, one line welcome
  6. - no scripts
  7. - drops same rarely used contrib modules
  8. - more modules could be dropped but minimal difference
  9. """
  10. # files to include from top level folder (default.py will be rebuilt)
  11. REQUIRED = """
  12. VERSION
  13. web2py.py
  14. anyserver.py
  15. applications/__init__.py
  16. applications/welcome/controllers/default.py
  17. handlers/fcgihandler.py
  18. handlers/gaehandler.py
  19. handlers/wsgihandler.py
  20. """
  21. # files and folders to exclude from gluon folder (comment with # if needed)
  22. IGNORED = """
  23. gluon/contrib/websocket_messaging.py
  24. gluon/contrib/feedparser.py
  25. gluon/contrib/generics.py
  26. gluon/contrib/gql.py
  27. gluon/contrib/populate.py
  28. gluon/contrib/sms_utils.py
  29. gluon/contrib/spreadsheet.py
  30. gluon/tests/
  31. gluon/contrib/markdown/
  32. gluon/contrib/pyfpdf/
  33. gluon/contrib/pymysql/
  34. gluon/contrib/pyrtf/
  35. gluon/contrib/pysimplesoap/
  36. """
  37. import sys
  38. import os
  39. import shutil
  40. import glob
  41. def main():
  42. global REQUIRED, IGNORED
  43. if len(sys.argv) < 2:
  44. print USAGE
  45. # make target folder
  46. target = sys.argv[1]
  47. os.mkdir(target)
  48. # change to os specificsep
  49. REQUIRED = REQUIRED.replace('/', os.sep)
  50. IGNORED = IGNORED.replace('/', os.sep)
  51. # make a list of all files to include
  52. files = [x.strip() for x in REQUIRED.split('\n')
  53. if x and not x[0] == '#']
  54. ignore = [x.strip() for x in IGNORED.split('\n')
  55. if x and not x[0] == '#']
  56. def accept(filename):
  57. for p in ignore:
  58. if filename.startswith(p):
  59. return False
  60. return True
  61. pattern = os.path.join('gluon', '*.py')
  62. while True:
  63. newfiles = [x for x in glob.glob(pattern) if accept(x)]
  64. if not newfiles:
  65. break
  66. files += newfiles
  67. pattern = os.path.join(pattern[:-3], '*.py')
  68. # copy all files, make missing folder, build default.py
  69. files.sort()
  70. defaultpy = os.path.join(
  71. 'applications', 'welcome', 'controllers', 'default.py')
  72. for f in files:
  73. dirs = f.split(os.path.sep)
  74. for i in range(1, len(dirs)):
  75. try:
  76. os.mkdir(target + os.sep + os.path.join(*dirs[:i]))
  77. except OSError:
  78. pass
  79. if f == defaultpy:
  80. open(os.path.join(
  81. target, f), 'w').write('def index(): return "hello"\n')
  82. else:
  83. shutil.copyfile(f, os.path.join(target, f))
  84. if __name__ == '__main__':
  85. main()