annotate python/dotpath.py @ 286:db07fef40642

add a command to apply patches
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 10 May 2013 10:59:38 -0700
parents 03fc1f76db91
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
2
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
3 import sys
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
4
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
5 def filename(dotpath):
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
6 path = dotpath.split('.')
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
7 while path:
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
8 try:
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
9 module = __import__('.'.join(path))
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
10 return module.__file__.rstrip('c')
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
11 except ImportError:
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
12 path.pop()
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
13
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
14 def main(args=sys.argv[1:]):
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
15 for arg in args:
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
16 try:
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
17 _filename = filename(arg)
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
18 except Exception, e:
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
19 print e
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
20 continue
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
21 print _filename
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
22
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
23 if __name__ == '__main__':
03fc1f76db91 adding dotpath python helper
k0s <k0scist@gmail.com>
parents:
diff changeset
24 main()