Skip to content

Commit

Permalink
pierre's changes to ofProject script to accept examples folder
Browse files Browse the repository at this point in the history
  • Loading branch information
arturoc committed Feb 11, 2010
1 parent b4d1f72 commit f0c4d39
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions scripts/linux/ofProjectManager/ofProjectManager.py
Expand Up @@ -6,35 +6,50 @@
import sys import sys
from ofEnvironment import of_root from ofEnvironment import of_root


of_path = of_root + "apps/myApps/"

class ofProjectManager: class ofProjectManager:
"""class to add addons to projects""" """class to add addons to projects"""


def __init__(self,project): # def __init__(self,project):
# try:
# f = open(of_path + project + "/" + project + ".cbp","r")
# f.close()
# except IOError:
# self.createFromEmpty(project)
#
# self.projectName = project
# self.project = ofProject(of_path + project + "/" + project + ".cbp")

def __init__(self,project,path=""):
global of_path
try: try:
f = open(of_root + "apps/myApps/" + project + "/" + project + ".cbp","r") if len(path) != 0:
of_path = path
f = open(of_path + project + "/" + project + ".cbp","r")
f.close() f.close()
except IOError: except IOError:
self.createFromEmpty(project) self.createFromEmpty(project)


self.projectName = project self.projectName = project
self.project = ofProject(of_root + "apps/myApps/" + project + "/" + project + ".cbp") self.project = ofProject(of_path + project + "/" + project + ".cbp")


def createFromEmpty(self,project): def createFromEmpty(self,project):
shutil.copytree (of_root + "apps/examples/emptyExample",of_root + "apps/myApps/" + project) shutil.copytree (of_root + "apps/examples/emptyExample",of_path + project)
shutil.move(of_root + "apps/myApps/"+project+"/emptyExample.cbp", of_root +"apps/myApps/" + project+ "/" + project + ".cbp") shutil.move(of_path + project+"/emptyExample.cbp", of_path + project+ "/" + project + ".cbp")
f = open(of_root + "apps/myApps/" + project + "/" + project + ".cbp","r") f = open(of_path + project + "/" + project + ".cbp","r")
projectStr = f.read() projectStr = f.read()
f.close() f.close()
projectStr = projectStr.replace("emptyExample",project) projectStr = projectStr.replace("emptyExample",project)
f = open(of_root + "apps/myApps/" + project + "/" + project + ".cbp","w") f = open(of_path + project + "/" + project + ".cbp","w")
f.write(projectStr) f.write(projectStr)


def addAddon(self,addon): def addAddon(self,addon):
addon = ofxDescriptor(of_root + "addons/" + addon + "/install.xml") addon = ofxDescriptor(of_root + "addons/" + addon + "/install.xml")
self.project.addAddon(addon) self.project.addAddon(addon)


def saveProject(self): def saveProject(self):
f = open(of_root + "apps/myApps/" + self.projectName + "/"+self.projectName+".cbp","w") f = open(of_path + self.projectName + "/"+self.projectName+".cbp","w")
self.project.xml(f); self.project.xml(f);
f.close() f.close()


Expand All @@ -43,15 +58,26 @@ def saveProject(self):
if __name__ == "__main__": if __name__ == "__main__":
if(len(sys.argv) > 2): if(len(sys.argv) > 2):
if sys.argv[1] == "add": if sys.argv[1] == "add":
if(len(sys.argv) > 3): if(len(sys.argv) > 4):
projectManager = ofProjectManager(sys.argv[2]) projectManager = ofProjectManager(sys.argv[2],sys.argv[4])
projectManager.addAddon(sys.argv[3]) projectManager.addAddon(sys.argv[3])
projectManager.saveProject() projectManager.saveProject()
else:
if(len(sys.argv) > 3):
projectManager = ofProjectManager(sys.argv[2])
projectManager.addAddon(sys.argv[3])
projectManager.saveProject()


if sys.argv[1] == "create": if sys.argv[1] == "create":
projectManager = ofProjectManager(sys.argv[2]) if(len(sys.argv) > 3):
# specify project path
projectManager = ofProjectManager(sys.argv[2],sys.argv[3])
projectManager.saveProject() projectManager.saveProject()

else:
if(len(sys.argv) > 2):
# do not specify project path
projectManager = ofProjectManager(sys.argv[2])
projectManager.saveProject()
else: else:
print """Usage: ofProjectManager [command] [project] [addon] print """Usage: ofProjectManager [command] [project] [addon]
commands: create commands: create
Expand Down

0 comments on commit f0c4d39

Please sign in to comment.