Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- def get_immediate_subdirectories(dir):
- return [name for name in os.listdir(dir)
- if os.path.isdir(os.path.join(dir, name))]
- from twisted.python.filepath import FilePath
- def subdirs(pathObj):
- for subpath in pathObj.walk():
- if subpath.isdir():
- yield subpath
- if __name__ == '__main__':
- for subdir in subdirs(FilePath(".")):
- print "Subdirectory:", subdir
- def copyTemplates(topdir):
- for subdir in subdirs(topdir):
- tpl = subdir.child("index.tpl")
- if tpl.exists():
- tpl.copyTo(subdir.child("index.html"))
- class MyFakePath:
- def child(self, name):
- "Return an appropriate child object"
- def walk(self):
- "Return an iterable of MyFakePath objects"
- def exists(self):
- "Return true or false, as appropriate to the test"
- def isdir(self):
- "Return true or false, as appropriate to the test"
- ...
- subdirs(MyFakePath(...))
- def copy_client_files (file_src, file_dst):
- for file in os.listdir(file_src):
- print "Copying file: %s" % file
- shutil.copy(os.path.join(file_src, file), os.path.join(file_dst, file))
- import os
- import shutil
- def copy_over(path, from_name, to_name):
- for path, dirname, fnames in os.walk(path):
- for fname in fnames:
- if fname == from_name:
- shutil.copy(os.path.join(path, from_name), os.path.join(path, to_name))
- copy_over('.', 'index.tpl', 'index.html')
Add Comment
Please, Sign In to add comment