diff options
author | Aamir Khan <syst3m.w0rm@gmail.com> | 2012-06-24 23:41:04 -0400 |
---|---|---|
committer | Aamir Khan <syst3m.w0rm@gmail.com> | 2012-06-24 23:41:04 -0400 |
commit | fe908c14aa9816eea5846279f647a6ea22fc482a (patch) | |
tree | 07104a7de0a7b3e9cbbdfd23113a7a6dd7a4295e | |
parent | 826968df9c21f815cfc4a71dc7104c14e543e9e6 (diff) | |
download | hyperkitty-fe908c14aa9816eea5846279f647a6ea22fc482a.tar.gz hyperkitty-fe908c14aa9816eea5846279f647a6ea22fc482a.tar.xz hyperkitty-fe908c14aa9816eea5846279f647a6ea22fc482a.zip |
Removed unnecessary code : lib/
-rw-r--r-- | lib/__init__.py | 14 | ||||
-rw-r--r-- | lib/mockup.py | 167 | ||||
-rw-r--r-- | lib/mongo.py | 199 |
3 files changed, 0 insertions, 380 deletions
diff --git a/lib/__init__.py b/lib/__init__.py deleted file mode 100644 index aa5a3d9..0000000 --- a/lib/__init__.py +++ /dev/null @@ -1,14 +0,0 @@ -#-*- coding: utf-8 -*- - -from hashlib import md5 -import urllib - - -def gravatar_url(email): - '''Return a gravatar url for an email address''' - size = 64 - default = "http://fedoraproject.org/static/images/" + \ - "fedora_infinity_%ix%i.png" % (size, size) - query_string = urllib.urlencode({'s': size, 'd': default}) - identifier = md5(email).hexdigest() - return 'http://www.gravatar.com/avatar/%s?%s' % (identifier, query_string) diff --git a/lib/mockup.py b/lib/mockup.py deleted file mode 100644 index 6dfe298..0000000 --- a/lib/mockup.py +++ /dev/null @@ -1,167 +0,0 @@ -#-*- coding: utf-8 -*- - - -class Email(object): - """ Email class containing the information needed to store and - display email threads. - """ - - def __init__(self): - """ Constructor. - Instanciate the default attributes of the object. - """ - self.email_id = '' - self.title = '' - self.body = '' - self.tags = [] - self.category = 'question' - self.category_tag = None - self.participants = set(['Pierre-Yves Chibon']) - self.answers = [] - self.liked = 0 - self.author = '' - self.avatar = None - -class Author(object): - """ Author class containing the information needed to get the top - author of the month! - """ - - def __init__(self): - """ Constructor. - Instanciate the default attributes of the object. - """ - self.name = None - self.kudos = 0 - self.avatar = None - - -def get_email_tag(tag): - threads = generate_random_thread() - output = [] - for email in threads: - if tag in email.tags or tag in email.category: - output.append(email) - elif email.category_tag and tag in email.category_tag: - output.append(email) - return output - - -def generate_thread_per_category(): - threads = generate_random_thread() - categories = {} - for thread in threads: - category = thread.category - if thread.category_tag: - category = thread.category_tag - if category in categories.keys(): - categories[category].append(thread) - else: - categories[category] = [thread] - return categories - -def generate_top_author(): - authors = [] - - author = Author() - author.name = 'Pierre-Yves Chibon' - author.avatar = 'https://secure.gravatar.com/avatar/072b4416fbfad867a44bc7a5be5eddb9' - author.kudos = 3 - authors.append(author) - - author = Author() - author.name = 'Stanislav Ochotnický' - author.avatar = 'http://sochotni.fedorapeople.org/sochotni.jpg' - author.kudos = 4 - authors.append(author) - - author = Author() - author.name = 'Toshio Kuratomi' - author.avatar = 'https://secure.gravatar.com/avatar/7a9c1d88f484c9806bceca0d6d91e948' - author.kudos = 5 - authors.append(author) - - return authors - -def generate_random_thread(): - threads = [] - - ## 1 - email = Email() - email.email_id = 1 - email.title = 'Headsup! krb5 ccache defaults are changing in Rawhide' - email.age = '6 days' - email.body = '''Dear fellow developers, -with the upcoming Fedora 18 release (currently Rawhide) we are going to change the place where krb5 credential cache files are saved by default. - -The new default for credential caches will be the /run/user/username directory. -''' - email.tags.extend(['rawhide', 'krb5']) - email.participants = set(['Stephen Gallagher', 'Toshio Kuratomi', 'Kevin Fenzi', 'Seth Vidal']) - email.answers.extend([1,2,3,4,5,6,7,8,9,10,11,12]) - email.liked = 1 - email.author = 'Stephen Gallagher' - email.avatar = 'http://fedorapeople.org/~sgallagh/karrde712.png' - threads.append(email) - - ## 2 - email = Email() - email.email_id = 2 - email.title = 'Problem in packaging kicad' - email.age = '6 days' - email.body = '''Paragraph 1: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ''' - email.tags.extend(['packaging', 'kicad']) - email.participants = set(['Pierre-Yves Chibon', 'Tom "spot" Callaway', 'Toshio Kuratomi', 'Kevin Fenzi']) - email.answers.extend([1,2,3,4,5,6,7,8,9,10,11,12]) - email.liked = 0 - email.author = 'Pierre-Yves Chibon' - email.avatar = 'https://secure.gravatar.com/avatar/072b4416fbfad867a44bc7a5be5eddb9' - threads.append(email) - - ## 3 - email = Email() - email.email_id = 3 - email.title = 'Update Java Guideline' - email.age = '6 days' - email.body = '''Paragraph 1: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ''' - email.tags.extend(['rawhide', 'krb5']) - email.participants = set(['Stanislav Ochotnický', 'Tom "spot" Callaway', 'Stephen Gallagher', 'Jason Tibbitts', 'Rex Dieter', 'Toshio Kuratomi']) - email.answers.extend([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]) - email.liked = 5 - email.category = 'todo' - email.author = 'Stanislav Ochotnický' - email.avatar = 'http://sochotni.fedorapeople.org/sochotni.jpg' - threads.append(email) - - ## 4 - email = Email() - email.email_id = 4 - email.title = 'Agenda for the next Board Meeting' - email.age = '6 days' - email.body = '''Paragraph 1: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ''' - email.tags.extend(['agenda', 'board']) - email.participants = set(['Toshio Kuratomi', 'Tom "spot" Callaway', 'Robyn Bergeron', 'Max Spevack']) - email.answers.extend([1,2,3,4,5,6,7,8,9,10,11,12]) - email.liked = 20 - email.category = 'agenda' - email.author = 'Toshio Kuratomi' - email.avatar = 'https://secure.gravatar.com/avatar/7a9c1d88f484c9806bceca0d6d91e948' - threads.append(email) - - ## 5 - email = Email() - email.email_id = 5 - email.title = 'I told you so! ' - email.age = '6 days' - email.body = '''Paragraph 1: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ''' - email.tags.extend(['systemd', 'mp3', 'pulseaudio']) - email.participants = set(['Pierre-Yves Chibon']) - email.answers.extend([1,2,3,4,5,6,7,8,9,10,11,12]) - email.liked = 0 - email.author = 'Pierre-Yves Chibon' - email.avatar = 'https://secure.gravatar.com/avatar/072b4416fbfad867a44bc7a5be5eddb9' - email.category = 'shut down' - email.category_tag = 'dead' - threads.append(email) - - return threads diff --git a/lib/mongo.py b/lib/mongo.py deleted file mode 100644 index 028b4d6..0000000 --- a/lib/mongo.py +++ /dev/null @@ -1,199 +0,0 @@ -#-*- coding: utf-8 -*- - -import pymongo -import re -from bunch import Bunch -from datetime import datetime - -connection = pymongo.Connection('localhost', 27017) - - -def _build_thread(emails): - thread = {} - for email in emails: - #print email['Date'], email['From'] , email['MessageID'] - email = Bunch(email) - ref = [] - if 'References' in email: - refs = email['References'].split()[-1:] - refs = [item.replace('<', '').replace('>', '') for item in refs] - ref.extend(refs) - elif 'InReplyTo' in email: - rep = email['InReplyTo'].replace('<', '').replace('>', '') - ref.append(rep) - - if email['MessageID'] not in thread: - thread[email['MessageID']] = Bunch( - {'email': email, 'child': []}) - else: - thread[email['MessageID']].email = email - - for ref in set(ref): - if ref in thread: - thread[ref].child.append(email['MessageID']) - else: - thread[ref] = Bunch( - {'email': None, 'child': [email['MessageID']]}) - return thread - - -def _tree_to_list(tree, mailid, level, thread_list): - start = tree[mailid] - #print start.email.From, start.email.Date, start.child - start.level = level - thread_list.append(start) - for mail in start.child: - mail = tree[mail] - thread_list = _tree_to_list(tree, mail.email['MessageID'], - level + 1, thread_list) - return thread_list - - -def get_thread_list(table, threadid): - db = connection[table] - db.mails.create_index('ThreadID') - db.mails.ensure_index('ThreadID') - db.mails.create_index('References') - db.mails.ensure_index('References') - db.mails.create_index('InReplyTo') - db.mails.ensure_index('InReplyTo') - - thread = list(db.mails.find({'ThreadID': threadid})) - start = db.mails.find_one({'ThreadID': threadid, - 'References': {'$exists':False}, - 'InReplyTo': {'$exists':False}}) - - tree = _build_thread(thread) - thread_list = [] - if thread: - thread = _tree_to_list(tree, start['MessageID'], 0, thread_list) - return thread - else: - return [] - - -def get_thread_name(table, threadid): - db = connection[table] - db.mails.create_index('ThreadID') - db.mails.ensure_index('ThreadID') - thread = list(db.mails.find({'ThreadID': int(threadid)}, - sort=[('Date', pymongo.ASCENDING)])) - if thread: - return thread[0]['Subject'] - else: - return '' - - -def get_email(table, emailid): - db = connection[table] - db.mails.create_index('MessageID') - db.mails.ensure_index('MessageID') - return db.mails.find_one({'MessageID': emailid}) - - -def get_emails_thread(table, start_email, thread): - db = connection[table] - db.mails.create_index('Date') - db.mails.ensure_index('Date') - db.mails.create_index('InReplyTo') - db.mails.ensure_index('InReplyTo') - db.mails.create_index('MessageID') - db.mails.ensure_index('MessageID') - regex = '.*%s.*' % start_email['MessageID'] - for el in db.mails.find({'References': re.compile(regex, re.IGNORECASE)}, - sort=[('Date', pymongo.DESCENDING)]): - thread.append(el) - get_emails_thread(el, thread) - return thread - - -def get_archives(table, start, end): - db = connection[table] - db.mails.create_index('Date') - db.mails.ensure_index('Date') - db.mails.create_index('References') - db.mails.ensure_index('References') - # Beginning of thread == No 'References' header - archives = [] - for el in db.mails.find( - {'References': {'$exists':False}, - 'InReplyTo': {'$exists':False}, - "Date": {"$gt": start, "$lt": end}}, - sort=[('Date', pymongo.DESCENDING)]): - archives.append(el) - return archives - - -def get_thread(table, start, end): - db = connection[table] - db.mails.create_index('Date') - db.mails.ensure_index('Date') - db.mails.create_index('References') - db.mails.ensure_index('References') - # Beginning of thread == No 'References' header - archives = Bunch() - for el in db.mails.find({'References': {'$exists':False}, - "Date": {"$gte": start, "$lt": end}}, - sort=[('Date', pymongo.DESCENDING)]): - thread = get_emails_thread(el, [el]) - #print el['Subject'], len(thread) - archives[el['Subject']] = thread - return archives - - -def get_thread_length(table, thread_id): - db = connection[table] - db.mails.create_index('ThreadID') - db.mails.ensure_index('ThreadID') - return db.mails.find({'ThreadID': thread_id}).count() - - -def get_thread_participants(table, thread_id): - db = connection[table] - db.mails.create_index('ThreadID') - db.mails.ensure_index('ThreadID') - authors = set() - for mail in db.mails.find({'ThreadID': thread_id}): - authors.add(mail['From']) - return len(authors) - - -def get_archives_length(table): - db = connection[table] - db.mails.create_index('Date') - db.mails.ensure_index('Date') - archives = {} - entry = db.mails.find_one(sort=[('Date', pymongo.ASCENDING)]) - date = entry['Date'] - now = datetime.now() - year = date.year - month = date.month - while year < now.year: - archives[year] = range(1,13)[(month -1):] - year = year + 1 - month = 1 - archives[now.year] = range(1,13)[:now.month] - return archives - - -def search_archives(table, query, limit=None): - db = connection[table] - db.mails.create_index('Date') - db.mails.ensure_index('Date') - for el in query: - db.mails.create_index(str(el)) - db.mails.ensure_index(str(el)) - output = [] - if limit: - try: - limit = int(limit) - except ValueError: - limit = None - if limit: - output = list(db.mails.find(query, sort=[('Date', - pymongo.DESCENDING)]).limit(limit)) - else: - output = list(db.mails.find(query, sort=[('Date', - pymongo.DESCENDING)])) - return output - |