def get_all(cls, force_reload=False): """ Return all available categories. """ if force_reload: cls.__cache__ = [] if not len(cls.__cache__): tree = etree.parse( os.path.join(settings.get_config_dir(), 'categories.xml')) for node in tree.getroot().findall('category'): cls.__cache__.append(models.Category.new(node)) return cls.__cache__
def get_all(cls, force_reload=False): """ Return all available categories. """ if force_reload: cls.__cache__ = [] if not len(cls.__cache__): tree = etree.parse(os.path.join( settings.get_config_dir(), 'categories.xml' )) for node in tree.getroot().findall('category'): cls.__cache__.append(models.Category.new(node)) return cls.__cache__
@staticmethod def create(action_id, **kwargs): """ Create a new action skeleton with the give parameters. """ action_dir = action_id action_id = os.path.basename(action_id) # create directory of the action try: assert(action_id not in [a.info['id'] for a in ActionManager.get_all()]) os.mkdir(action_dir, 0744) except Exception, exc: raise Exception('Action "%s" already exists' % action_id) confdir = settings.get_config_dir() # write the xml file xmlfile = os.path.join(action_dir, 'action.xml') try: xml = etree.parse(os.path.join(confdir, 'action.xml.in')) xml.getroot().attrib['id'] = action_id # XXX todo fill the xml fh = open(xmlfile, 'w') fh.write('<?xml version="1.0" encoding="utf-8"?>\n') xml.write(fh, 'utf-8') fh.close() except Exception, exc: if os.path.exists(xmlfile): os.unlink(xmlfile) os.rmdir(action_dir) raise
@staticmethod def create(action_id, **kwargs): """ Create a new action skeleton with the give parameters. """ action_dir = action_id action_id = os.path.basename(action_id) # create directory of the action try: assert (action_id not in [a.info['id'] for a in ActionManager.get_all()]) os.mkdir(action_dir, 0744) except Exception, exc: raise Exception('Action "%s" already exists' % action_id) confdir = settings.get_config_dir() # write the xml file xmlfile = os.path.join(action_dir, 'action.xml') try: xml = etree.parse(os.path.join(confdir, 'action.xml.in')) xml.getroot().attrib['id'] = action_id # XXX todo fill the xml fh = open(xmlfile, 'w') fh.write('<?xml version="1.0" encoding="utf-8"?>\n') xml.write(fh, 'utf-8') fh.close() except Exception, exc: if os.path.exists(xmlfile): os.unlink(xmlfile) os.rmdir(action_dir) raise