if len(zargs) != 3: raise Exception("3 parameters expected, found " + str(len(zargs))) oid = zargs[0] omodule = zargs[1] oclass = zargs[2] params = {'__name__' : zname, '__package__' : zpackage, '__oid__' : oid, '__omodule__' : omodule, '__oclass__' : oclass} # Create the object file if it does not already exist utils.replicate(zpath + "/templates/ZenPacks", ".", params, False) # Now we need to parse the desitination file as XML and then rewrite it # with our new object ofile = "ZenPacks/" + zpackage + "/" + zname + "/objects/objects.xml" dom = parse(ofile) node = xpath.find("//object[@id='" + oid + "']", dom) # If an object with the given ID was found then raise an exception if len(node) != 0: raise Exception("Object '" + oid + "' already exists") # The object does not exists, so find the "root" object node and add it node = xpath.find("/objects", dom) if len(node) != 1: raise Exception("Object something really, really bad happened, object file is not the correct format")
''' import sys import errno from zails import utils global zargs, zpath, zpackage, zname if __name__ == '__main__': if zpackage != None: raise Exception("Attempting to create a ZenPack in a location where one already exists") if len(zargs) != 2: sys.stderr.write("error: invalid number of arguments, found " + str(len(zargs)) + " expected 2\n") sys.stderr.write("usage: create zenpack <zenpack package name> <zenpack name>\n") sys.stderr.write("example: create zenpack community sample\n") sys.exit(1) package = zargs[0] name = zargs[1] # Construct the base ZenPack directory structure. try: base = "ZenPacks." + package + "." + name params = {'__name__' : name, '__package__' : package} utils.replicate(zpath + "/templates/ZenPacks.__package__.__name__", ".", params) except OSError as err: if err.errno == errno.EEXIST: pass else: raise