imporve database stuff

This commit is contained in:
Bilal Elmoussaoui 2016-05-27 03:51:58 +02:00
parent 15b9fe44b1
commit a472d6b110
7 changed files with 41 additions and 16 deletions

View file

@ -1,4 +1,4 @@
desktopdir = $(DATADIR)/applications
desktopdir = $(datadir)/applications
desktop_DATA = twofactorauth.desktop
UPDATE_DESKTOP = update-desktop-database $(datadir)/applications || :
@ -15,7 +15,7 @@ logo_DATA = about.glade \
menu.glade \
style.css
appdatadir = $(DATADIR)/appdata
appdatadir = $(datadir)/appdata
appdata_DATA = \
two-factor.appdata.xml

Binary file not shown.

View file

@ -1,6 +0,0 @@
CREATE TABLE "providers" (
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE ,
"title" VARCHAR NOT NULL ,
"secret_code" VARCHAR NOT NULL UNIQUE ,
"image" TEXT NOT NULL
)

View file

@ -19,11 +19,13 @@
along with UnitsConverter. If not, see <http://www.gnu.org/licenses/>.
"""
import sys
sys.path.insert(1, '@pyexecdir@')
sys.path.insert(1, '@pythondir@')
from twofactorauth import application
if __name__ == "__main__":
app = application.TwoFactor(package="@PACKAGE@",
app = application.Application(package="@PACKAGE@",
version="@VERSION@",
pkgdatadir="@pkgdatadir@")
app.run(None)
exit_status = app.run(sys.argv)
sys.exit(exit_status)

View file

@ -1,7 +1,7 @@
from gi import require_version
require_version("Gtk", "3.0")
from gi.repository import Gtk, GLib, Gio, Gdk, GObject
from ui.window import TwoFactorWindow
from ui.window import Window
import logging
from models.provider import Provider
@ -9,8 +9,7 @@ logging.basicConfig(level=logging.DEBUG,
format='[%(levelname)s] %(message)s',
)
class TwoFactor(Gtk.Application):
class Application(Gtk.Application):
win = None
def __init__(self, *args, **kwargs):

View file

@ -1,13 +1,18 @@
import sqlite3
import logging
from os import path
from os import path, mknod
from gi.repository import GdkPixbuf, Gtk
logging.basicConfig(level=logging.DEBUG,
format='[%(levelname)s] %(message)s',
)
class Provider:
def __init__(self):
self.conn = sqlite3.connect('/home/bilal/Projects/Two-factor-gtk/database.db')
database_file = '/home/bilal/.config/TwoFactorAuth/database.db'
if not (path.isfile(database_file) and path.exists(database_file)):
mknod(database_file)
self.conn = sqlite3.connect(database_file)
if not self.is_table_exists():
self.create_table()
def add_provider(self, name, secret_code, image):
t = (name, secret_code, image,)
@ -79,3 +84,28 @@ class Provider:
logging.error("Couldn't fetch providers list")
logging.error(str(e))
return None
def create_table(self):
query = '''CREATE TABLE "providers" (
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE ,
"title" VARCHAR NOT NULL ,
"secret_code" VARCHAR NOT NULL UNIQUE ,
"image" TEXT NOT NULL
)'''
try:
self.conn.execute(query)
self.conn.commit()
except Exception as e:
logging.error("Error during the creation of the database table")
logging.error(str(e))
def is_table_exists(self):
query = "SELECT id from providers LIMIT 1"
c = self.conn.cursor()
try:
data = c.execute(query)
return True
except Exception as e:
logging.error("Coudln't check if a table exists")
logging.error(e)
return False

View file

@ -13,7 +13,7 @@ logging.basicConfig(level=logging.DEBUG,
format='[%(levelname)s] %(message)s',
)
class TwoFactorWindow(Gtk.ApplicationWindow):
class Window(Gtk.ApplicationWindow):
app = None
selected_app_idx = None