Example #1
0
    def exportDb(self):
        """Export the database tables to CSV files."""
        caption = "Selecciona en donde guardar la base de datos"
        fileDir = QFileDialog.getExistingDirectory(
            parent=self,
            caption=caption,
            directory="/",
            options=QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks)

        db = Db.Db()
        tables = [
            "tickets", "ticketProducts", "productos", "cupones", "categorias",
            "configuraciones"
        ]

        for table in tables:
            with open(fileDir + "/" + str(table) + ".csv", "w",
                      newline="") as newFile:
                data = db.getTableItems(table)
                wr = csv.writer(newFile, quoting=csv.QUOTE_ALL)
                rawCol = db.getTableMeta(table)
                header = []
                header = [col[1] for col in rawCol]
                wr.writerow(header)
                wr.writerows(data)
Example #2
0
    def updateTables(self):
        """Update tables."""
        db = Db.Db()
        tables = ["tickets", "ticketProducts", "productos", "cupones",
                  "categorias", "configuraciones"]
        t = 0
        for table in tables:
            data = db.getTableItems(table)
            tableObj = self.tables[t]
            r = 0
            rawCol = db.getTableMeta(table)
            colNames = [x[1] for x in rawCol]
            tableObj.setHorizontalHeaderLabels(colNames)
            for row in data:
                c = 0
                for column in row:
                    prevItem = tableObj.item(r, c)
                    item = QTableWidgetItem(str(column))
                    item.setTextAlignment(Qt.AlignRight|
                                          Qt.AlignVCenter)
                    if prevItem:
                        if prevItem.text() != str(column):
                            item.setForeground(Qt.white)
                            item.setBackground(Qt.red)
                    else:
                        item.setForeground(Qt.white)
                        item.setBackground(Qt.red)

                    tableObj.setItem(r, c, item)
                    c += 1
                r += 1
            tableObj.resizeColumnsToContents()
            tableObj.resizeRowsToContents()
            t += 1
Example #3
0
    def __init__(self, mainW):
        """Init."""
        super().__init__(mainW)

        # user = [ID, TYPE[ROOT=0, ADMIN=1, USER=2]]
        self.mainW = mainW
        self.user = self.mainW.user

        self.db = Db.Db()

        self.userData = self.db.getUserById(self.user[0], self.mainW.cursor)

        self.username = self.userData[2]

        if self.userData[1] == 0:
            self.userType = " Root"
        elif self.userData[1] == 1:
            self.userType = " Admin"
        elif self.userData[1] == 2:
            self.userType = " Regular"
        else:
            # Raise error because this data is wrong.
            pass

        title = self.mainW.getVersion() + " - Usuario: {} - Tipo: {}".format(
            str(self.username), self.userType)

        self.mainW.setWindowTitle(title)

        self.initUi()
Example #4
0
    def importDb(self):
        """Import database table from csv file."""
        dataBases = [
            "categorias", "configuraciones", "productos", "cupones",
            "ticketProducts", "tickets"
        ]
        caption = "Selecciona la base de datos que quieres actualizar"
        fileName = QFileDialog.getOpenFileName(parent=self,
                                               caption=caption,
                                               directory="/",
                                               filter="CSV (*.csv)")

        if fileName[0] != "":
            fileName = fileName[0]
            table = fileName.split("/")
            table = table[len(table) - 1].split(".")
            table = table[0]

            rows = []

            if not table not in dataBases:
                with open(fileName) as csvfile:
                    re = csv.reader(csvfile)
                    for row in re:
                        rows.append(row)

            db = Db.Db()
            db.overwriteTable(table, rows)
Example #5
0
    def __init__(self, cursor, connection):
        """Init."""
        super().__init__()

        self.startDb = Db.Db()
        self.session = None
        self.cursor = cursor
        self.user = None
        self.connection = connection
        # print(self.startDb.selectUsernames(self.cursor))

        self.setWindowTitle(self.getVersion())
        self.initUi()
        self.setStyleSheet("font-family: 'Roboto'; color: #333333;")
Example #6
0
def pgmstart():
    global db1, DR1, Quest1
    # Connessione a database MYsql
    hostname = 'localhost'
    db = 'quiz'
    db_user = '******'
    db_passwd = 'red'
    # Inizializzazione oggetto Database
    db1 = Db.Db(hostname, db_user, db_passwd, db)
    db1.connection_on()
    # Inizializzazione oggetto Domande/risposte
    DR1 = DomaRisp.DomaRisp(db1)
    # Inizializzazione oggetto questionario
    Quest1 = Questionario.Questionario(db1)
Example #7
0
    def __init__(self, parent, callback, minPrivilege, cursor):
        """Init."""
        super().__init__(parent)

        self.minPrivilege = minPrivilege

        self.cursor = cursor

        self.callback = callback

        self.setFixedWidth(300)
        # self.setFixedHeight(200)

        self.titleStyle = """
        QLabel {
            font-size: 30px;
            font-weight: 900;
        }
        """

        self.buttonStyle = """
        QPushButton {
            font-size: 20px;
            font-weight: 900;
        }
        """

        self.inputStyle = """
        QLineEdit {
            font-size: 25px;
            border: 2px solid #666666;
            border-radius: 8px;
            font-weight: bold;
        }"""

        self.messageStyle = """
        QLabel {
            color: red;
            font-size: 16px;
            font-weight: regular;
        }"""

        self.db = Db.Db()

        self.initUi()
