GRASS Programmer's Manual  6.5.svn(2012)-r51648
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
create__init__.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import os
00004 import sys
00005 import glob
00006 
00007 def main(path):
00008     if not os.path.exists(path) or not os.path.isdir(path):
00009         print >> sys.stderr, "'%s' is not a directory" % path
00010         return 1
00011     
00012     modules = []
00013     for f in glob.glob(os.path.join(os.path.basename(path), '*.py')):
00014         if f[-5:-3] == '__':
00015             continue
00016         modules.append(os.path.splitext(os.path.basename(f))[0])
00017         
00018     fd = open(os.path.join(path, '__init__.py'), 'w')
00019     try:
00020         fd.write('all = [%s' % os.linesep)
00021         for m in modules:
00022             fd.write("    '%s',%s" % (m, os.linesep))
00023         fd.write('    ]%s' % os.linesep)
00024     finally:
00025         fd.close()
00026     
00027     return 0
00028 
00029 if __name__ == "__main__":
00030     if len(sys.argv) < 2:
00031         sys.exit("usage: %s path/to/gui_modules" % sys.argv[0])
00032     
00033     sys.exit(main(sys.argv[1]))