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.
 
 
 
 
 
 

74 lines
1.6 KiB

  1. class wnJSCompiler:
  2. @staticmethod
  3. def concate_files_in_dir(path,dest):
  4. """
  5. Concatenates all files in a directory
  6. """
  7. import os
  8. allfiles = []
  9. dirname = path
  10. l = os.listdir(path)
  11. for i in l:
  12. if os.path.isfile(os.path.join(dirname,i)):
  13. allfiles.append(os.path.join(dirname,i))
  14. fout = open(dest,'w')
  15. for filename in allfiles:
  16. f = open(filename)
  17. fout.write(f.read())
  18. f.close
  19. fout.close
  20. @staticmethod
  21. def getsubs(path):
  22. """
  23. gets all the sub directories of a directory (recursive)
  24. """
  25. import os
  26. subs = []
  27. for root, subd, files in os.walk(path):
  28. for i in subd:
  29. subs.append(os.path.join(root,i))
  30. return subs
  31. @staticmethod
  32. def compilejs(path):
  33. """
  34. Compiles the js tree for ondemand import
  35. """
  36. if not wnJSCompiler.is_changed(path):
  37. return
  38. import os
  39. import webnotes.utils.jsnamespace as jsn
  40. subs = wnJSCompiler.getsubs(path)
  41. for subdir in subs:
  42. modname = jsn.jsNamespace.getmodname(subdir)
  43. wnJSCompiler.concate_files_in_dir(subdir,os.path.join(subdir, modname))
  44. wnJSCompiler.minifyjs(os.path.join(subdir, modname))
  45. @staticmethod
  46. def is_changed(path):
  47. #compare new timestamps with the ones stored in file
  48. from webnotes.utils import jstimestamp
  49. try:
  50. frm_file = jstimestamp.generateTimestamp.read_ts_from_file(path)
  51. newts = jstimestamp.generateTimestamp.gents(path)
  52. except IOError:
  53. return True
  54. if frm_file == newts:
  55. return False
  56. else:
  57. return True
  58. @staticmethod
  59. def minifyjs(modpath):
  60. """
  61. Stub to minify js
  62. """
  63. pass
  64. if __name__=="__main__":
  65. a = wnJSCompiler()
  66. print a.compilejs('../js/wn')