Changeset cdfc6b in indico
- Timestamp:
- 01/24/11 15:07:18 (2 years ago)
- Branches:
- master, burotel, hello-world-walkthrough, ipv6, v0.98-series, v0.98.2, v0.98.3, v0.98b1, v0.98b2, v0.99, 051b2622c51afb171a1dedb46a0df4fbb0cbd02e, 4c7d4152dff271ba5df5a8606605969cab454080
- Children:
- 76defd
- Parents:
- 6df324
- git-author:
- Pedro Ferreira <jose.pedro.ferreira@…> (12/16/10 11:45:36)
- git-committer:
- Pedro Ferreira <jose.pedro.ferreira@…> (01/24/11 15:07:18)
- File:
-
- 1 edited
-
indico/ext/livesync/invenio/agent.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
indico/ext/livesync/invenio/agent.py
r3e1254 rcdfc6b 31 31 from MaKaC.common.xmlGen import XMLGen 32 32 33 # some useful constants 34 STATUS_DELETED, STATUS_CREATED, STATUS_CHANGED = 1,2,4 35 33 36 34 37 class InvenioRecordProcessor(object): 35 38 36 39 @classmethod 37 def _breakDownCategory(cls, categ, chgSet): 40 def _setStatus(cls, chgSet, obj, state): 41 if obj not in chgSet: 42 chgSet[obj] = 0 43 44 chgSet[obj] |= state 45 46 @classmethod 47 def _breakDownCategory(cls, categ, chgSet, state): 38 48 39 49 # categories are never converted to records 40 50 41 51 for conf in categ.getAllConferenceList(): 42 cls._breakDownConference(conf, chgSet )52 cls._breakDownConference(conf, chgSet, state) 43 53 44 54 @classmethod 45 def _breakDownConference(cls, conf, chgSet ):55 def _breakDownConference(cls, conf, chgSet, state): 46 56 47 c hgSet.add(conf)57 cls._setStatus(chgSet, conf, state) 48 58 49 59 for contrib in conf.getContributionList(): 50 cls._breakDownContribution(contrib, chgSet )60 cls._breakDownContribution(contrib, chgSet, state) 51 61 52 62 @classmethod 53 def _breakDownContribution(cls, contrib, chgSet ):63 def _breakDownContribution(cls, contrib, chgSet, state): 54 64 55 c hgSet.add(contrib)65 cls._setStatus(chgSet, contrib, state) 56 66 57 67 for scontrib in contrib.getSubContributionList(): 58 c hgSet.add(scontrib)68 cls._setStatus(chgSet, scontrib, state) 59 69 60 70 @classmethod … … 63 73 64 74 if isinstance(obj, conference.Category): 65 cls._breakDownCategory(obj, chgSet )75 cls._breakDownCategory(obj, chgSet, STATUS_CHANGED) 66 76 elif isinstance(obj, conference.Conference): 67 cls._breakDownConference(obj, chgSet )77 cls._breakDownConference(obj, chgSet, STATUS_CHANGED) 68 78 elif isinstance(obj, conference.Contribution): 69 cls._breakDownContribution(obj, chgSet )79 cls._breakDownContribution(obj, chgSet, STATUS_CHANGED) 70 80 elif isinstance(obj, conference.SubContribution): 71 c hgSet.add(obj)81 cls._setStatus(chgSet, obj, STATUS_CHANGED) 72 82 73 83 @classmethod … … 78 88 """ 79 89 80 deleted = set() 81 changed = set() 82 created = set() 83 protectionChanged = set() 84 90 records = dict() 85 91 result = [] 86 92 87 print 'Computing records...'88 89 93 for ts, aw in data: 90 91 94 obj = aw.getObject() 92 95 93 if obj in deleted: 94 # previously deleted? 95 continue 96 if obj in records: 97 if (records[obj] & STATUS_DELETED): 98 # previously deleted? jump over this one 99 continue 100 else: 101 records[obj] = 0 96 102 97 103 for action in aw.getActions(): … … 100 106 # if the record has been deleted, mark it as such 101 107 # nothing else will matter 102 deleted.add(obj)108 records[obj] |= STATUS_DELETED 103 109 104 110 elif action == 'created': 105 111 # if the record has been created, mark it as such 106 created.add(obj)112 records[obj] |= STATUS_CREATED 107 113 108 114 elif action in ['data_changed', 'acl_changed', 'moved']: 109 115 # categories are ignored 110 if not isinstance(obj, conference.Category): 111 changed.add(obj) 116 records[obj] |= STATUS_CHANGED 112 117 113 118 elif action in ['set_private', 'set_public']: 114 119 # protection changes have to be handled more carefully 115 cls._computeProtectionChanges(obj, action, protectionChanged)120 cls._computeProtectionChanges(obj, action, records) 116 121 117 print 'Computed records: %s created, %s changed, %s protection' % \ 118 (len(created), len(changed), len(protectionChanged)) 119 120 for obj in (created | changed | protectionChanged) - deleted: 121 yield aw._timestamp, obj, 'create' 122 123 for obj in (deleted): 124 yield aw._timestamp, obj, 'delete' 125 126 # TODO: branching to sub objects (i.e. category protection) 122 for record, state in records.iteritems(): 123 yield ts, record, state 127 124 128 125 … … 149 146 xg.openTag("collection",[["xmlns","http://www.loc.gov/MARC21/slim"]]) 150 147 151 di.toMarc(record, overrideCache=True, deleted = (operation == 'delete'))148 di.toMarc(record, overrideCache=True, deleted = (operation & STATUS_DELETED)) 152 149 153 150 xg.closeTag("collection") … … 178 175 self._v_logger.info('Starting metadata/upload cycle') 179 176 for ts, record, operation in crecords: 180 # TODO: check operation 177 178 if isinstance(record, conference.Category): 179 continue 180 181 181 rdata = self._getMetadata(operation, record) 182 182 try:
Note: See TracChangeset
for help on using the changeset viewer.
