Skip to content

Commit

Permalink
fixed the db store path issue and added nested lists
Browse files Browse the repository at this point in the history
  • Loading branch information
suburbanfilth committed Sep 8, 2017
1 parent 7a4506e commit 4bf1d26
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
7 changes: 5 additions & 2 deletions noted/database.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import GLib
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from database_tables import Notebook, Note, Base
import getpass
import os
import subprocess

class Database(object):

def start_database(self):
db_path = "/home/{}/Noted/sqlitedatabase.db".format(getpass.getuser())
path = GLib.get_user_data_dir()
db_path = "{}/Noted/sqlitedatabase.db".format(path)
if not os.path.exists(db_path):
self.engine = create_engine('sqlite:///{}'.format(db_path),echo=False)
Base.metadata.create_all(self.engine)
Expand Down
1 change: 0 additions & 1 deletion noted/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def __init__(self,parent):
self.scrolled_window.set_hexpand(True)
self.parent = parent

self.current_indent_level = 1
self.offset_after_tab_deletion = None

# TextView
Expand Down
10 changes: 5 additions & 5 deletions noted/main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk
from gi.repository import Gtk, Gdk, GLib
import sidebar as sb
import headerbar as hb
import editor
import shelve
from dialogs import notebook_dialog as nd
from dialogs import delete_dialog as dd
from database import Database
import getpass
import os
import subprocess

Expand Down Expand Up @@ -122,10 +121,10 @@ def save_note(self, event):
self.sidebar.modify_item(path, title)

def start_database(self):
path = "/home/{}/Noted".format(getpass.getuser())
path = "{}/Noted".format(GLib.get_user_data_dir())
if not os.path.exists(path):
subprocess.call(['mkdir', path])
db = shelve.open("/home/{}/Noted/database.db".format(getpass.getuser()))
db = shelve.open("{}/database.db".format(path))
self.database = Database()
self.database.start_database()
if not db:
Expand All @@ -142,7 +141,8 @@ def start_database(self):
db.close()

def close_database(self, event):
db = shelve.open("/home/{}/Noted/database.db".format(getpass.getuser()))
path = GLib.get_user_data_dir()
db = shelve.open("{}/Noted/database.db".format(path))
db['note_id'] = self.id
db['notebook_id'] = self.notebook_id
db.close()
Expand Down

0 comments on commit 4bf1d26

Please sign in to comment.