Esempio n. 1
0
    def __init__(self, server_list):

        # Make a copy of the SERVERLIST which we fiddle around with
        self.SERVERLIST = list(server_list)

        # Open listening sockets for each of the servers we have
        for server in self.SERVERLIST:
            #print server
            try:
                tmp_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                tmp_sock.bind(('', server['port']))
                tmp_sock.listen(1)
                server['socket'] = tmp_sock
            except socket.error as e:
                print "Oops, something went wrong while initialzing", server['name']
                print "The Error Message says:", e
                print "Server attrs are:\n", server
                self.SERVERLIST.remove(server)

        # Initialize DB for every server
        for server in self.SERVERLIST:
            if not db.check_table_exists(server['name']):
                db.init_table(server['name'])

        self.pltr = plot.Plotter(self.SERVERLIST)

        print "Listener, init'd"
Esempio n. 2
0
def main():
    if len(sys.argv) < 2:
        print("Usage: init_fortune.py <fortune_filename> [table name]")
        sys.exit(1)

    fortune_file = sys.argv[1]

    # If [table name] specified, use it. Otherwise get table name from fortune filename.
    if len(sys.argv) >= 3:
        tbl = sys.argv[2]
    else:
        (sdir, filename) = os.path.split(fortune_file)
        tbl = os.path.splitext(filename)[0]

    con = db.connect_db()

    db.purge_table(con, tbl)
    db.init_table(con, tbl)

    cur = con.cursor()
    sql = f"INSERT INTO {tbl} (_id, _body) VALUES (?, ?)"

    body_lines = []

    with open(fortune_file, "r") as f:
        # Skip over lines until the first "%" line
        #for line in f:
        #    line = line.rstrip()
        #    print(line)
        #    if re.search(r'^%\s*$', line):
        #        break

        for line in f:
            line = line.rstrip()

            # "%" separator line
            if re.search(r'^%\s*$', line):
                body = "\n".join(body_lines).strip()
                if body != "":
                    print(body)
                    print("---")
                    cur.execute(sql, [util.gen_id(), body])

                body_lines = []
                continue

            body_lines.append(line)

        body = "\n".join(body_lines).strip()
        if body != "":
            print(body)
            print("---")
            cur.execute(sql, [util.gen_id(), body])

    con.commit()
Esempio n. 3
0
    def on_create_table(self, w):
        dlg = CreateTableDlg(self)
        resp = dlg.run()

        # Create new table.
        if resp == Gtk.ResponseType.OK:
            tbl = dlg.table_name()
            if tbl != "":
                db.init_table(self.con, tbl)
                db.commit(self.con)
                self.refresh_tables(tbl)

        dlg.destroy()
Esempio n. 4
0
    def __init__(self,server_list):

        self.SERVERLIST = list(server_list)
        # If there is a table corresponding to the server name,
        # load data from it. If not, create a table for it.
        for server in self.SERVERLIST:
            if not db.check_table_exists(server['name']):
                db.init_table(server['name'])
            else:
                # Filter data/apply function? Yes
                server['data'] = [[],[]]
                for entry in db.read_all(server['name']):
                    x,y = server['function'](entry[:-1])
                    server['data'][0].append(float(x))
                    server['data'][1].append(float(y))
Esempio n. 5
0
def main():
    con = db.connect_db()
    tbl = "art_of_worldly_wisdom"

    db.purge_table(con, tbl)
    db.init_table(con, tbl)

    cur = con.cursor()
    sql = f"INSERT INTO {tbl} (_id, _body) VALUES (?, ?)"

    body_lines = []

    is_last_line_page_break = False

    with open("aww.txt", "r") as aww:
        for line in aww:
            line = line.rstrip()

            # Skip over "[p. nnn]" lines
            if re.search(r'^\[p\..*]', line):
                is_last_line_page_break = True
                continue

            # Skip the line after the "[p. nnn]" line
            if is_last_line_page_break and line.strip() == "":
                is_last_line_page_break = False
                continue

            # Title: "iii Keep Matters for a Time in Suspense."
            if re.search(r'^[ivxlcdm]+\s+\w+', line):
                body = "\n".join(body_lines).strip()
                print(body)
                print("---")
                cur.execute(sql, [util.gen_id(), body])

                body_lines = []

            line = line.replace("[paragraph continues] ", "")
            body_lines.append(line)

        if len(body_lines) > 0:
            body = "\n".join(body_lines).strip()
            print(body)
            print("\n---\n")
            cur.execute(sql, [util.gen_id(), body])

    con.commit()
Esempio n. 6
0
def init_db():
	db.open()
	try:
		db.init_table()
	finally:
		db.db.close()
Esempio n. 7
0
 def __init_table(self):
     db.connect()
     db.init_table()
Esempio n. 8
0
    def on_activate(self, w):
        tag = w.tag
        print(f"on_activate(): {tag}")

        if tag == "tblmaker_exit":
            Gtk.main_quit()
        elif tag == "table_new-table":
            dlg = CreateTableDlg(self)
            resp = dlg.run()
            tbl = dlg.table_name()
            dlg.destroy()

            # Create new table.
            if resp == Gtk.ResponseType.OK and tbl != "":
                db.init_table(self.con, tbl)
                db.commit(self.con)

                self.refresh_tables()
                self.select_table(tbl)

                self.run_query(self.state.tbl, "", "")
        elif tag == "record_new":
            # Show Edit Rec window with blank recid.
            editw = EditRecWin(self.con, self.state.tbl, "", self.on_edit_save,
                               self.on_edit_close)
            self.state.editwins[editw.winid] = editw

        elif tag == "record_edit":
            if not self.state.rec:
                return

            # Show Edit Rec window with currect rec selected.
            recid = self.state.rec['_id']
            editw = EditRecWin(self.con, self.state.tbl, recid,
                               self.on_edit_save, self.on_edit_close)
            self.state.editwins[recid] = editw

        elif tag == "record_delete":
            if not self.state.rec:
                return

            dlg = Gtk.MessageDialog(self, 0, Gtk.MessageType.QUESTION,
                                    Gtk.ButtonsType.YES_NO, "Delete this rec?")
            dlg.format_secondary_text(rec_row_excerpt(self.state.rec))
            resp = dlg.run()
            dlg.destroy()

            if resp == Gtk.ResponseType.YES:
                recid = self.state.rec['_id']
                self.run_delete(self.state.tbl, recid)

                # Set rec selected to next row's rec.
                # If no next row's rec, set to previous row's rec.
                prev_row = None
                last_prev_row = None
                is_found = False
                for row in self.get_results_lb():
                    if prev_row and self.state.rec['_id'] == prev_row.rec[
                            '_id']:
                        self.state.rec = row.rec
                        is_found = True
                        break

                    last_prev_row = prev_row
                    prev_row = row

                if not is_found:
                    if prev_row == None:
                        # No result rows
                        self.state.rec = None
                    elif last_prev_row and self.state.rec[
                            '_id'] == prev_row.rec['_id']:
                        # Deleted last result row
                        self.state.rec = last_prev_row.rec
                    else:
                        # Deleted the only result row
                        self.state.rec = None

                # Remove deleted rec from results.
                self.refresh_results(None, self.state.tbl)

        elif tag == "search_text":
            dlg = FindInputDlg(self)
            resp = dlg.run()
            qfind = dlg.qfind()
            dlg.destroy()

            if resp == Gtk.ResponseType.OK and qfind != "":
                self.run_query(self.state.tbl, qfind, "")