Created
October 3, 2013 21:47
-
-
Save mouseroot/6817651 to your computer and use it in GitHub Desktop.
Project manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from optparse import OptionParser | |
| def main(): | |
| pass | |
| if __name__ == "__main__": | |
| usage = "Usage: %prog [Options] <params>" | |
| desc = "Template" | |
| parser = OptionParser(usage=usage,description=desc) | |
| (options,args) = parser.parse_args() | |
| if(len(args) > 0): | |
| main() | |
| else: | |
| parser.print_help() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Project manager | |
| from optparse import OptionParser | |
| import shutil | |
| import os | |
| def main(project,template,folder): | |
| #First check if project folder exists | |
| if os.path.exists("%s//%s" % (folder,project)): | |
| print "Project folder exists" | |
| exit() | |
| else: | |
| print "Createing project",project | |
| os.mkdir("%s//%s" % (folder,project)) | |
| #Next copy template as main.py | |
| shutil.copyfile("%s.tmp" % template,"%s//%s//main.py" % (folder,project)) | |
| def remove(project,folder): | |
| if os.path.exists("%s//%s" % (folder,project)): | |
| print "Removing",project | |
| for f in os.listdir("%s//%s" % (folder,project)): | |
| os.remove("%s//%s//%s" % (folder,project,f)) | |
| os.rmdir("%s//%s" % (folder,project)) | |
| else: | |
| print "No such project",project | |
| if __name__ == "__main__": | |
| usage = "Usage: %prog [Options] project_name" | |
| desc = "Creates Projects from templates" | |
| parser = OptionParser(usage=usage,description=desc) | |
| parser.add_option("-t","--template",default="blank",dest="template",help="Template to use for new project") | |
| parser.add_option("-f","--folder",default=".",dest="folder",help="Parent directory for project to be created in") | |
| parser.add_option("-r","--remove",action="store_true",dest="remove",help="Deletes project") | |
| (options,args) = parser.parse_args() | |
| if(len(args) > 0): | |
| project_name = args[0] | |
| template = options.template | |
| parent_folder = options.folder | |
| if options.remove == True: | |
| remove(project_name,parent_folder) | |
| else: | |
| main(project_name,template,parent_folder) | |
| else: | |
| parser.print_help() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment