def load_project(filename): """ Helper function that creates a whole new project from the given project file (extension spj). >>> load_project("zno.spj") """ try: archive = tarfile.open(filename,'r:gz') except tarfile.ReadError: logger.error('Error while opening archive "%s"' % filename) raise FileNotFoundError logger.debug("Creating project from project.xml") # Create Project from file try: projectfile = archive.extractfile("project.xml") # project filename must be set _before_ fromTree, # because any importer that is set up therein # must know the project filename! project = Project() project.filename = filename fromTree( project, parse(projectfile) ) except: raise # remember the archive so that it can be closed later on project._archive = archive return project
def read_configfile(app, filename=const.CONFIG_FILE): check_path() # open config file filename = os.path.expanduser(filename) if os.path.isfile(filename) is not True: logger.info("No configuration file '%s' found." % filename) # create root element return Element("Config") else: logger.info("Reading configuration file '%s'." % filename) fd = open(filename, 'r') try: try: eRoot = parse(fd).getroot() #parse_all(app, eRoot) return eRoot except: raise print "Parse Error" finally: fd.close()