Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import os
- import sys
- def find_match(src_path_list, files_list, name):
- rv = []
- for p,f in zip(src_path_list, files_list):
- if name in f:
- rv.append(p)
- return rv
- def process(dst_path, src_path_list):
- # Check destination
- if not os.path.exists(dst_path):
- os.mkdir(dst_path)
- # File list for each sources
- files_list = [set(os.listdir(x)) for x in src_path_list]
- # Find all entries and count hits
- files_all = set()
- for fl in files_list:
- files_all.update(fl)
- # Exclude .git
- files_all.discard('.git')
- # Process all entries
- for n in files_all:
- # Destination
- dp = os.path.join(dst_path, n)
- # Find matchings path
- mp = find_match(src_path_list, files_list, n)
- # Single hit -> Direct link
- if len(mp) == 1:
- print "Direct single : %s" % n
- sp = os.path.join(mp[0],n)
- os.symlink(sp, dp)
- # Multiple hit, but normal file -> Direct link
- elif not os.path.isdir(os.path.join(mp[0], n)):
- print "Direct file : %s" % n
- sp = os.path.join(mp[0],n)
- os.symlink(sp, dp)
- # Multiple hits and directory -> Recurse
- else:
- print "Recurse : %s" % n
- process(dp, [os.path.join(x,n) for x in mp])
- def main(argv0, dst, *srcs):
- process(
- os.path.abspath(dst),
- [os.path.abspath(x) for x in srcs]
- )
- if __name__ == '__main__':
- main(*sys.argv)
Advertisement
Add Comment
Please, Sign In to add comment