예제 #1
0
파일: main.py 프로젝트: bk2204/newfol
    def callback(self, type_, obj):
        dbd = DatabaseData()
        if self.is_callback_type(type_, "select"):
            fields = self._get_fields()
            fieldres = []
            for f in fields:
                try:
                    fieldres.append(re.compile(f, re.IGNORECASE))
                except:
                    msg = _("'%s' is not a valid regular expression")
                    mb = MessageBox(msg % f)
                    mb.render(self.loop)
                    return

            def filter_(rec):
                if fieldres[0].search(rec.table) is None:
                    return False
                for field, reobj in zip(rec.fields, fieldres[1:]):
                    if reobj.search(field) is None:
                        return False
                return True
            recs = dbd.database().records(filter_)
            self.session.render_view(DisplayTemplateRecordView(fields[0],
                                                               recs))
        elif type_ == "change":
            self._set_titles_for_grid(obj[1])
        else:
            return super().callback(type_, obj)
예제 #2
0
파일: main.py 프로젝트: bk2204/newfol
 def __init__(self, title, button, record=None):
     dbd = DatabaseData()
     if record is None:
         self.rec = filemanip.Record([None] * dbd.schema().nfields())
     else:
         self.rec = record
     self.button_name = button
     self.title = title
예제 #3
0
파일: main.py 프로젝트: bk2204/newfol
 def _compute_titles_from_table(self, table):
     titles = []
     schema = DatabaseData().schema()
     for i in range(schema.nfields() + 1):
         if i == 0:
             text = _("Table name")
         elif table in schema.mapping():
             text = schema.mapping()[table].desc[i-1] or ""
         else:
             text = ""
         titles.append(text)
     return titles
예제 #4
0
파일: main.py 프로젝트: bk2204/newfol
 def _render_in_editor_ro(self, title, recs, content, selected):
     dbd = DatabaseData()
     items = []
     for rec in recs:
         recvals = []
         for field in selected:
             if field == "table":
                 recvals.append(rec.table)
             else:
                 recvals.append(rec.fields[field])
         items.append(filemanip.Record(recvals))
         if dbd.database().schema().options("editor", "blank-lines"):
             items.append(filemanip.Record([]))
     self._display_in_editor(items, True)
예제 #5
0
파일: main.py 프로젝트: bk2204/newfol
def main(args):
    argobj = parse_args(args)
    if argobj.dbname is not None:
        sys.stderr.write("--dbname is obsolete; use --table instead\n")
    if argobj.table is None and argobj.dbname is not None:
        argobj.table = argobj.dbname
    ensure_db_dir(argobj.homedir)
    db = None
    try:
        txntype = argobj.txntype
        if argobj.from_txntype and argobj.cmd == 'upgrade':
            txntype = argobj.from_txntype
        db = newfol.database.Database.load(argobj.homedir, txntype,
                                           argobj.config)
        db.lock()
        dbd = DatabaseData()
        dbd._database = db
        do_import(db.schema().imports())
        # Check to see if the database needs upgrading.
        if argobj.cmd != "upgrade":
            db.records()
    except Exception as e:
        if argobj.cmd != "version":
            raise e
        db = None
    if argobj.cmd == "curses":
        start_curses(db)
    elif argobj.cmd == "import":
        import_into(db, argobj.table, argobj.dbtype, argobj.minfields,
                    argobj.strict, argobj.identity)
    elif argobj.cmd == "validate":
        db.validate(True)
    elif argobj.cmd == "repair":
        db.repair()
        db.validate(True)
    elif argobj.cmd == "test":
        pass
    elif argobj.cmd == "upgrade":
        upgrade_database(db, argobj.upgrade_version, argobj.txntype)
        return
    elif argobj.cmd == "export":
        export_from(db, argobj.table, argobj.dbtype)
    elif argobj.cmd == "version":
        print_version(db)
        return
    db.store()
    db.unlock()
예제 #6
0
파일: main.py 프로젝트: bk2204/newfol
 def _render_record(self, rec):
     self.cells = []
     schema = DatabaseData().schema()
     for i in range(schema.nfields() + 1):
         head = self.text("", "description")
         body = self._create_body(rec, i)
         pile = urwid.Pile([head, body])
         self.cells.append(pile)
     mapped_cells = self._map_cells()
     screen_cols = self.loop.screen.get_cols_rows()[0]
     grid = urwid.GridFlow(mapped_cells,
                           int((screen_cols - 2) / schema.columns()), 1,
                           1, "left")
     self.grid = grid
     for i in self.cells:
         i.widget_list[1].set_grid(self.grid)
     self._set_titles_for_grid(rec.table)
     return grid
