def process_admin_request(self, req, cat, page, path_info): envs = DatamoverSystem(self.env).all_environments() source_db = self.env.get_db_cnx() source_cursor = source_db.cursor() source_cursor.execute('SELECT type, name FROM enum') hashed_enums = {} for enum_type, enum_name in source_cursor: hashed_enums.setdefault(enum_type, []).append(enum_name) if req.method == 'POST': source_type = req.args.get('source') if not source_type or source_type not in ('type', 'enum', 'all'): raise TracError, "Source type not specified or invalid" source = req.args.get(source_type) dest = req.args.get('destination') action = None if 'copy' in req.args.keys(): action = 'copy' elif 'move' in req.args.keys(): action = 'move' else: raise TracError, 'Action not specified or invalid' action_verb = {'copy': 'Copied', 'move': 'Moved'}[action] enum_filter = None if source_type == 'type': sel_type = req.args.get('enumtype') enum_filter = lambda e: e[0] == sel_type elif source_type == 'enum': sel_enums = [(k, v) for k, v in req.args.items() if k.startswith('enum[')] enum_filter = lambda e: ('enum[%s]' % e[0], e[1]) in sel_enums elif source_type == 'all': enum_filter = lambda c: True try: filtered_enums = [e for e in enums if enum_filter(e)] dest_db = _open_environment(dest).get_db_cnx() for enum in filtered_enums: copy_enum(self.env, dest, enum[0], enum[1], dest_db) dest_db.commit() if action == 'move': for enum in filtered_enums: source_cursor.execute( 'DELETE FROM enum WHERE type=%s AND name=%s', enum) req.hdf['datamover.message'] = '%s enums %s' % ( action_verb, ', '.join( ['%s:%s' % e for e in filtered_enums])) except TracError, e: req.hdf[ 'datamover.message'] = "An error has occured: \n" + str(e) self.log.warn(req.hdf['datamover.message'], exc_info=True)
def process_admin_request(self, req, cat, page, path_info): envs = DatamoverSystem(self.env).all_environments() permissions = PermissionSystem(self.env).get_all_permissions() if req.method == 'POST': source_type = req.args.get('source') if not source_type or source_type not in ('permission', 'all'): raise TracError, "Source type not specified or invalid" source = req.args.get(source_type) dest = req.args.get('destination') action = None if 'copy' in req.args.keys(): action = 'copy' elif 'move' in req.args.keys(): action = 'move' else: raise TracError, 'Action not specified or invalid' action_verb = {'copy': 'Copied', 'move': 'Moved'}[action] perm_filter = None if source_type == 'permission': in_permissions = [ tuple(p.split(':', 2)) for p in req.args.getlist('perm') ] perm_filter = lambda p: p in in_permissions elif source_type == 'all': perm_filter = lambda p: True try: sel_permissions = [p for p in permissions if perm_filter(p)] dest_env = _open_environment(dest) for perm in sel_permissions: # revoke first in case it's already there # also, go directly to the store to bypass validity checks PermissionSystem(dest_env).store.revoke_permission( perm[0], perm[1]) PermissionSystem(dest_env).store.grant_permission( perm[0], perm[1]) if action == 'move': for perm in sel_permissions: PermissionSystem(self.env).revoke_permission( perm[0], perm[1]) req.hdf['datamover.message'] = '%s permissions %s' % ( action_verb, ', '.join( ["%s:%s" % (u, a) for u, a in sel_permissions])) except TracError, e: req.hdf[ 'datamover.message'] = "An error has occured: \n" + str(e) self.log.warn(req.hdf['datamover.message'], exc_info=True)
def process_admin_request(self, req, cat, page, path_info): envs = DatamoverSystem(self.env).all_environments() if req.method == 'POST': source_type = req.args.get('source') if not source_type or source_type not in ('prefix', 'glob', 'regex', 'all'): raise TracError, "Source type not specified or invalid" source = req.args.get(source_type) dest = req.args.get('destination') action = None if 'copy' in req.args.keys(): action = 'copy' elif 'move' in req.args.keys(): action = 'move' else: raise TracError, 'Action not specified or invalid' action_verb = {'copy': 'Copied', 'move': 'Moved'}[action] page_filter = None if source_type == 'prefix': page_filter = lambda p: p.startswith(source.strip()) elif source_type == 'glob': page_filter = lambda p: fnmatch.fnmatch(p, source) elif source_type == 'regex': page_filter = lambda p: re.search(re.compile(source, re.U), p) elif source_type == 'all': page_filter = lambda p: True try: pages = [ p for p in WikiSystem(self.env).get_pages() if page_filter(p) ] dest_db = _open_environment(dest).get_db_cnx() for page in pages: copy_wiki_page(self.env, dest, page, dest_db) dest_db.commit() if action == 'move': for page in pages: WikiPage(self.env, page).delete() req.hdf['datamover.message'] = '%s pages %s' % ( action_verb, ', '.join(pages)) except TracError, e: req.hdf[ 'datamover.message'] = "An error has occured: \n" + str(e) self.log.warn(req.hdf['datamover.message'], exc_info=True)
def process_admin_request(self, req, cat, page, path_info): system = DatamoverSystem(self.env) envs = system.all_environments() any_mutable = system.any_mutable() if req.method == 'POST': if req.args.get('add'): path = req.args.get('env_path') if not path: raise TracError('You must give a path to add') system.add_environment(path) elif req.args.get('remove'): envs = req.args.getlist('sel') for env in envs: system.delete_environment(env) req.redirect(req.href.admin(cat, page)) req.hdf['datamover.envs'] = envs req.hdf['datamover.any_mutable'] = any_mutable return 'datamover_config.cs', None
def process_admin_request(self, req, cat, page, path_info): envs = DatamoverSystem(self.env).all_environments() versions = [v.name for v in Version.select(self.env)] if req.method == 'POST': source_type = req.args.get('source') if not source_type or source_type not in ('version', 'all'): raise TracError, "Source type not specified or invalid" source = req.args.get(source_type) dest = req.args.get('destination') action = None if 'copy' in req.args.keys(): action = 'copy' elif 'move' in req.args.keys(): action = 'move' else: raise TracError, 'Action not specified or invalid' action_verb = {'copy': 'Copied', 'move': 'Moved'}[action] ver_filter = None if source_type == 'version': in_versions = req.args.getlist('version') ver_filter = lambda c: c in in_versions elif source_type == 'all': ver_filter = lambda c: True try: sel_versions = [v for v in versions if ver_filter(v)] dest_db = _open_environment(dest).get_db_cnx() for version in sel_versions: copy_version(self.env, dest, version, dest_db) dest_db.commit() if action == 'move': for version in sel_versions: Version(self.env, version).delete() req.hdf['datamover.message'] = '%s versions %s' % ( action_verb, ', '.join(sel_versions)) except TracError, e: req.hdf[ 'datamover.message'] = "An error has occured: \n" + str(e) self.log.warn(req.hdf['datamover.message'], exc_info=True)
def process_admin_request(self, req, cat, page, path_info): envs = DatamoverSystem(self.env).all_environments() source_db = self.env.get_db_cnx() source_cursor = source_db.cursor() source_cursor.execute("SELECT id FROM attachment WHERE type = 'wiki'") wiki_pages = list(set([a for (a, ) in source_cursor])) # kill duplicates wiki_pages.sort() if req.method == 'POST': source_type = req.args.get('source') if not source_type or source_type not in ('type', 'wiki', 'ticket', 'all'): raise TracError, "Source type not specified or invalid" source = req.args.get(source_type) dest = req.args.get('destination') action = None if 'copy' in req.args.keys(): action = 'copy' elif 'move' in req.args.keys(): action = 'move' else: raise TracError, 'Action not specified or invalid' action_verb = {'copy': 'Copied', 'move': 'Moved'}[action] att_filter = None if source_type == 'type': in_type = req.args.get('type') att_filter = lambda a: a.parent_type == in_type elif source_type == 'wiki': in_pages = req.args.getlist('wiki') att_filter = lambda a: a.parent_type == 'wiki' and a.parent_id in in_pages elif source_type == 'ticket': in_ticket = req.args.get('ticket') att_filter = lambda a: a.parent_type == 'ticket' and a.parent_id == in_ticket elif source_type == 'all': att_filter = lambda c: True try: source_cursor.execute( 'SELECT type,id,filename FROM attachment') attachments = [ Attachment(self.env, t, i, f) for (t, i, f) in source_cursor ] sel_attachments = [a for a in attachments if att_filter(a)] dest_db = _open_environment(dest).get_db_cnx() for att in sel_attachments: copy_attachment(self.env, dest, att.parent_type, att.parent_id, att.filename, dest_db) dest_db.commit() if action == 'move': for att in sel_attachments: att.delete() req.hdf['datamover.message'] = '%s attachments %s' % ( action_verb, ', '.join([ "%s:%s" % (a.parent_id, a.filename) for a in sel_attachments ])) except TracError, e: req.hdf[ 'datamover.message'] = "An error has occured: \n" + str(e) self.log.warn(req.hdf['datamover.message'], exc_info=True)