def update_resource(self, resource, new_resource=None, replace=True, flush=True, **kw): """update a resource with a new values @param resource: an etree element or uri @param new_resource: an etree element if resource is a uri @param replace: replace all members (if false then appends only) @param kw: view parameters for return """ uri = None log.debug('resource = %s' % resource) if isinstance(resource, etree._Element): uri = resource.get('uri') elif isinstance(resource, basestring): uri = resource if new_resource is None: raise BadValue( 'update_resource uri %s needs new_value to update ' % uri) if uri is not None: resource = load_uri(uri) log.debug('resource %s = %s' % (uri, resource)) node = bisquik2db(doc=new_resource, resource=resource, replace=replace) #response = etree.Element ('response') #self.cache_invalidate(r.get('uri')) if flush: self.flushchanges(node) self.cache_invalidate_resource(resource) r = db2tree(node, baseuri=self.url, **kw) return r
def new(self, factory, xml, **kw): """POST /ds/image : Create a reference to the image in the local database """ view = kw.pop('view', None) format = kw.pop('format', None) user = kw.pop('user', None) log.info("NEW: %s ... %s", request.url, xml.tag) # Create a DB object from the document. #if not identity.not_anonymous(): # pylons.response.status_int = 401 # return '<response status="FAIL">Permission denied</response>' parent = self.load_parent() log.debug("NEW: parent %s ", str(parent)) parent = self.check_access(parent, RESOURCE_EDIT) if user is not None and identity.is_admin(): self.set_new_identity(user) resource = bisquik2db(doc=xml, parent=parent) log.info("NEW: => %s ", str(resource)) if resource is None: resource = etree.Element('resource') resource.text = "FAIL" return self.resource_output(resource, view=view, format=format)
def new_resource(self, resource, parent=None, flush=True, **kw): '''Create a new resouce in the local database based on the resource tree given. ''' view = kw.pop('view', None) if isinstance(resource, basestring): log.debug('attributes= %s ', kw) resource = etree.Element(resource, **kw) log.debug('created %s ', resource) if parent is None and resource.get('resource_uniq') is None: resource.set('resource_uniq', self.resource_uniq()) else: if isinstance(parent, etree._Element): parent = parent.get('uri') if isinstance(parent, basestring): parent = load_uri(parent) node = bisquik2db(doc=resource, parent=parent) log.debug("new_resource %s", node) # Invalidate the top level container i.e. /data_service/<resource_type> #self.cache_invalidate(r.get('uri').rsplit('/', 1)[0]) if flush: self.flushchanges(node, parent) self.cache_invalidate_resource(node) r = db2tree(node, baseuri=self.url, view=view) return r
def append_resource(self, resource, tree=None, flush=True, **kw): '''Append an element to resource (a node) ''' if isinstance(resource, etree._Element): uri = resource.get('uri') resource = load_uri(uri) dbresource = bisquik2db(doc=tree, parent=resource) #self.cache_invalidate(r.get('uri')) if flush: self.flushchanges(dbresource, resource) self.cache_invalidate_resource(dbresource) r = db2tree(dbresource, baseuri=self.url, **kw) return r
def update(self, resource_tree, replace_all=False, flush=True, **kw): view = kw.pop('view', None) #if replace_all: # uri = resource_tree.get ('uri') # r = load_uri(resource_tree.get('uri')) # r.clear() resource = bisquik2db(doc=resource_tree, replace=replace_all) #response = etree.Element ('response') #self.cache_invalidate(r.get('uri')) if flush: self.flushchanges(resource) self.cache_invalidate_resource(resource) r = db2tree(resource, parent=None, view=view, baseuri=self.url) return r
def append(self, resource, xml, **kw): '''POST /ds/images/1/ : append the document to the resource Append value of the resource based on the args ''' view = kw.pop('view', None) user = kw.pop('user', None) if user is not None and identity.is_admin(): self.set_new_identity(user) log.info('APPEND %s %s', request.url, xml.tag) resource = self.check_access(resource, RESOURCE_EDIT) #parent = self.load_parent() resource = bisquik2db(doc=xml, parent=resource) #, resource = resource) log.info('APPEND/update: ==> %s ', str(resource)) return self.resource_output(resource, view=view)
def modify(self, resource, xml, **kw): '''PUT /ds/image/1 --> Replace all contents with doc ''' view = kw.pop('view', None) user = kw.pop('user', None) if user is not None and identity.is_admin(): self.set_new_identity(user) log.info('MODIFY %s %s', request.url, xml.tag) resource = self.check_access(resource, RESOURCE_EDIT) parent = self.load_parent() DBSession.autoflush = False old = resource.clear() log.debug("MODIFY: parent=%s resource=%s", str(parent), str(resource)) resource = bisquik2db(doc=xml, resource=resource, parent=parent, replace=True) log.info('MODIFIED: ==> %s ', str(resource)) return self.resource_output(resource, view=view)
def replace_all(self, resource, xml, **kw): '''PUT /ds/image/1/gobjects --> Replace contents of gobjects with doc ''' log.info('REPLACE_ALL %s %s', request.url, xml.tag) user = kw.pop('user', None) if user is not None and identity.is_admin(): self.set_new_identity(user) parent = self.load_parent() resource = None if parent: resource = self.check_access(parent, RESOURCE_EDIT) DBSession.autoflush = False log.debug('REPLACE %s in %s %s=>%s', self.resource_name, str(parent), xml.tag, str(resource)) # Here we clear the specific type (tag,gobject) etc. and parent.clear([self.resource_name]) resource = bisquik2db(doc=xml, parent=parent) if resource is None: resource = etree.Element('resource') resource.text = "FAIL" return self.resource_output(resource, **kw)
def bootstrap(command, conf, vars): """Place any commands to setup bq here""" # <websetup.bootstrap.before.auth from sqlalchemy.exc import IntegrityError from bq.data_service.model import Taggable, Tag, BQUser, ModuleExecution registry = Registry() registry.prepare() registry.register(session, SessionObject({})) registry.register(request, Request.blank('/bootstrap')) request.identity = {} log.info('BEGIN boostrap') try: initial_mex = ModuleExecution(mex_id = False, owner_id = False) initial_mex.mex = initial_mex initial_mex.name = "initialization" initial_mex.type = "initialization" initial_mex.hidden = True model.DBSession.add(initial_mex) model.DBSession.flush() admin = model.User( user_name = u"admin", display_name = config.get('bisque.admin_display_name', u'Bisque admin')) admin._email_address = config.get('bisque.admin_email', u'*****@*****.**') admin.password = u'admin' # password = u'admin') #admin.password = u'admin' model.DBSession.add(admin) for g in [ u'admins', u'managers' ] : group = model.Group() group.group_name = g group.display_name = u'Administrators Group' group.users.append(admin) model.DBSession.add(group) permission = model.Permission() permission.permission_name = u'root' permission.description = u'This permission give an administrative right to the bearer' permission.groups.append(group) model.DBSession.add(permission) #model.DBSession.flush() # This commit will setup the BQUser also transaction.commit() except IntegrityError: print 'Warning, there was a problem adding your auth data, it may have already been added:' #import traceback #print traceback.format_exc() transaction.abort() print 'Continuing with bootstrapping...' try: ###### # #from bq.data_service.model import UniqueName initial_mex = model.DBSession.query(ModuleExecution).first() session['mex_id'] = initial_mex.id #request.identity['bisque.mex_id'] = initial_mex.id admin = model.DBSession.query(BQUser).filter_by(resource_name = 'admin').first() admin.mex_id = initial_mex.id initial_mex.owner = admin session['user'] = admin system = model.DBSession.query(Taggable).filter_by (resource_type='system').first() if system is None: system_prefs = defaults_path('preferences.xml.default') if os.path.exists(system_prefs): with open (system_prefs) as f: system = bisquik2db (f) system.permission = 'published' else: print( "Couldn't find %s: using minimal default preferences" % system_prefs) system = Taggable(resource_type = 'system') version = Tag(parent = system) version.name ='version' version.value = __VERSION__ prefs = Tag(parent = system) prefs.name = 'Preferences' model.DBSession.add(system) transaction.commit() except IntegrityError: log.exception ( 'Warning, there was a problem adding your system object, it may have already been added:') #import traceback #print traceback.format_exc() transaction.abort() log.warning ( 'Continuing with bootstrapping...' ) log.info('END boostrap')