예제 #7
0
파일: main.py 프로젝트: bk2204/newfol
 def _render_standard(self, loop):
     self.loop = loop
     key = dict(map(lambda x: (x, DatabaseData().keys.shortcut(x)),
                    ["quit", "previous", "sync-database", "add",
                     "search", "next", "next-secondary",
                     "next-tertiary", "menu", "about", "browse"]))
     try:
         recver = DatabaseData().database().records()[0].version()
     except IndexError:
         recver = '?'
     db = DatabaseData().database()
     ver = db.version()
     msgs = [
         "newfol " + __version__,
         _("Keys: %s to quit, %s: previous view, %s: write to disk,") %
         (key['quit'], key['previous'], key['sync-database']),
         _("%s: add record, %s: search, %s: next, %s: secondary next,") %
         (key['add'], key['search'], key['next'], key['next-secondary']),
         _("%s: tertiary next, %s: menu, %s: this screen,") %
         (key['next-tertiary'], key['menu'], key['about']),
         _("%s: browse by table") %
         (key['browse']),
         "",
         " ".join([
             self._display_option("exe_ok",
                                  db.schema().execution_allowed()),
             self._display_option("homedir",
                                  db.location())]),
         " ".join([
             self._display_option("serialization",
                                  ver.serialization(),
                                  ver.serialization_version()),
             self._display_option("rec_ver",
                                  ver.record_version(),
                                  recver,
                                  filemanip.Record([]).version())
         ]),
     ]
     pile = urwid.Pile([
         urwid.AttrMap(urwid.Text(("text", i), align="center"), "bg")
         for i in msgs])
     fill = urwid.Filler(pile)
     return urwid.AttrMap(fill, "bg")
예제 #8
0
파일: main.py 프로젝트: bk2204/newfol
 def callback(self, type_, obj):
     if self.is_callback_type(type_, "simple-select"):
         dbd = DatabaseData()
         newrec = self._build_record()
         recs = []
         inserted = False
         for r in dbd.database().records():
             if r is self.rec:
                 r.fields[:] = newrec.fields[:]
                 r.table = newrec.table
                 inserted = True
             recs.append(r)
         if not inserted:
             recs.append(newrec)
         dbd.database().records()[:] = recs
         render_previous_view(self.loop)
     elif type_ == "change":
         self._set_titles_for_grid(obj[1])
         if not any(self.rec.fields) and not self.rec.table:
             self._autofill(obj[1])
     else:
         return super().callback(type_, obj)
예제 #9
0
파일: main.py 프로젝트: bk2204/newfol
 def _autofill(self, table):
     schema = DatabaseData().schema()
     if not schema.execution_allowed():
         return False
     if table not in schema.mapping():
         return False
     mapping = schema.mapping()[table].get_mapping_onto("internal",
                                                        "default")
     for i in range(0, len(mapping)):
         if mapping[i] == "" or mapping[i] is None:
             continue
         try:
             val = eval(mapping[i])
             if val is None:
                 continue
         except Exception:
             msg = _('%s is not a valid expression.')
             mbox = MessageBox(msg % mapping[i])
             mbox.render(self.loop)
             mapping[i] = None
             continue
         self.cells[i+1].widget_list[1].set_edit_text(str(val))
예제 #10
0
파일: main.py 프로젝트: bk2204/newfol
 def _render_standard(self, loop):
     self.loop = loop
     sch = DatabaseData().schema()
     items = sorted(DatabaseData().database().records(), key=self._key)
     title = _("List of all records by key field")
     return self._render_records(loop, title, items, sch.key_fields())
예제 #11
0
파일: main.py 프로젝트: bk2204/newfol
 def _render_standard(self, loop):
     dbd = DatabaseData()
     recs = dbd.database().records(lambda rec: rec.table == self.table)
     title = _("List of records by key field for %s") % self.table
     return self._render_records(loop, title, recs,
                                 dbd.schema().key_fields())