def get_all(cls, force_reload=False): """ Return all available actions. """ if force_reload: cls.__cache__ = [] if not len(cls.__cache__): sys_dir = settings.get_builtin_actions_dir() user_dir = settings.get_user_actions_dir() dirs = [os.path.join(sys_dir, d) for d in os.listdir(sys_dir)] + \ [os.path.join(user_dir, d) for d in os.listdir(user_dir)] sys.path.append(sys_dir) sys.path.append(user_dir) for d in dirs: try: xml = os.path.join(d, 'action.xml') assert os.path.exists(xml) node = etree.parse(xml).getroot() action_id = os.path.basename(d) mod = __import__(action_id) cls.__cache__.append(mod.UserAction.new(node)) except (AssertionError, ImportError), exc: pass sys.path.remove(sys_dir) sys.path.remove(user_dir)
def install(action_path, system_wide=False): """ Install the given action (either an action directory or an action zip file) system wide if the system_wide param is set to True or in the user home directory otherwise. """ if not os.path.exists(action_path): raise Exception('"%s" not found, please provide the path to the'\ ' action you want to install' % action_path) action_id = os.path.basename(action_path) if system_wide: path = settings.get_builtin_actions_dir() else: path = settings.get_user_actions_dir() if not os.path.exists(path): os.makedirs(path, 0744) if not helpers.is_valid_action(action_path): raise Exception('Invalid action "%s"' % action_path) destpath = os.path.join(path, action_id) if os.path.exists(destpath): raise Exception('Action "%s" already installed' % action_id) if zipfile.is_zipfile(action_path): helpers.extract_zipfile(action_path, path) else: shutil.copytree(action_path, destpath) return action_id
def uninstall(action_id): """ Uninstall the given action identified by action id. """ action_id = os.path.basename(action_id) for p in [settings.get_user_actions_dir(), settings.get_builtin_actions_dir()]: d = os.path.join(p, '%s' % action_id) if os.path.isfile(os.path.join(d, 'action.xml')): shutil.rmtree(d) return action_id raise Exception('Action "%s" is not installed' % action_id)
def uninstall(action_id): """ Uninstall the given action identified by action id. """ action_id = os.path.basename(action_id) for p in [ settings.get_user_actions_dir(), settings.get_builtin_actions_dir() ]: d = os.path.join(p, '%s' % action_id) if os.path.isfile(os.path.join(d, 'action.xml')): shutil.rmtree(d) return action_id raise Exception('Action "%s" is not installed' % action_id)