def insertDeltas(commit, objectName, type, items, delta_type, el_type, el_subtype = None): for item in items: deployable = getDeployable(commit.branch, objectName, type, el_type, item, el_subtype) delta = Delta() delta.user_change = getLastChange(objectName, el_type, item) delta.object = deployable delta.commit = commit delta.delta_type = delta_type delta.save()
def insertDeltas(commit, objectName, type, items, delta_type, el_type, el_subtype=None): for item in items: deployable = getDeployable(commit.branch, objectName, type, el_type, item, el_subtype) delta = Delta() delta.user_change = getLastChange(objectName, el_type, item) delta.object = deployable delta.commit = commit delta.delta_type = delta_type delta.save()
def analyzeCommit(branch, commit): global documentCache global mapCache global working_branch global change_batch working_branch = branch logger.info("Analyzing commit %s" % commit.hash) documentCache = { } # do not want to accumulate this stuff over multiple iterations mapCache = {} change_batch = None # clean up deltas in case we are rerunning Delta.objects.filter(commit=commit).delete() TranslationDelta.objects.filter(commit=commit).delete() lhash = commit.prev_hash rhash = commit.hash ## # call "git diff" to get a list of changed files ## omap = getDiffNames(lhash, rhash) ## # load all changed files from each hash into a map for performance ## lFileCache = createFileCache(lhash, omap, branch.name) rFileCache = createFileCache(rhash, omap, branch.name) for otype, olist in omap.items(): logger.debug("Type: %s" % otype) if otype == 'objects': analyzeObjectChanges(olist, lFileCache, rFileCache, 'fields', commit) analyzeObjectChanges(olist, lFileCache, rFileCache, 'validationRules', commit) analyzeObjectChanges(olist, lFileCache, rFileCache, 'webLinks', commit) analyzeObjectChanges(olist, lFileCache, rFileCache, 'recordTypes', commit) analyzeRecordTypePicklistChanges(olist, lFileCache, rFileCache, commit) analyzeObjectChanges(olist, lFileCache, rFileCache, 'namedFilters', commit) analyzeObjectChanges(olist, lFileCache, rFileCache, 'listViews', commit) # misc single-node elements # analyzeObjectChanges(list, lFileCache, rFileCache, 'label', commit) # analyzeObjectChanges(list, lFileCache, rFileCache, 'nameField', commit, nameKey='label') # analyzeObjectChanges(list, lFileCache, rFileCache, 'pluralLabel', commit) # analyzeObjectChanges(list, lFileCache, rFileCache, 'searchLayouts', commit) # analyzeObjectChanges(list, lFileCache, rFileCache, 'sharingModel', commit) elif otype == 'translations': analyzeTranslationChanges(olist, lFileCache, rFileCache, commit) elif otype == 'workflows': analyzeWorkflowChanges(olist, lFileCache, rFileCache, 'alerts', commit) analyzeWorkflowChanges(olist, lFileCache, rFileCache, 'fieldUpdates', commit) analyzeWorkflowChanges(olist, lFileCache, rFileCache, 'rules', commit) analyzeWorkflowChanges(olist, lFileCache, rFileCache, 'tasks', commit) elif otype == 'objectTranslations': analyzeObjectTranslationChanges(olist, lFileCache, rFileCache, 'fields', commit) analyzeObjectTranslationChanges(olist, lFileCache, rFileCache, 'validationRules', commit) analyzeObjectTranslationChanges(olist, lFileCache, rFileCache, 'webLinks', commit) elif otype == 'labels': analyzeLabelChanges(olist, lFileCache, rFileCache, 'labels', commit) else: for listitem in olist: delta_type = None if lFileCache.has_key(listitem) and rFileCache.has_key( listitem) == False: delta_type = 'd' elif lFileCache.has_key(listitem) == False: delta_type = 'a' else: delta_type = 'u' delta = Delta() delta.object = getDeployable(branch, listitem, otype, None, None, None) delta.commit = commit delta.user_change = getLastChange(listitem, None, None) if delta.user_change is None: print '** Audit record not found for %s' % listitem else: #print 'audit record found!' pass delta.delta_type = delta_type delta.save() commit.status = 'c' commit.save()
def analyzeCommit(branch, commit): global documentCache global mapCache global working_branch global change_batch working_branch = branch logger.info("Analyzing commit %s" % commit.hash) documentCache = {} # do not want to accumulate this stuff over multiple iterations mapCache = {} change_batch = None # clean up deltas in case we are rerunning Delta.objects.filter(commit=commit).delete() TranslationDelta.objects.filter(commit=commit).delete() lhash = commit.prev_hash rhash = commit.hash ## # call "git diff" to get a list of changed files ## omap = getDiffNames(lhash, rhash) ## # load all changed files from each hash into a map for performance ## lFileCache = createFileCache(lhash, omap, branch.name) rFileCache = createFileCache(rhash, omap, branch.name) for otype,olist in omap.items(): logger.debug("Type: %s" % otype) if otype == 'objects': analyzeObjectChanges(olist, lFileCache, rFileCache, 'fields', commit) analyzeObjectChanges(olist, lFileCache, rFileCache, 'validationRules', commit) analyzeObjectChanges(olist, lFileCache, rFileCache, 'webLinks', commit) analyzeObjectChanges(olist, lFileCache, rFileCache, 'recordTypes', commit) analyzeRecordTypePicklistChanges(olist, lFileCache, rFileCache, commit) analyzeObjectChanges(olist, lFileCache, rFileCache, 'namedFilters', commit) analyzeObjectChanges(olist, lFileCache, rFileCache, 'listViews', commit) # misc single-node elements # analyzeObjectChanges(list, lFileCache, rFileCache, 'label', commit) # analyzeObjectChanges(list, lFileCache, rFileCache, 'nameField', commit, nameKey='label') # analyzeObjectChanges(list, lFileCache, rFileCache, 'pluralLabel', commit) # analyzeObjectChanges(list, lFileCache, rFileCache, 'searchLayouts', commit) # analyzeObjectChanges(list, lFileCache, rFileCache, 'sharingModel', commit) elif otype == 'translations': analyzeTranslationChanges(olist, lFileCache, rFileCache, commit) elif otype == 'workflows': analyzeWorkflowChanges(olist, lFileCache, rFileCache, 'alerts', commit) analyzeWorkflowChanges(olist, lFileCache, rFileCache, 'fieldUpdates', commit) analyzeWorkflowChanges(olist, lFileCache, rFileCache, 'rules', commit) analyzeWorkflowChanges(olist, lFileCache, rFileCache, 'tasks', commit) elif otype == 'objectTranslations': analyzeObjectTranslationChanges(olist, lFileCache, rFileCache, 'fields', commit) analyzeObjectTranslationChanges(olist, lFileCache, rFileCache, 'validationRules', commit) analyzeObjectTranslationChanges(olist, lFileCache, rFileCache, 'webLinks', commit) elif otype == 'labels': analyzeLabelChanges(olist, lFileCache, rFileCache, 'labels', commit) else: for listitem in olist: delta_type = None if lFileCache.has_key(listitem) and rFileCache.has_key(listitem) == False: delta_type = 'd' elif lFileCache.has_key(listitem) == False: delta_type = 'a' else: delta_type = 'u' delta = Delta() delta.object = getDeployable(branch, listitem, otype, None, None, None) delta.commit = commit delta.user_change = getLastChange(listitem, None, None) if delta.user_change is None: print '** Audit record not found for %s' % listitem else: #print 'audit record found!' pass delta.delta_type = delta_type delta.save() commit.status = 'c' commit.save()
def test_large_diff(self): map = difflist() ## # load all changed files from each hash into a map for performance ## lFileCache = createFileCache('sfdiff/testfiles/ltest', map) rFileCache = createFileCache('sfdiff/testfiles/rtest', map) repo = Repo() repo.location = '/tmp' repo.save() branch = Branch() branch.name = 'test' branch.repo = repo branch.save() rel = Release() rel.isdefault = True rel.name = 'test' rel.branch = branch rel.save() commit = Commit() commit.branch = branch commit.hash = 'test' commit.status = 'p' commit.save() for type,list in map.items(): if type == 'objects': analyzeObjectChanges(list, lFileCache, rFileCache, 'fields', commit) analyzeObjectChanges(list, lFileCache, rFileCache, 'validationRules', commit) analyzeObjectChanges(list, lFileCache, rFileCache, 'webLinks', commit) analyzeRecordTypeChanges(list, lFileCache, rFileCache, commit) analyzeObjectChanges(list, lFileCache, rFileCache, 'namedFilters', commit) elif type == 'translations': analyzeTranslationChanges(list, lFileCache, rFileCache, commit) elif type == 'labels': analyzeLabelChanges(list, lFileCache, rFileCache, 'labels', commit) else: for listitem in list: delta_type = None if lFileCache.has_key(listitem) and rFileCache.has_key(listitem) == False: delta_type = 'd' elif lFileCache.has_key(listitem) == False: delta_type = 'a' else: delta_type = 'u' delta = Delta() delta.object = getDeployable(branch, listitem, type, None, None, None) delta.commit = commit delta.delta_type = delta_type delta.save() output = file('/tmp/deltas.json', 'w') output.write(serializers.serialize('json', Delta.objects.all(), indent=2)) output.close() output = file('/tmp/deployables.json', 'w') output.write(serializers.serialize('json', DeployableObject.objects.all(), indent=2)) output.close() self.assertTrue(filecmp.cmp('/tmp/deltas.json', 'sfdiff/testfiles/results/deltas.json', False), 'delta mismatch') self.assertTrue(filecmp.cmp('/tmp/deployables.json', 'sfdiff/testfiles/results/deployables.json', False), 'deployable mismatch')