Guest User

Untitled

a guest
Jun 20th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. import os
  2. def get_immediate_subdirectories(dir):
  3. return [name for name in os.listdir(dir)
  4. if os.path.isdir(os.path.join(dir, name))]
  5.  
  6. from twisted.python.filepath import FilePath
  7.  
  8. def subdirs(pathObj):
  9. for subpath in pathObj.walk():
  10. if subpath.isdir():
  11. yield subpath
  12.  
  13. if __name__ == '__main__':
  14. for subdir in subdirs(FilePath(".")):
  15. print "Subdirectory:", subdir
  16.  
  17. def copyTemplates(topdir):
  18. for subdir in subdirs(topdir):
  19. tpl = subdir.child("index.tpl")
  20. if tpl.exists():
  21. tpl.copyTo(subdir.child("index.html"))
  22.  
  23. class MyFakePath:
  24. def child(self, name):
  25. "Return an appropriate child object"
  26.  
  27. def walk(self):
  28. "Return an iterable of MyFakePath objects"
  29.  
  30. def exists(self):
  31. "Return true or false, as appropriate to the test"
  32.  
  33. def isdir(self):
  34. "Return true or false, as appropriate to the test"
  35. ...
  36. subdirs(MyFakePath(...))
  37.  
  38. def copy_client_files (file_src, file_dst):
  39. for file in os.listdir(file_src):
  40. print "Copying file: %s" % file
  41. shutil.copy(os.path.join(file_src, file), os.path.join(file_dst, file))
  42.  
  43. import os
  44. import shutil
  45.  
  46. def copy_over(path, from_name, to_name):
  47. for path, dirname, fnames in os.walk(path):
  48. for fname in fnames:
  49. if fname == from_name:
  50. shutil.copy(os.path.join(path, from_name), os.path.join(path, to_name))
  51.  
  52.  
  53. copy_over('.', 'index.tpl', 'index.html')
Add Comment
Please, Sign In to add comment