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.
 
 
 
 
 
 

32 lines
962 B

  1. class jsDependencyBuilder:
  2. @staticmethod
  3. def read_code(js_path):
  4. try:
  5. f = open(js_path)
  6. try:
  7. code = f.read()
  8. finally:
  9. f.close
  10. except Exception, e:
  11. raise e
  12. return code
  13. @staticmethod
  14. def read_imports(code):
  15. import re
  16. p = re.compile('\$import\(\' (?P<name> [^)]*)\' \)', re.VERBOSE)
  17. return p.findall(code)
  18. @staticmethod
  19. def build_dependency(jsdir,modname,depends= set()):
  20. import webnotes.utils.jsnamespace as jsn
  21. js_path = jsn.jsNamespace.modname_to_filename(modname,jsdir)
  22. code = jsDependencyBuilder.read_code(js_path)
  23. curdepend = jsDependencyBuilder.read_imports(code)
  24. for i in curdepend:
  25. if i not in depends:
  26. depends.add(i)
  27. depends = depends.union( jsDependencyBuilder.build_dependency(jsdir,i,depends))
  28. return depends
  29. def build_dependency_from_file(modname,depends= set()):
  30. # TODO STUB to read dependency from dependency tree stored in file
  31. return jsDependencyBuilder.build_dependency(modname)