def evolve_process_def(root, registry): def_container = find_service('process_definition_container') for pd in def_container.definitions: pd.contexts = PersistentList([]) log.info('Process def evolved.')
def _cleanup(self, obj): references = [ o for o in obj.__dict__.get(self.key, _empty) if get_ref(o) is not None ] setattr(obj, self.key, PersistentList(references))
def migrate_responses(self, task): container = IResponseContainer(task) old_container = OldIResponseContainer(task) for old_response in old_container: response = TaskResponse() if old_response.text: response.text = old_response.text if old_response.rendered_text: response.rendered_text = old_response.rendered_text if old_response.transition: response.transition = old_response.transition if old_response.changes: for change in old_response.changes: response.add_change(change.get('id'), change.get('before'), change.get('after'), change.get('name')) if old_response.creator: response.creator = old_response.creator if old_response.date: response.created = old_response.date.asdatetime().replace( tzinfo=None) if old_response.type: response.response_type = old_response.type if old_response.type: response.mimetype = old_response.mimetype if old_response.relatedItems: response.related_items = PersistentList( old_response.relatedItems) if old_response.added_object: added_objects = old_response.added_object if not hasattr(added_objects, '__iter__'): added_objects = [added_objects] response.added_objects = PersistentList(added_objects) if old_response.successor_oguid: response.successor_oguid = old_response.successor_oguid container.add(response) annotations = IAnnotations(task) if old_container.ANNO_KEY in annotations: # We do not delete the old responses but backup it in a different # annotations-key. As soon as we completely remove the old implementation # we can remove the backup. Otherwise we won't have the possibilty to # restore any response if there went soemthing wrong. # Just leaving the responses under the same key is not an option. # Running the upgradestep twice would duplicate the migrated responses. annotations['backup-{}'.format( old_container.ANNO_KEY)] = annotations[old_container.ANNO_KEY] del annotations[old_container.ANNO_KEY]
class UserProfile(grok.Model): grok.implements(IUserProfile, ILayout) # Derived stats health = 0 # 1 Vitality = 10 health) armor = 0 # Toughness + Defense crit_chance = 0 # (Crit Chance = 5% + Precision / 21 crit_dmg = 0 # (Crit Dmg = 150% + by Ferocity/15 boon_duration = 0 # Increased by Concentration (15 = 1%) cond_duration = 0 # Increased by Expertise (15 = 1%) base_health = {'Warrior':9212, 'Necromancer':9212, 'Revenant':5922, 'Engineer':5922, 'Ranger':5922, 'Mesmer':5922, 'Guardian':1645, 'Thief':1645, 'Elementalist':1645 } stats = PersistentDict() runes = PersistentDict() buffs = PersistentList() selected_weapon = 0 selected_traits = [] characters = [] selected = '' refresh = False skill_choices = None skill_choice = None gear = [] trinkets = [] amulet = [] backpack = [] aquatic = [] game_modes = ["pve", "pvp", "wvw"] gmode = "wvw" spec_bg = grok.Container() grok.traversable('spec_bg') def __init__(self, user): location.locate(self.spec_bg, self, 'spec_bg') self.user = user def update(self): location.locate(self.spec_bg, self, 'spec_bg') account = GW2API().account(self.user.gw2_apikey) if account is not None: self.account = account characters = GW2API().characters(self.user.gw2_apikey) if characters is not None: self.characters = characters # self.refresh=True if len(self.selected)==0: self.selected = self.characters[0] self.refresh = True if self.refresh: core = GW2API().character_core(self.user.gw2_apikey, self.selected) if core is not None: self.core = core # self.equipment = GW2API().character_equipment(self.user.gw2_apikey, self.selected) # self.skills = GW2API().character_skills(self.user.gw2_apikey, self.selected) # self.specializations = GW2API().character_specializations(self.user.gw2_apikey, self.selected) self.refresh = False self.stats = PersistentDict({'Power': 1000, 'Precision': 1000, 'Toughness': 1000, 'Vitality':1000, 'Defense':0, 'ConditionDamage': 0, 'CritDamage':0, 'Concentration':0, 'Expertise':0, 'Ferocity':0, 'Healing':0, 'BoonDuration':0, 'ConditionDuration':0 }) self.runes = PersistentDict() self.buffs = PersistentList() self.gear = self._gear() self.trinkets = self._trinkets() self.amulet = self._amulet() self.backpack = self._backpack() self.weapons = self._weapons() self.aquatic = self._aquatic() self.profession = GW2API().get_profession(self.core['profession']) self.skill_choices = None if self.profession['name'] == 'Elementalist': self.skill_choices = 'attunement' if self.skill_choice is None: self.skill_choice = 'Fire' self.prof_skills = self._profession_skills() self.weap_skills = self._weapon_skills() self.rune_bonuses = [] for r in self.runes.values(): b = r['rune']['bonuses'][:r['count']] for effect in b: self.rune_bonuses.append(effect) if effect.find(' to All Stats')>0: perc = int(effect.split(' ')[0]) for stat in ['Power', 'Precision', 'Toughness', 'Vitality', 'Ferocity', 'Healing', 'ConditionDamage']: self.stats[stat] += perc elif effect.find('% Boon Duration') > 0: perc = int(effect.split('%')[0]) self.stats['BoonDuration'] += perc * 15 elif self._stat_effect(effect): pass else: self.buffs.append(effect) self.health = self.stats['Vitality'] * 10 + self.base_health[self.core['profession']] self.armor = self.stats['Toughness'] + self.stats['Defense'] self.crit_chance = (self.stats['Precision']-916) / 21.0 self.crit_dmg = 150 + (self.stats['CritDamage'] + self.stats['Ferocity']) / 15.0 self.boon_duration = (self.stats['BoonDuration'] + self.stats['Concentration']) / 15.0 self.cond_duration = (self.stats['ConditionDuration'] + self.stats['Expertise']) / 15.0 # for i in list(self.spec_bg.keys()): # del self.spec_bg[i] self.selected_traits = [] for spec in self.specs(): for t in spec['traits']: if 'description' in t: self.buffs.append("%s - %s"%(t['name'], t['description'])) else: self.buffs.append(t['name']) img = SpecImage(spec['id']['background']) if img.fn not in self.spec_bg.keys(): img.retrieve() self.spec_bg[img.fn] = img spec['id']['img_no'] = img.fn self.selected_traits.extend([t['name'] for t in spec['traits']]) pass def gear_title(self, gear): try: if 'stats' in gear: stats = [ "%s: +%s" % (n, s) for n, s in gear['stats']['attributes'].items()] return "\n".join(stats) else: attributes = gear['id']['details']['infix_upgrade']['attributes'] return "\n".join(['%s: +%s' % (a['attribute'], a['modifier']) for a in attributes]) except Exception, e: print "Cannot determine gear title for %s" % gear print "%s" % str(e) return ''
def _update(self, values): """ Update criteria """ anno = IAnnotations(self.context) anno[ANNO_CRITERIA] = PersistentList(values) self.criteria = anno[ANNO_CRITERIA]
def checkTheWorld(self): # Test constructors u = PersistentList() u0 = PersistentList(l0) u1 = PersistentList(l1) u2 = PersistentList(l2) uu = PersistentList(u) uu0 = PersistentList(u0) uu1 = PersistentList(u1) uu2 = PersistentList(u2) v = PersistentList(tuple(u)) class OtherList: def __init__(self, initlist): self.__data = initlist def __len__(self): return len(self.__data) def __getitem__(self, i): return self.__data[i] v0 = PersistentList(OtherList(u0)) vv = PersistentList("this is also a sequence") # Test __repr__ eq = self.assertEqual eq(str(u0), str(l0), "str(u0) == str(l0)") eq(repr(u1), repr(l1), "repr(u1) == repr(l1)") eq( ` u2 `, ` l2 `, "`u2` == `l2`") # Test __cmp__ and __len__ def mycmp(a, b): r = cmp(a, b) if r < 0: return -1 if r > 0: return 1 return r all = [l0, l1, l2, u, u0, u1, u2, uu, uu0, uu1, uu2] for a in all: for b in all: eq(mycmp(a, b), mycmp(len(a), len(b)), "mycmp(a, b) == mycmp(len(a), len(b))") # Test __getitem__ for i in range(len(u2)): eq(u2[i], i, "u2[i] == i") # Test __setitem__ uu2[0] = 0 uu2[1] = 100 try: uu2[2] = 200 except IndexError: pass else: raise TestFailed("uu2[2] shouldn't be assignable") # Test __delitem__ del uu2[1] del uu2[0] try: del uu2[0] except IndexError: pass else: raise TestFailed("uu2[0] shouldn't be deletable") # Test __getslice__ for i in range(-3, 4): eq(u2[:i], l2[:i], "u2[:i] == l2[:i]") eq(u2[i:], l2[i:], "u2[i:] == l2[i:]") for j in range(-3, 4): eq(u2[i:j], l2[i:j], "u2[i:j] == l2[i:j]") # Test __setslice__ for i in range(-3, 4): u2[:i] = l2[:i] eq(u2, l2, "u2 == l2") u2[i:] = l2[i:] eq(u2, l2, "u2 == l2") for j in range(-3, 4): u2[i:j] = l2[i:j] eq(u2, l2, "u2 == l2") uu2 = u2[:] uu2[:0] = [-2, -1] eq(uu2, [-2, -1, 0, 1], "uu2 == [-2, -1, 0, 1]") uu2[0:] = [] eq(uu2, [], "uu2 == []") # Test __contains__ for i in u2: self.failUnless(i in u2, "i in u2") for i in min(u2) - 1, max(u2) + 1: self.failUnless(i not in u2, "i not in u2") # Test __delslice__ uu2 = u2[:] del uu2[1:2] del uu2[0:1] eq(uu2, [], "uu2 == []") uu2 = u2[:] del uu2[1:] del uu2[:1] eq(uu2, [], "uu2 == []") # Test __add__, __radd__, __mul__ and __rmul__ #self.failUnless(u1 + [] == [] + u1 == u1, "u1 + [] == [] + u1 == u1") self.failUnless(u1 + [1] == u2, "u1 + [1] == u2") #self.failUnless([-1] + u1 == [-1, 0], "[-1] + u1 == [-1, 0]") self.failUnless(u2 == u2 * 1 == 1 * u2, "u2 == u2*1 == 1*u2") self.failUnless(u2 + u2 == u2 * 2 == 2 * u2, "u2+u2 == u2*2 == 2*u2") self.failUnless(u2 + u2 + u2 == u2 * 3 == 3 * u2, "u2+u2+u2 == u2*3 == 3*u2") # Test append u = u1[:] u.append(1) eq(u, u2, "u == u2") # Test insert u = u2[:] u.insert(0, -1) eq(u, [-1, 0, 1], "u == [-1, 0, 1]") # Test pop u = PersistentList([0, -1, 1]) u.pop() eq(u, [0, -1], "u == [0, -1]") u.pop(0) eq(u, [-1], "u == [-1]") # Test remove u = u2[:] u.remove(1) eq(u, u1, "u == u1") # Test count u = u2 * 3 eq(u.count(0), 3, "u.count(0) == 3") eq(u.count(1), 3, "u.count(1) == 3") eq(u.count(2), 0, "u.count(2) == 0") # Test index eq(u2.index(0), 0, "u2.index(0) == 0") eq(u2.index(1), 1, "u2.index(1) == 1") try: u2.index(2) except ValueError: pass else: raise TestFailed("expected ValueError") # Test reverse u = u2[:] u.reverse() eq(u, [1, 0], "u == [1, 0]") u.reverse() eq(u, u2, "u == u2") # Test sort u = PersistentList([1, 0]) u.sort() eq(u, u2, "u == u2") # Test extend u = u1[:] u.extend(u2) eq(u, u1 + u2, "u == u1 + u2")
def __init__(self, config: PruneConfig): super().__init__() self.config = config self.repositories = PersistentList()
def add_data(self, name, data): if not hasattr(self, name): setattr(self, name, PersistentList()) getattr(self, name).append(data)
def __init__(self, title): self.title = title self.entries = PersistentList()
def __init__(self): super(OrderedContainer, self).__init__() self._order = PersistentList()
def __init__(self): super(ExecutionContext, self).__init__() self.parent = None self.sub_execution_contexts = PersistentList() self.properties_names = PersistentList()
def __init__(self, warehouse, name): self._warehouse = warehouse self.name = name self.metadata = PersistentMapping() self.history = PersistentList()
def list_to_plist(l): pl = PersistentList() for val in l: pl.append(obj_to_pobj(val)) return pl
def load_data(fname, root_node): json_data = load_json(fname) root_node['data'] = PersistentList() for d in json_data: root_node['data'].append(PersistentMapping(d))
def get_participations(self): return self.annotations.get(self.annotation_key, PersistentList())
def start(self, context, request, appstruct, **kw): context.state = PersistentList(['submitted']) context.reindex() return {}
def deliver_documents_and_complete_task(self, formdata, response): """Delivers the selected documents to the predecesser task and complete the task: - Copy the documents to the predecessor task (no new responses) - Execute workflow transition (no new response) - Add a new response indicating the workflow transition, the added documents and containing the entered response text. """ # add documents to the response response.added_object = PersistentList() predecessor = Task.query.by_oguid(self.context.predecessor) transporter = Transporter() intids = getUtility(IIntIds) data = { 'documents': [], 'text': formdata['text'], 'transition': formdata['transition'] } related_ids = [] if getattr(self.context, 'relatedItems'): related_ids = [item.to_id for item in self.context.relatedItems] for doc_intid in formdata['documents']: doc = intids.getObject(int(doc_intid)) data['documents'].append(transporter.extract(doc)) # add a releation when a document from the dossier was selected if int(doc_intid) not in related_ids: # check if its a relation if aq_parent(aq_inner(doc)) != self.context: # add relation to doc on task if self.context.relatedItems: self.context.relatedItems.append( RelationValue(int(doc_intid))) else: self.context.relatedItems = [ RelationValue(int(doc_intid)) ] # add response change entry for this relation if not response.relatedItems: response.relatedItems = [RelationValue(int(doc_intid))] else: response.relatedItems.append( RelationValue(int(doc_intid))) # set relation flag doc._v__is_relation = True response.add_change( 'relatedItems', _(u'label_related_items', default=u"Related Items"), '', linked(doc, doc.Title())) else: # add entry to the response for this document response.added_object.append(RelationValue(int(doc_intid))) else: # append only the relation on the response doc._v__is_relation = True response.add_change( 'relatedItems', _(u'label_related_items', default=u"Related Items"), '', linked(doc, doc.Title())) request_data = {'data': json.dumps(data)} response = dispatch_request( predecessor.admin_unit_id, '@@complete_successor_task-receive_delivery', predecessor.physical_path, data=request_data) response_body = response.read() if response_body.strip() != 'OK': raise Exception('Delivering documents and updating task failed ' 'on remote client %s.' % predecessor.admin_unit_id)
def setData(self, portletsdata, metadata): """create or updates portlet informations """ for manager_name in portletsdata.keys(): column = queryUtility(IPortletManager, name=manager_name, context=self.object) if column is None: continue # ok we have a portlet manager # get all current assigned portlets portlets = getMultiAdapter(( self.object, column, ), IPortletAssignmentMapping, context=self.object) p_ids = [p for p in portlets._data.keys()] # get new order order = portletsdata[manager_name]['order'] and \ portletsdata[manager_name]['order'].split(',') or [] # set blackliststatus blacklist = getMultiAdapter((self.object, column), ILocalPortletAssignmentManager) blacklistdata = portletsdata[manager_name]['blackliststatus'] blacklist.setBlacklistStatus(GROUP_CATEGORY, blacklistdata[GROUP_CATEGORY]) blacklist.setBlacklistStatus(USER_CATEGORY, blacklistdata[USER_CATEGORY]) blacklist.setBlacklistStatus(CONTENT_TYPE_CATEGORY, blacklistdata[CONTENT_TYPE_CATEGORY]) blacklist.setBlacklistStatus(CONTEXT_CATEGORY, blacklistdata[CONTEXT_CATEGORY]) # bit clean up del portletsdata[manager_name]['blackliststatus'] del portletsdata[manager_name]['order'] # remove all currenlty assigned portlets from manager for p_id in p_ids: del portlets._data[p_id] for portlet_id in portletsdata[manager_name].keys(): portletfielddata = portletsdata[manager_name][portlet_id] # get Assignment portlet_module = modules[portletfielddata['module']] portlet_class = getattr( portlet_module, portletfielddata['assignment_class_name']) settings = portletfielddata.get('settings', None) # prepare data to pass as arguments del portletfielddata['module'] del portletfielddata['assignment_class_name'] del portletfielddata['settings'] annotations = portletfielddata.get('__annotations__', None) if '__annotations__' in portletfielddata: del portletfielddata['__annotations__'] # check for dicts for k, v in portletfielddata.items(): if isinstance(v, dict): # so we have one, now we have to turn the # serialized data into an object # this is generic, but currently only in use # by the image portlet klass = modules[v['module']].__dict__[v['klass_name']] for argname in ('file', 'data'): if argname in v['kwargs']: v['kwargs'][argname] = base64.decodestring( v['kwargs'][argname]) imgobj = klass(**v['kwargs']) portletfielddata[k] = imgobj portlets[portlet_id] = portlet_class(**portletfielddata) # XXX boolean value fix # for some reason boolean types cannpt be passed with **... # use setattr for k, v in portletfielddata.items(): if isinstance(v, bool): setattr(portlets[portlet_id], k, v) if annotations: portlets[portlet_id].__annotations__ = annotations # portlet settings (visibility) portlet_assignment = portlets[portlet_id] IPortletAssignmentSettings(portlet_assignment).data = settings # set new order afterwards portlets._order = PersistentList(order)
def __init__(self): self.policies = PersistentList() self.configs = PersistentList()
def __init__(self): self.viewlets = PersistentList() self.default = '' self.use_default_viewlets = True self.use_default_default = True
def reply(self): acl = api.portal.get_tool('acl_users') plugin = acl[PAS_ID] plugin.disabled_user_ids = PersistentList() return json.dumps(list(plugin.disabled_user_ids))
def _order(self, create=False): annotations = IAnnotations(self.context) if create: return annotations.setdefault(self.ORDER_KEY, PersistentList()) return annotations.get(self.ORDER_KEY, [])
def update(self): location.locate(self.spec_bg, self, 'spec_bg') account = GW2API().account(self.user.gw2_apikey) if account is not None: self.account = account characters = GW2API().characters(self.user.gw2_apikey) if characters is not None: self.characters = characters # self.refresh=True if len(self.selected)==0: self.selected = self.characters[0] self.refresh = True if self.refresh: core = GW2API().character_core(self.user.gw2_apikey, self.selected) if core is not None: self.core = core # self.equipment = GW2API().character_equipment(self.user.gw2_apikey, self.selected) # self.skills = GW2API().character_skills(self.user.gw2_apikey, self.selected) # self.specializations = GW2API().character_specializations(self.user.gw2_apikey, self.selected) self.refresh = False self.stats = PersistentDict({'Power': 1000, 'Precision': 1000, 'Toughness': 1000, 'Vitality':1000, 'Defense':0, 'ConditionDamage': 0, 'CritDamage':0, 'Concentration':0, 'Expertise':0, 'Ferocity':0, 'Healing':0, 'BoonDuration':0, 'ConditionDuration':0 }) self.runes = PersistentDict() self.buffs = PersistentList() self.gear = self._gear() self.trinkets = self._trinkets() self.amulet = self._amulet() self.backpack = self._backpack() self.weapons = self._weapons() self.aquatic = self._aquatic() self.profession = GW2API().get_profession(self.core['profession']) self.skill_choices = None if self.profession['name'] == 'Elementalist': self.skill_choices = 'attunement' if self.skill_choice is None: self.skill_choice = 'Fire' self.prof_skills = self._profession_skills() self.weap_skills = self._weapon_skills() self.rune_bonuses = [] for r in self.runes.values(): b = r['rune']['bonuses'][:r['count']] for effect in b: self.rune_bonuses.append(effect) if effect.find(' to All Stats')>0: perc = int(effect.split(' ')[0]) for stat in ['Power', 'Precision', 'Toughness', 'Vitality', 'Ferocity', 'Healing', 'ConditionDamage']: self.stats[stat] += perc elif effect.find('% Boon Duration') > 0: perc = int(effect.split('%')[0]) self.stats['BoonDuration'] += perc * 15 elif self._stat_effect(effect): pass else: self.buffs.append(effect) self.health = self.stats['Vitality'] * 10 + self.base_health[self.core['profession']] self.armor = self.stats['Toughness'] + self.stats['Defense'] self.crit_chance = (self.stats['Precision']-916) / 21.0 self.crit_dmg = 150 + (self.stats['CritDamage'] + self.stats['Ferocity']) / 15.0 self.boon_duration = (self.stats['BoonDuration'] + self.stats['Concentration']) / 15.0 self.cond_duration = (self.stats['ConditionDuration'] + self.stats['Expertise']) / 15.0 # for i in list(self.spec_bg.keys()): # del self.spec_bg[i] self.selected_traits = [] for spec in self.specs(): for t in spec['traits']: if 'description' in t: self.buffs.append("%s - %s"%(t['name'], t['description'])) else: self.buffs.append(t['name']) img = SpecImage(spec['id']['background']) if img.fn not in self.spec_bg.keys(): img.retrieve() self.spec_bg[img.fn] = img spec['id']['img_no'] = img.fn self.selected_traits.extend([t['name'] for t in spec['traits']]) pass
def __init__(self, contexts=(), **kwargs): super(ActivityDefinition, self).__init__(**kwargs) self.contexts = PersistentList([]) self._init_contexts(contexts)
def init(self, obj): if getattr(obj, self.key, _marker) is _marker: setattr(obj, self.key, PersistentList())
def _init_contexts(self, contexts): self.contexts = PersistentList(contexts) for context in contexts: context.node_definition = self
def reset(self, **kwargs): self.operator = kwargs.get('operator', 'AND') self._queries = PersistentMapping() self._order = PersistentList()
def roles(self, value): if value is None: pass elif not isinstance(value, PersistentList): value = PersistentList(value) self._roles = value
def __init__(self): RoomBlockingBase.__init__(self) self.blockedRooms = PersistentList() self.allowed = PersistentList()
def __init__(self, **kw): SchemaConfigured.__init__(self, **kw) Sso.__init__(self) self.__keys = PersistentList() self.new_key()