diff options
author | Nico von Geyso <Nico.Geyso@FU-Berlin.de> | 2012-05-14 11:52:42 +0200 |
---|---|---|
committer | Nico von Geyso <Nico.Geyso@FU-Berlin.de> | 2012-05-14 11:52:42 +0200 |
commit | 0a2ed52efaf75405928644b04093f34dc5fff9d8 (patch) | |
tree | 151adc2d088adebe5d4c8d4935c70ca813d30623 /fit.py | |
parent | 84424f7955c0108b6e69b893a427fb1136ff3728 (diff) | |
download | klausuren-0a2ed52efaf75405928644b04093f34dc5fff9d8.tar.gz klausuren-0a2ed52efaf75405928644b04093f34dc5fff9d8.tar.bz2 klausuren-0a2ed52efaf75405928644b04093f34dc5fff9d8.zip |
search rewritten and refactoring
* search result are only files which are in all search tags
* javascript refactoring
Diffstat (limited to 'fit.py')
-rw-r--r-- | fit.py | 34 |
1 files changed, 24 insertions, 10 deletions
@@ -1,4 +1,5 @@ import os, time +import collections from pygit2 import Repository, Signature from binascii import b2a_hex @@ -127,22 +128,35 @@ class Fit: def get_files_for_tags(self, tags): try: commit = self._get_last_commit() - tree = commit.tree['tags'].to_object() - entries = [ tree[x.encode('ascii')].to_object() for x in tags] - add = lambda x,y: x+y - return reduce(add, - map(lambda entry: [ (x.name, x.hex) for x in entry ],entries) - ) + root = commit.tree['tags'].to_object() + + def get_obj(x): + try: + return root[x.encode('ascii')].to_object() + except KeyError: + return [] + + entries = [get_obj(x) for x in tags] + + def merge(list_to_merge): + for sublist in list_to_merge: + for elem in sublist: + yield elem + + # return only entries which have all tags + search = collections.Counter([(x.name, x.hex) for x in merge(entries)]) + return [i for i in search if search[i]>=len(tags)] + except: return [] - def get_file_with_tags(self, oid): + def get_tags_for_file(self, oid): tags = [] - for name, tag_oid in fit.get_all_tags(): + for name, tag_oid in self.get_all_tags(): for entry in self.repo[tag_oid]: - if entry.oid == oid: - tags.append((name, tag_oid)) + if b2a_hex(entry.oid).decode('ascii') == oid: + tags.append(name) return tags |