Example #8
0
    def __init__(self, parent, mainW):
        """Init."""
        super().__init__(parent)

        self.mainW = mainW

        self.setFixedWidth(300)
        self.setFixedHeight(200)

        self.titleStyle = """
        QLabel {
            font-size: 30px;
            font-weight: 900;
        }
        """

        self.buttonStyle = """
        QPushButton {
            font-size: 20px;
            font-weight: 900;
        }
        """

        self.inputStyle = """
        QLineEdit {
            font-size: 25px;
            border: 2px solid #666666;
            border-radius: 8px;
            font-weight: bold;
        }"""

        self.messageStyle = """
        QLabel {
            color: red;
            font-size: 16px;
            font-weight: regular;
        }"""

        self.db = Db.Db()

        self.initUi()
Example #9
0
 def make_variables(self):
     self.db = Db.Db()
     self.path = self.export_path = QStandardPaths.writableLocation(
         QStandardPaths.DocumentsLocation)
     self.recent_files = RecentFiles.get(RECENT_FILES_MAX)
     self.closing = False
Example #10
0
import os
from os.path import join, dirname
from dotenv import load_dotenv

import Db
import HistoryCollectorManager as HCM

dotenv_path = join(dirname(__file__), '..', '.env')
load_dotenv(dotenv_path)

db = Db.Db()
hcm = HCM.HistoryCollectorManager(db)
hcm.start()
Example #11
0
def writeToDb(topic):
    db = Db.Db()
    db.writeTopics(topic)
Example #12
0
from os import *
from Db import *
from DbMapper import *


class Usuarios(DbMapper):
    name = 'usuarios'


if __name__ == "__main__":

    database = Db({
        'hostname': '192.168.6.96',
        'username': '******',
        'password': '******',
        'database': 'ecentry_erp'
    })

    # SELECT statements

    usuarios = Usuarios(database)

    usuarios.fields(('t1.id', 't1.nome', 't2.nome AS empresa'))
    usuarios.join_inner('empresas t2', 't1.id_empresa = t2.id')
    usuarios.order('t1.id')
    usuarios.group('t1.id')

    rowset = usuarios.fetch_all()

    for row in rowset:
        print row.id
Example #13
0
def getInstance():
    instance = Db.Db(host='localhost',
                     user='******',
                     password='******',
                     dbname='tinyFirewall')
    return instance
Example #14
0
def Main():

    u = os.system('reset')

    db = Db.Db()
    message = Msg.Msg(0, 0)
    door = True

    try:

        while True:

            #override
            if (db.override() == "0"):
                u = os.system('clear')
                print("stopped")

                db.state = 0

                message.data = db.override()
                message.send()

            else:
                #restart
                if (db.state == 0):
                    print("restarting...")
                    message.data = db.getNext()
                    message.send()
                    #db.state = 1

                message.recieve()

                if message.new is not None:
                    #u = os.system('clear')

                    print(message.new)
                    print("current: " + str(db.getCurrent()))
                    print("next: " + str(db.getNext()))

                    #if from motor controller update current
                    if int(message.nodeId) == 101:
                        db.updateCurrent(message.data)

                    #if from a node
                    if int(message.nodeId) == 200 or int(
                            message.nodeId) == 201 or int(
                                message.nodeId) == 202 or int(
                                    message.nodeId) == 203:
                        if int(message.data) == 8:
                            door = True
                        elif int(message.data) == 9:
                            door = False
                        else:
                            db.insertDebug(message.nodeId, message.data)
                            db.insertQueue(message.nodeId, message.data)

                #dequeue if not moving
                if door == True:
                    if (db.getCurrent() == db.getNext()):

                        message.data = db.dequeue()

                        #don't bother sending if queue is empty/same floor
                        if (message.data != db.getCurrent()):
                            message.send()

                        db.updateNext(message.data)
                    else:
                        print("moving........")

    except (KeyboardInterrupt):
        pass
Example #15
0
            {'id': 3, 'name': u'section 3', 'seqId': 2}, \
            {'id': 4, 'name': u'section 4', 'seqId': 3}, \
            {'id': 5, 'name': u'section 5', 'seqId': 4}, \
            {'id': 0, 'name': u'section 0', 'seqId': 5}, \
            ]
    assert (r == ex), "mismatch"

    prepare_reorder(sections)
    list = [0, 1, 2, 3, 4, 5]
    sections.reorderItem(list, 5)
    r = sections.getItems()
    ex = [  {'id': 0, 'name': u'section 0', 'seqId': 0}, \
            {'id': 1, 'name': u'section 1', 'seqId': 1}, \
            {'id': 2, 'name': u'section 2', 'seqId': 2}, \
            {'id': 3, 'name': u'section 3', 'seqId': 3}, \
            {'id': 4, 'name': u'section 4', 'seqId': 4}, \
            {'id': 5, 'name': u'section 5', 'seqId': 5}]
    assert (r == ex), "mismatch"

    print "done"


if __name__ == '__main__':
    db = Db("test.db")
    db.open()
    db.resetTables()
    db.createTable()

    test_section(db)

    print "done"
Example #16
0
 def __init__(self, parent, cursor):
     """Init."""
     self.db = Db.Db()
     self.cursor = cursor
     self.parent = parent