Merge branch 'master' into peter
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
This commit is contained in:
commit
0b8d47824a
4 changed files with 45 additions and 15 deletions
|
|
@ -576,7 +576,9 @@ class Database:
|
||||||
|
|
||||||
def upgrade(self, txntype=None, notify=None, version=None):
|
def upgrade(self, txntype=None, notify=None, version=None):
|
||||||
if notify is None:
|
if notify is None:
|
||||||
notify = lambda x: x
|
|
||||||
|
def notify(x):
|
||||||
|
x
|
||||||
if txntype is None:
|
if txntype is None:
|
||||||
txntype = list(self._schema.transaction_types())
|
txntype = list(self._schema.transaction_types())
|
||||||
elif isinstance(txntype, str):
|
elif isinstance(txntype, str):
|
||||||
|
|
|
||||||
|
|
@ -249,8 +249,9 @@ class HashHook(Hook):
|
||||||
line)
|
line)
|
||||||
except (IOError, FileNotFoundError):
|
except (IOError, FileNotFoundError):
|
||||||
if not self._options["forgiving"]:
|
if not self._options["forgiving"]:
|
||||||
raise newfol.exception.UpgradeNeededError("dtb is missing"
|
raise newfol.exception.UpgradeNeededError("dtb is " +
|
||||||
+ " checksum")
|
"missing " +
|
||||||
|
"checksum")
|
||||||
|
|
||||||
def commit_close(self):
|
def commit_close(self):
|
||||||
if "w" in self._mode:
|
if "w" in self._mode:
|
||||||
|
|
|
||||||
|
|
@ -375,13 +375,14 @@ class AboutView(StandardView):
|
||||||
|
|
||||||
|
|
||||||
class RecordView(StandardView):
|
class RecordView(StandardView):
|
||||||
def __init__(self, button, record=None):
|
def __init__(self, title, button, record=None):
|
||||||
dbd = DatabaseData()
|
dbd = DatabaseData()
|
||||||
if record is None:
|
if record is None:
|
||||||
self.rec = filemanip.Record([None] * dbd.schema().nfields())
|
self.rec = filemanip.Record([None] * dbd.schema().nfields())
|
||||||
else:
|
else:
|
||||||
self.rec = record
|
self.rec = record
|
||||||
self.button_name = button
|
self.button_name = button
|
||||||
|
self.title = title
|
||||||
|
|
||||||
def _compute_titles_from_table(self, table):
|
def _compute_titles_from_table(self, table):
|
||||||
titles = []
|
titles = []
|
||||||
|
|
@ -462,14 +463,18 @@ class RecordView(StandardView):
|
||||||
|
|
||||||
def _render_standard(self, loop):
|
def _render_standard(self, loop):
|
||||||
self.loop = loop
|
self.loop = loop
|
||||||
|
head = self.text(self.title, "header")
|
||||||
# We need a box widget for the frame, but GridFlow is a flow widget.
|
# We need a box widget for the frame, but GridFlow is a flow widget.
|
||||||
pile = urwid.Pile([self._render_record(self.rec)])
|
pile = urwid.Pile([self._render_record(self.rec)])
|
||||||
return urwid.Filler(pile, valign="top")
|
filler = urwid.Filler(pile, valign="top")
|
||||||
|
return urwid.Frame(filler, head)
|
||||||
|
|
||||||
|
|
||||||
class DisplayRecordView(RecordView):
|
class DisplayRecordView(RecordView):
|
||||||
def __init__(self, record=None):
|
def __init__(self, title=None, record=None):
|
||||||
super().__init__(_("Commit"), record)
|
if title is None:
|
||||||
|
title = _("Add Record")
|
||||||
|
super().__init__(title, _("Commit"), record)
|
||||||
|
|
||||||
def _build_record(self):
|
def _build_record(self):
|
||||||
fields = [i.widget_list[1].get_edit_text() for i in self.cells]
|
fields = [i.widget_list[1].get_edit_text() for i in self.cells]
|
||||||
|
|
@ -537,7 +542,8 @@ class DisplayRecordView(RecordView):
|
||||||
|
|
||||||
class SearchRecordView(RecordView):
|
class SearchRecordView(RecordView):
|
||||||
def __init__(self, record=None):
|
def __init__(self, record=None):
|
||||||
super().__init__(_("Select Display Template"), record)
|
super().__init__(_("Search Records"), _("Select Display Template"),
|
||||||
|
record)
|
||||||
|
|
||||||
def _get_fields(self):
|
def _get_fields(self):
|
||||||
return [i.widget_list[1].get_edit_text() for i in self.cells]
|
return [i.widget_list[1].get_edit_text() for i in self.cells]
|
||||||
|
|
@ -585,7 +591,7 @@ class SearchRecordView(RecordView):
|
||||||
|
|
||||||
class DisplayTemplateRecordView(RecordView):
|
class DisplayTemplateRecordView(RecordView):
|
||||||
def __init__(self, table, records):
|
def __init__(self, table, records):
|
||||||
super().__init__(_("Search"))
|
super().__init__(_("Display Template"), _("Search"))
|
||||||
self.records = records
|
self.records = records
|
||||||
self.table = table
|
self.table = table
|
||||||
|
|
||||||
|
|
@ -646,7 +652,7 @@ class DisplayTemplateRecordView(RecordView):
|
||||||
|
|
||||||
class SortingTemplateRecordView(RecordView):
|
class SortingTemplateRecordView(RecordView):
|
||||||
def __init__(self, table, records, selected):
|
def __init__(self, table, records, selected):
|
||||||
super().__init__(_("Search"))
|
super().__init__(_("Sorting Template"), _("Search"))
|
||||||
self.records = records
|
self.records = records
|
||||||
self.table = table
|
self.table = table
|
||||||
self.selected = selected
|
self.selected = selected
|
||||||
|
|
@ -862,7 +868,7 @@ class RecordListView(ListView):
|
||||||
cur = self._current_item()
|
cur = self._current_item()
|
||||||
if cur is None:
|
if cur is None:
|
||||||
return
|
return
|
||||||
self.session.render_view(DisplayRecordView(cur))
|
self.session.render_view(DisplayRecordView(_("Current Record"), cur))
|
||||||
|
|
||||||
|
|
||||||
class TableContentsListView(RecordListView):
|
class TableContentsListView(RecordListView):
|
||||||
|
|
@ -1148,12 +1154,16 @@ def import_into(db, dtbname, dbtype, minfields=0, strict=False,
|
||||||
|
|
||||||
def export_from(db, table, dbtype):
|
def export_from(db, table, dbtype):
|
||||||
vault = filemanip.FileStorage(dbtype, sys.stdout)
|
vault = filemanip.FileStorage(dbtype, sys.stdout)
|
||||||
f = lambda x: True
|
|
||||||
|
def f(x):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def g(x):
|
||||||
|
return x.table == table
|
||||||
if table is None and dbtype == "csv":
|
if table is None and dbtype == "csv":
|
||||||
raise newfol.exception.NewfolError(_("A table is required for csv"))
|
raise newfol.exception.NewfolError(_("A table is required for csv"))
|
||||||
if table is not None:
|
func = f if table is None else g
|
||||||
f = lambda x: x.table == table
|
vault.store(db.records(func))
|
||||||
vault.store(db.records(f))
|
|
||||||
|
|
||||||
|
|
||||||
def parse_args(args):
|
def parse_args(args):
|
||||||
|
|
|
||||||
|
|
@ -253,6 +253,10 @@ class ExampleFile(newfol.filemanip.FileFormat):
|
||||||
return [Record(['a', 'b'])]
|
return [Record(['a', 'b'])]
|
||||||
|
|
||||||
|
|
||||||
|
class ExampleHook(newfol.filemanip.Hook):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class PluggableBackendsTest(unittest.TestCase):
|
class PluggableBackendsTest(unittest.TestCase):
|
||||||
def test_adding_backend(self):
|
def test_adding_backend(self):
|
||||||
FileStorage.register_backend('example', ExampleFile)
|
FileStorage.register_backend('example', ExampleFile)
|
||||||
|
|
@ -269,5 +273,18 @@ class PluggableBackendsTest(unittest.TestCase):
|
||||||
with self.assertRaises(KeyError):
|
with self.assertRaises(KeyError):
|
||||||
FileStorage.BACKENDS['example']
|
FileStorage.BACKENDS['example']
|
||||||
|
|
||||||
|
|
||||||
|
class PluggableHooksTest(unittest.TestCase):
|
||||||
|
def test_adding_hook(self):
|
||||||
|
FileStorage.register_hook('example', ExampleHook)
|
||||||
|
self.assertEqual(FileStorage.HOOKS['example'], ExampleHook)
|
||||||
|
|
||||||
|
def test_removing_hook(self):
|
||||||
|
FileStorage.register_hook('example', ExampleFile)
|
||||||
|
self.assertEqual(FileStorage.HOOKS['example'], ExampleFile)
|
||||||
|
FileStorage.unregister_hook('example')
|
||||||
|
with self.assertRaises(KeyError):
|
||||||
|
FileStorage.HOOKS['example']
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue