Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrustic committed Jun 22, 2022
1 parent 2633e59 commit 6746169
Show file tree
Hide file tree
Showing 15 changed files with 801 additions and 341 deletions.
289 changes: 157 additions & 132 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions rustic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Loading...
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ license = MIT
keywords =
library
json
sql
sqlite
data
shared
binary
Expand All @@ -33,8 +35,7 @@ packages = find:
include_package_data = true
zip_safe = false
install_requires =
probed
hackernote
jesth

[options.entry_points]
console_scripts =
Expand Down
8 changes: 6 additions & 2 deletions shared/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"""The Shared Data Interface"""
from shared.document import Document
from shared.document import Document, create, write, readonly, autosave
from shared.dossier import Dossier
from shared.database import Database
from shared.constant import DEFAULT_DIRECTORY
from jesth.util import get_key_value


__all__ = ["Document", "Dossier", "Database"]
__all__ = ["Document", "Dossier", "Database",
"create", "readonly", "write", "autosave",
"get_key_value", "DEFAULT_DIRECTORY"]
13 changes: 8 additions & 5 deletions shared/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
Update the content of an entry
==============================
set <entry-name> <type>
set <entry-name> <type> <new-content-filename>
set <entry-name> <type>:
set <entry-name> <type>: <new-content-filename>
Valid types: dict list set bin
Delete a specific entry
Expand Down Expand Up @@ -126,7 +126,7 @@ def check_handler(*args):
if not info:
print(ENTRY_DOESNT_EXIST_NOTE)
return
container, filename = info
_, container, filename = info
size = get_file_size(filename)
print("'{}' {} {}".format(entry, container, size))
else:
Expand All @@ -135,7 +135,7 @@ def check_handler(*args):
print(EMPTY_DOSSIER_NOTE)
return
for entry in sorted(info):
container, filename = info[entry]
_, container, filename = info[entry]
size = get_file_size(filename)
print("- '{}' {} {}".format(entry, container, size))

Expand All @@ -159,7 +159,7 @@ def get_handler(*args):
if not info:
print(ENTRY_DOESNT_EXIST_NOTE)
return
container, filename = info
_, container, filename = info
if container == "bin":
if not os.path.exists(filename):
print("Missing binary file '{}'".format(filename))
Expand All @@ -186,9 +186,11 @@ def set_handler(*args):
# update entry with default value accordingly to its container type
if len(args) == 2:
entry, container = args
container = container.rstrip(":")
update_entry_with_default_data(dossier, entry, container)
else:
entry, container, source_filename = args
container = container.rstrip(":")
update_entry_content(dossier, entry, container, source_filename)


Expand All @@ -214,6 +216,7 @@ def update_entry_content(dossier, entry, container,
if not os.path.exists(source_filename):
print("Non existent filename '{}'.".format(source_filename))
return
container = container.rstrip(":")
if container not in ("bin", "dict", "list", "set"):
print("Unknown container type '{}'.".format(container))
return
Expand Down
3 changes: 0 additions & 3 deletions shared/constant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@

DEFAULT_DIRECTORY = os.path.join(os.path.expanduser("~"),
"PyrusticHome", "shared")


VALID_DOCUMENT_FILE_FORMATS = ("auto", "json", "hackernote")
34 changes: 20 additions & 14 deletions shared/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sqlite3 as sqlite
from shared.constant import DEFAULT_DIRECTORY
from shared import error
from shared import dto


class Database:
Expand Down Expand Up @@ -173,11 +174,13 @@ def query(self, sql, param=None):
"""
Use this method to query your database.
Formally: Data Query Language (DQL)
It returns a tuple: (data, description).
Data is a list with data from ur query.
Description is a list with the name of columns related to data
Example: ( [1, "Jack", 50], ["id", "name", "age"] )
This method can raise sqlite.Error, sqlite.Warning
It returns a namedtuple: (columns, data).
Columns is a list of strings, columns names.
Data is a list with data from ur query.
Example:
namedtuple(columns=["id", "name", "age"],
data= ( [1, "Jack", 50], ...) )
This method can raise sqlite.Error, sqlite.Warning
"""
if self._deleted:
raise error.AlreadyDeletedError
Expand All @@ -200,7 +203,8 @@ def query(self, sql, param=None):
finally:
if cur:
cur.close()
return [x[0] for x in description], data
columns = [x[0] for x in description]
return dto.QueryResult(columns, data)

def script(self, script):
"""
Expand Down Expand Up @@ -279,14 +283,13 @@ def get_tables(self):

def get_columns(self, table):
"""
Returns the list of columns names of the given table name
A column is like:
(int_id, str_column_name, str_column_datatype, int_boolean_nullability,
default_value, int_primary_key)
Returns information about the columns of a given table
A column is a namedtuple:
namedtuple(index, name, type, not_null, default, primary_key)
Example:
[(0, "id", "INTEGER", 1, None, 1),
(1, "name", "TEXT", 0, None, 0),
(2, "age", "INTEGER", 1, None, 0)]
[namedtuple(0, "id", "INTEGER", 1, None, 1),
namedtuple(1, "name", "TEXT", 0, None, 0),
namedtuple(2, "age", "INTEGER", 1, None, 0)]
This method can raise sqlite.Error, sqlite.Warning
"""
Expand All @@ -298,7 +301,7 @@ def get_columns(self, table):
try:
cur = self._connection.cursor()
cur.execute("pragma table_info('{}')".format(table))
data = cur.fetchall()
cache = cur.fetchall()
except sqlite.Error as e:
if self._raise_exception:
raise
Expand All @@ -308,6 +311,9 @@ def get_columns(self, table):
finally:
if cur:
cur.close()
for item in cache:
info = dto.ColumnInfo(*item)
data.append(info)
return data

def close(self):
Expand Down
Loading

0 comments on commit 6746169

Please sign in to comment.