Skip to content
Open
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
2 changes: 1 addition & 1 deletion LICENSE-MIT.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014 Sartaj Singh, Sumit Sahrawat
Copyright (c) 2015 Sartaj Singh, Sumit Sahrawat, Govind Sahai

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand Down
10 changes: 0 additions & 10 deletions rollcall/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
#!/usr/bin/env python2

##
# rollcall
# https://github.com/numerals/rollcall.git
#
# Copyright (c) 2014 Sartaj Singh, Sumit Sahrawat
# Licensed under the MIT license.
##

2 changes: 1 addition & 1 deletion rollcall/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def total_classes(json_dic, field=None):
def classes_with_tag(json_dic, tag=fj.TAGS['p']):
"""
takes in a json dictionary
returns list of all the classes
returns list of all the classes
with the tag
"""
classes = []
Expand Down
8 changes: 7 additions & 1 deletion rollcall/exce.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class NoField(Exception):

class UnknownTag(Exception):
"""
Raised when tag is not recognised
Raised when tag is not recognised
"""
pass

class DatabaseError(Exception):
"""
Raised when there is some problem with DB
"""
pass
6 changes: 3 additions & 3 deletions rollcall/func_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def update_status(json_dic, field, val):
if no such field raises NoField exception
"""
if not json_dic.has_key(field):
raise exce.NoField("No such field: %s" %(field))
raise exce.NoField("No such Field : %s" %(field))
json_dic[field] = val
return json_dic[field]

Expand All @@ -63,7 +63,7 @@ def gen_dict(semester_start, class_weekdays, semester_weeks=16):

json_dict = {}
for d in class_dates:
json_dict[format_date(d)] = "future"
json_dict[format_date(d)] = TAGS['f']

return json_dict

Expand All @@ -77,7 +77,7 @@ def update_json_dict(json_dic, date, status):
formatted_date = format_date(date)

if not json_dic.has_key(formatted_date):
raise exce.NoField("No Field: %s" %(date))
raise exce.NoField("No such Date : %s" %(date))

json_dic[formatted_date] = status
return json_dic
File renamed without changes.
65 changes: 65 additions & 0 deletions rollcall/gui/rollcallGUIClass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python2

"""
Contains the main GUI Class
"""

import os
import gtk


def find_file(dire, fName):
"""
Generates the complete path of a file
returns the complete path
"""
path = os.path.join(os.path.dirname(dire), fName)
return path


def load_interface(dire, fName):
"""
Loads the interface
in particular loads the glade file
returns the builder
"""
fName = find_file(dire, fName)
builder = gtk.Builder()
builder.add_from_file(fName)
return builder


class rollcallGUIClass:
"""
Sets up the GUI interface
"""
def __init__(self):

self.builder = load_interface(__file__, 'glade/rollcallGUI.glade')
self.save_objects()
self.builder.connect_signals(self.setup_signals())
self.window.show_all()

def setup_signals(self):
"""
Sets up the signals
"""
sig = {}

return sig

def save_objects(self):
"""
Get the required objects
"""
pass

def close(self, *args):
"""
Handles Destroy Event
"""
gtk.main_quit()


if __name__ == '__main__':
gtk.main()
21 changes: 6 additions & 15 deletions rollcall/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_json_file(sub):
returns json as a dictionary
"""
if not fileExists(sub):
raise exce.SubjectError("Subject: %s does not exit" %(sub))
raise exce.SubjectError("Subject: %s does not exist" %(sub))

with open(sub, "r") as recordFile:
json_string = recordFile.read()
Expand Down Expand Up @@ -109,22 +109,13 @@ def gen_percent(tag=fj.TAGS['p'], ext='.json', dire=pDir()):
percent = display.percent(json_dic, tag)
yield filename, percent

def fileDelete(fName):
def deleteSubject(fName):
"""
Delete a file and return status
Delete a file and raises SubjectError if not Found
"""
if fileExists(fName):
os.remove(fName)
return True
return False

def delete(sub):
"""
Delete a subject
"""
if fileDelete(sub):
return True
return False
if not fileExists(fName):
raise exce.SubjectError("Subject: %s is not Found" %(fName))
os.remove(fName)

def reset(ext='.json', dire=pDir()):
"""
Expand Down
1 change: 1 addition & 0 deletions rollcall/sql/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

192 changes: 192 additions & 0 deletions rollcall/sql/rollcallSQLClass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
#!/usr/bin/env python2
#ref : http://zetcode.com/db/sqlitepythontutorial/

"""
SQL Class rollcall
"""

from __future__ import print_function
import os
import sys
import rollcall.exce as exce
from rollcall.func_json import TAGS
from rollcall.main import pDir, full_path_to

try:
import sqlite3 as sql
except ImportError:
print("SQLite3 is not found!")
sys.exit()

dbNameDef = 'rollcall.db'
dbPathDef = full_path_to(dbNameDef)

def connect_db(dbPath = dbPathDef):
"""
Connect to DB
and Return the sqlite3.Connection object
"""
try:
conn = sql.connect(dbPath)
except:
raise exce.DatabaseError("Unable to open Database File!")
return conn

def close_db_connection(conn):
"""
close the connection 'conn'
where conn is sqlite3.Connection object
"""
conn.close()

def get_subjects(dbPath = dbPathDef):
"""
Get a List of All Subjects Present in DB
yield subject
"""
conn = connect_db(dbPath)
command = "SELECT name FROM sqlite_master WHERE type='table'"
try:
subQuery = conn.execute(command)
subList = subQuery.fetchall()
except:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be explicit here. Which exceptions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OperationError I guess

conn.rollback()
close_db_connection(conn)
raise exce.DatabaseError("Some problem occurred in DB!")
close_db_connection(conn)
for sub in subList:
yield sub[0]

def get_count_subject_tag(subName, tag = 'p', dbPath = dbPathDef):
"""
Get the number of classes in Subject with tag
"""

if not TAGS.has_key(tag):
raise exce.UnknownTag("Tag: %s UNKNOWN" %(tag))

if not subName in get_subjects(dbPath):
raise exce.SubjectError("There is no records for %s." %(subName))

conn = connect_db(dbPath)
command = """SELECT COUNT(*) FROM %s
WHERE class_tag=\"%s\"""" % (subName, TAGS[tag])
try:
count = conn.execute(command)
count = count.fetchall()
except:
conn.rollback()
close_db_connection(conn)
raise exce.DatabaseError("Some problem occurred in DB!")
close_db_connection(conn)
return count[0][0]

