GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
create__init__.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import os
4 import sys
5 import glob
6 
7 def main(path):
8  if not os.path.exists(path) or not os.path.isdir(path):
9  print >> sys.stderr, "'%s' is not a directory" % path
10  return 1
11 
12  modules = []
13  for f in glob.glob(os.path.join(os.path.basename(path), '*.py')):
14  if f[-5:-3] == '__':
15  continue
16  modules.append(os.path.splitext(os.path.basename(f))[0])
17 
18  fd = open(os.path.join(path, '__init__.py'), 'w')
19  try:
20  fd.write('all = [%s' % os.linesep)
21  for m in modules:
22  fd.write(" '%s',%s" % (m, os.linesep))
23  fd.write(' ]%s' % os.linesep)
24  finally:
25  fd.close()
26 
27  return 0
28 
29 if __name__ == "__main__":
30  if len(sys.argv) < 2:
31  sys.exit("usage: %s path/to/gui_modules" % sys.argv[0])
32 
33  sys.exit(main(sys.argv[1]))