def get_buildtree(vertices, indices, normals): doc = XMLNode("buildspace") gen = doc.generator gen.config.attrs = {"a": 10} gen.attrs = (("id", "1"), ("seed", "1"), ("name", "generator"), ("location", "None"), ("bbox", "None")) gen_geoms = gen.geoms geom = gen_geoms.geom geom.attrs = ( ("shape", "geom"), ("bbox", "None"), ("area", "None"), ("volume", "None"), ("location", "None"), ("visible", 1), ) geom.mesh = "%s;\n%s;\n%s;" % (repr(vertices), repr(normals), repr(indices)) sgen = gen.sub_generators s = stringio() doc.serialize(s) build_tree = s.getvalue() return build_tree
def serialize(self, **options): doc = XMLNode('buildspace') self.root_gen.serialize(doc, **options) stream = cStringIO.StringIO() doc.serialize(stream) return stream.getvalue()
def apiresponse(message=None, code='success', data=None): message = message or resp_codes[code][1] code_no = resp_codes[code][0] response = HttpResponse(mimetype='text/xml') root = XMLNode('response') root.attrs = {'code': code_no, 'message': message} if data: data = xmlrpclib.dumps((data,), allow_none=True) if data else data root.data = data response.write('<?xml version="1.0"?>\n') root.serialize(response) return response
def main(options): repo_xml = os.path.join(options.repo_dir, 'repository.xml') if os.path.exists(repo_xml): print 'repository already exists at "%s"' % options.repo_dir sys.exit(1) # create repo dir if not os.path.exists(options.repo_dir): os.makedirs(options.repo_dir) # create repo data dir repo_data_dir = os.path.join(options.repo_dir, 'data') if not os.path.exists(repo_data_dir): os.makedirs(repo_data_dir) # create symlink to cgi scripts actions_dir = os.path.join(options.repo_dir, 'actions') cgi_scripts_dir = os.path.join(options.installation_dir, \ 'repository/server/cgi/') os.symlink(cgi_scripts_dir, actions_dir) # create 'repository.xml' ostream = open(repo_xml, 'w') repo = XMLNode('repository') repo.attrs = {'title': options.title} if options.description: repo.description = options.description ostream.write('<?xml version="1.0" encoding="UTF-8"?>\n') repo.serialize(ostream) ostream.close() # inform user of installation dir being used print 'using: installation_dir = "%s"' % (options.installation_dir) # write .htaccess for apache config htaccess_fpath = os.path.join(options.repo_dir, '.htaccess') f = open(htaccess_fpath, 'w') conf = APACHE_CONFIG % {'pythonpath': options.installation_dir} f.write(conf) f.close()