def get_total_class_subject(subName, dbPath = dbPathDef):
"""
Get the total classes happened till date
"""

if not subName in get_subjects(dbPath):
raise exce.SubjectError("There is no records for %s." %(subName))

conn = connect_db(dbPath)
command = """SELECT COUNT(*) FROM %s""" % (subName)
try:
count = conn.execute(command)
count = count.fetchall()
except:
conn.rollback()
close_db_connection(conn)
raise exce.DatabaseError("Some problem occurred in DB!")
close_db_connection(conn)
return count[0][0]

#Todo : Add tests
def add_subject(subName, dbPath = dbPathDef):
"""
Add a Subject to the DB
"""

if subName in get_subjects(dbPath):
raise exce.SubjectExists("Records for %s are already present." %(subName))

conn = connect_db(dbPath)
cur = conn.cursor()
command = """CREATE TABLE %s
(
class_no INTEGER NOT NULL,
class_tag VARCHAR(10) NOT NULL
CONSTRAINT chk_tag CHECK (class_tag IN ("absent",
"present", "future", "holiday", "other")),
class_date DATETIME NOT NULL DEFAULT(DATETIME('now', 'localtime')),
PRIMARY KEY (class_no)
)""" % subName
try:
cur.execute(command)
conn.commit()
except:
conn.rollback()
close_db_connection(conn)
raise exce.DatabaseError("Some problem occurred in DB!")
close_db_connection(conn)

#Todo : add tests
def delete_subject(subName, dbPath = dbPathDef):
"""
Delete a Subject if Made by mistake :)
"""

if not subName in get_subjects(dbPath):
raise exce.SubjectError("There is no records for %s." %(subName))

conn = connect_db(dbPath)
cur = conn.cursor()
command = """DROP TABLE %s""" % subName
try:
cur.execute(command)
conn.commit()
except:
conn.rollback()
close_db_connection(conn)
raise exce.DatabaseError("Some problem occurred in DB!")
close_db_connection(conn)

def update_subject(subName, tag = 'p', dbPath = dbPathDef):
"""
Update Subject with Tag
"""

if not TAGS.has_key(tag):
raise exce.UnknownTag("Tag: %s UNKNOWN" %(tag))

if not subName in get_subjects(dbPath):
raise exce.SubjectError("There is no records for %s." %(subName))

conn = connect_db(dbPath)
cur = conn.cursor()
command = """INSERT INTO %s (class_tag)
VALUES (\"%s\")""" %(subName, TAGS[tag])
try:
cur.execute(command)
conn.commit()
except:
conn.rollback()
close_db_connection(conn)
raise exce.DatabaseError("Some problem occurred in DB!")
close_db_connection(conn)

def get_subject_tag_percent(subName, tag = 'p', dbPath = dbPathDef):
"""
Get Percent of tag in subName in total Records till Date
"""

if not TAGS.has_key(tag):
raise exce.UnknownTag("Tag: %s UNKNOWN" %(tag))

if not subName in get_subjects(dbPath):
raise exce.SubjectError("There is no records for %s." %(subName))

count_tag = get_count_subject_tag(subName, tag, dbPath)
count_total = get_total_class_subject(subName, dbPath)
fract = count_tag * 1.0 / count_total
return fract*100
Empty file added rollcall/sql/tests/__init__.py
Empty file.
29 changes: 29 additions & 0 deletions rollcall/sql/tests/helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python2

"""
Helper Module for SQL Tests
"""

import os
from os.path import realpath, dirname
import sys

import rollcall.sql.rollcallSQLClass as rcsql

def hadd_subjects(dbPath):
"""
Helper Method which add subjects to DB at dbPath
"""
rcsql.add_subject('Maths', dbPath)
rcsql.add_subject('Physics', dbPath)
rcsql.add_subject('Chemistry', dbPath)
rcsql.add_subject('Python', dbPath)

def hupdate_subjects(dbPath):
"""
Helper Method which updates each subject with two 'p' & one 'a'
"""
for subject in rcsql.get_subjects(dbPath):
rcsql.update_subject(subject, 'p', dbPath)
rcsql.update_subject(subject, 'p', dbPath)
rcsql.update_subject(subject, 'a', dbPath)
Empty file.
Loading