Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge all changes from the forked repository #5

Merged
merged 7 commits into from
Apr 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ db
*.log
*.pot
*.pyc
*.swp
local_settings.py
/.idea
23 changes: 23 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright (c) 2014, BRL-CAD
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Originally forked from [here](http://bitbucket.org/suryajith/benchmark/)

## Screenshots

![Hi There](http://i.imgur.com/BDKsKVJ.png "Result of a Benchmark Run")
![Hi There](http://i.imgur.com/zmhV8Sk.png "Result of a Benchmark Run")

Result of a Benchmark Run

Expand Down
17 changes: 17 additions & 0 deletions deploy/after_push
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -e
oldrev=$1
newrev=$2

run() {
[ -x $1 ] && $1 $oldrev $newrev
}

echo files changed: $(git diff $oldrev $newrev --diff-filter=ACDMR --name-only | wc -l)

umask 002

git submodule sync && git submodule update --init --recursive

run deploy/before_restart
run deploy/restart && run deploy/after_restart
10 changes: 10 additions & 0 deletions deploy/before_restart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
mkdir -p media/benchmarkLogs
mkdir -p log
touch log/benchmark.log
chmod a+w -R media/benchmarkLogs
chmod a+w log/benchmark.log
virtualenv env
source env/bin/activate
pip install -r requirements.txt
rm -rf bin/ lib/ build/ dist/ *.egg-info/ include/ local/
4 changes: 4 additions & 0 deletions deploy/restart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
source env/bin/activate
python manage.py collectstatic --clear --noinput
touch wsgi.py # trigger reload
30 changes: 15 additions & 15 deletions libs/imaputils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
###
#
# This contains the utility functions needed to access the IMAP
#
# This contains the utility functions needed to access the IMAP
# server.

__author__ = 'Suryajith Chillara'
Expand All @@ -47,19 +47,19 @@

def get_imapserv_conn():
"""
Return the connection to an imap server and
Return the connection to an imap server and
choose the default mailbox as INBOX.
"""
config = ConfigParser()
config.read(['../config'])
config.read(['../project_config'])

imap_server = imaplib.IMAP4_SSL(config.get("imap_credentials", "imap_server"),
config.get("imap_credentials", "imap_port"))
imap_server.login(config.get("imap_credentials", 'username'),
imap_server.login(config.get("imap_credentials", 'username'),
config.get("imap_credentials", 'password'))

imap_server.select('INBOX')

return imap_server


Expand All @@ -68,28 +68,28 @@ def get_attachment(imap_server, email_id):
"""
Get attachments and return as a dictionary.
"""

attachments = {}
msg, data = imap_server.fetch(email_id, "(RFC822)")
# Convert the message
email_body = email.message_from_string(data[0][1])

# Walk through the sections of the code
for section in email_body.walk() :
if section.get_content_maintype() == 'multipart':
continue
if section.get('Content-Disposition') is None:
continue

# Get the filename of the attachment
filename = section.get_filename()

# Get the content of the attachment
content = section.get_payload(decode=True)

attachments[filename] = content


return attachments

# Local Variables:
Expand All @@ -98,4 +98,4 @@ def get_attachment(imap_server, email_id):
# python-indent-offset: 4
# indent-tabs-mode: t
# End:
# ex: shiftwidth=4 tabstop=8
# ex: shiftwidth=4 tabstop=8
30 changes: 15 additions & 15 deletions scripts/benchmark_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,45 +44,45 @@
from ConfigParser import ConfigParser

def main() :

if len(sys.argv) == 2 :
filename = sys.argv[1]

config = ConfigParser()
config.read(['../config'])
config.read(['../project_config'])

url = config.get("locations", "api_url")

content = open(filename, 'r').read()
filename_clean = filename.split('/')[-1]

values = {'action' : 'benchmark',
'filename' : filename_clean,
'content' : content,
'format' : 'xml',
}

data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
print response.read()


else :
print "Usage: python benchmark_upload.py <relative-path-to-file>"
sys.exit(1)




if __name__ == '__main__':

main()

# Local Variables:
# mode: python
# tab-width: 8
# python-indent-offset: 4
# indent-tabs-mode: t
# End:
# ex: shiftwidth=4 tabstop=8
# ex: shiftwidth=4 tabstop=8
76 changes: 38 additions & 38 deletions scripts/email_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

import libs.util as util
import libs.dbutils as dbutils
import libs.imaputils as imaputils
import libs.imaputils as imaputils
from libs.bp_logger import bp_logger


Expand All @@ -61,9 +61,9 @@ def is_email_logged(db_conn, email_id):
query = """
SELECT * from email_logs where imap_id = {:d}
""".format(int(email_id))

result = dbutils.db_select(db_conn, query)

if len(result) == 0 :
return False
else :
Expand All @@ -76,41 +76,41 @@ def is_content_same(imap_server, email_id):
"""
Check if the content is the same on the disk and the mail.
"""

config = ConfigParser()
config.read(['../config'])
config.read(['../project_config'])

attachments = imaputils.get_attachment(imap_server, email_id)
for filename, content in attachments.items() :

for filename, content in attachments.items() :


if re.search("run-[0-9]+-benchmark.log", filename) == None :
continue


filelocation_archive = os.path.join(os.path.dirname('__FILE__'), '../',
config.get("locations", "archives"), filename)
filelocation_queue = os.path.join(os.path.dirname('__FILE__'), '../',
config.get("locations", "queue"), filename)


md5 = hashlib.md5()
md5.update(content)
md5_hash = md5.hexdigest()
filelocation_archive = filelocation_archive + '.' + md5_hash
filelocation_queue = filelocation_queue + '.' + md5_hash
#
filelocation_queue = filelocation_queue + '.' + md5_hash


#
if util.check_if_file_exists_on_disk(filelocation_archive) :
if util.md5_for_file(open(filelocation_archive, 'r')) == md5_hash :
if util.md5_for_file(open(filelocation_archive, 'r')) == md5_hash :
return True
else :
os.remove(filelocation_archive)
return False
elif util.check_if_file_exists_on_disk(filelocation_queue) :
if util.md5_for_file(open(filelocation_queue, 'r')) == md5_hash :
if util.md5_for_file(open(filelocation_queue, 'r')) == md5_hash :
return True
else :
os.remove(filelocation_queue)
Expand All @@ -125,17 +125,17 @@ def verify_email(imap_server, db_conn, email_id):
"""
return is_email_logged(db_conn, email_id) and is_content_same(imap_server, email_id)


def main():
"""
MAIN
"""

logger = bp_logger('EMAIL_VERIFIER')

imap_server = imaputils.get_imapserv_conn()
db_conn = dbutils.get_connection()

query = """
SELECT MAX(`verified_till`) FROM email_verification_logs
"""
Expand All @@ -144,46 +144,46 @@ def main():
start = 0
else :
start = int(result[0][0])

end = start


msg, emails = imap_server.search(None, "SEEN")

for email_id in emails[0].split() :

if email_id <= start :
continue


# TODO: Make this operation occur as batchwise processing
if verify_email(imap_server, db_conn, email_id) :
logger.info("Everything seems alright.")
else :
logger.info("Marking {:d} as unread".format(int(email_id)))
imap_server.store(int(email_id), '-FLAGS', '\SEEN')

if int(email_id) > end :
end = int(email_id)

# Make an entry only if there was something to be checked.
if end > start :

query = """
INSERT INTO email_verification_logs (verified_till, time)
VALUES ({:d}, NOW())
""".format(int(end))

dbutils.db_insert(db_conn, query)


if __name__ == '__main__' :
main()

# Local Variables:
# mode: python
# tab-width: 8
# python-indent-offset: 4
# indent-tabs-mode: t
# End:
# ex: shiftwidth=4 tabstop=8
# ex: shiftwidth=4 tabstop=8
Loading