示例#1
0
    def stop_server(self):

        try:
            self.run = False
            AddToLog('-----User stop server-----')
            exit(0)
        except Exception:
            AddToLog('---Fail Stop Server!!----')
示例#2
0
文件: DM.py 项目: welir/TCP-PYTHON
 def del_base(self):
     try:
         os.remove(base)
         AddToLog('Database removed.')
     except EOFError:
         AddToLog('Error removing base ')
     except PermissionError:
         AddToLog(
             'Процесс не может получить доступ к базе, так как этот файл занят другим процессом,попробуте закрыть все программы, которые используют базу '
         )
示例#3
0
 def get_data(self):
     try:
         AddToLog(self.sess.ip + '---' + 'Reserve main data...<-- ' +
                  self.sess.data[5:])
         self.sess.sql_ins_data()
         AddToLog(self.sess.ip + '---' + 'Send confirm data...  --> ' +
                  self.details[0])
         self.data_parse()
     except Exception:
         AddToLog(self.sess.ip + '---' + 'Connection refuse...' +
                  self.details[0])
示例#4
0
    def sql_ins_photo(self, name):

        conn = sqlite3.connect('sessions.db')
        c = conn.cursor()
        c.execute('''INSERT INTO USERS(name) VALUES(:d2)''', (name, ))
        conn.commit()
        conn.close()

        AddToLog(self.ip + '---' + "Writing to base ... Ок")

        AddToLog(self.ip + '---' + "Error:" + (sqlite3.DatabaseError))
示例#5
0
 def sql_ins_data(self):
     try:
         conn = sqlite3.connect('sessions.db')
         c = conn.cursor()
         c.execute('''INSERT INTO DATA(dt,data) VALUES(:d2,:d3)''',
                   ((datetime.datetime.now().strftime('%d.%m.%Y %H:%M:%S'),
                     self.data)))
         conn.commit()
         conn.close()
         AddToLog(self.ip + '---' + "Writing to base ... Ок")
     except sqlite3.DatabaseError:
         AddToLog(self.ip + '---' + "Error:" + sqlite3.DatabaseError)
示例#6
0
文件: DM.py 项目: welir/TCP-PYTHON
 def cr_base(self, exec_string=[]):
     global conn
     try:
         conn = sqlite3.connect(base)
         c = conn.cursor()
         AddToLog("Initialization Database...")
         for i in range(len(exec_string)):
             c.execute(exec_string[i])
         conn.commit()
         AddToLog('Initialization complete.')
         conn.close()
     except Exception:
         conn.close()
         AddToLog('Initialization Database Error!.')
         exit()
示例#7
0
 def run(self):
     #self.get_session_info()
     try:
         while True:
             if self.type_input_data() == 'data':
                 self.get_data()
     except Exception:
         AddToLog('Unknown reserving data type')
示例#8
0
    def start_server(self):

        self.run = True
        AddToLog('+++++++++++++++++++++++++++++++++++++++++++++++++++')
        AddToLog("++ TCP Server Start, waiting clients...")
        AddToLog('++ Server address: ' + self.host + '  Port: ' +
                 str(self.port))
        AddToLog('+++++++++++++++++++++++++++++++++++++++++++++++++++')

        try:
            while True:
                if self.run:
                    channel, details = self.server_socket.accept()
                    self.ClientThread(channel, details).start()

        except Exception:
            AddToLog('---Server Stopped!----')
示例#9
0
    def get_data(self):
        try:
            AddToLog(self.sess.ip + '---' + 'Reserve main data...<-- ' +
                     self.sess.data[5:])
            self.sess.sql_ins_data()
            AddToLog(self.sess.ip + '---' + 'Send confirm data...  --> ' +
                     self.details[0])
            self.channel.send(bytes('data_ok' + "\r\n", 'utf-8'))
            AddToLog(
                "-----------------------------------------------------------------"
            )

            time.sleep(1)

        except Exception:
            AddToLog(self.sess.ip + '---' + 'Connection refuse...' +
                     self.details[0])
示例#10
0
    def get_session_info(self):

        try:

            AddToLog(
                "-----------------------------------------------------------------"
            )
            AddToLog(self.sess.ip + '---' + 'Reserve session data... <-- ' +
                     self.sess.client_name + ' ' + self.sess.dt + ' ' +
                     self.sess.ip)
            self.sess.sql_ins_session()
            AddToLog(self.sess.ip + '---' + 'Send confirm data... --> ' +
                     self.details[0])
            self.channel.send(bytes('sess_ok ' + str(self.channel), 'utf-8'))
            time.sleep(1)
        except Exception:
            AddToLog('Connection refuse...' + self.details[0])
示例#11
0
文件: DM.py 项目: welir/TCP-PYTHON
    def sql_drop(self, table):

        conn = sqlite3.connect(self.base)
        c = conn.cursor()
        c.execute('''DELETE FROM ''' + table)
        conn.commit()
        conn.close()
        AddToLog('---' + 'Delete from Table ' + table + '... Ок')
示例#12
0
文件: DM.py 项目: welir/TCP-PYTHON
    def sql_insert(self, table, values):

        conn = sqlite3.connect(self.base)
        c = conn.cursor()
        c.execute('''INSERT INTO ''' + table + ''' VALUES(:s1,:s2)''', values)
        conn.commit()
        conn.close()
        AddToLog('---' + "Writing to base ... Ок")
示例#13
0
 def sql_ins_session(self):
     try:
         conn = sqlite3.connect('sessions.db')
         c = conn.cursor()
         c.execute('''INSERT INTO SES VALUES(:s1,:s2,:s3)''',
                   (self.client_name, self.ip, self.dt))
         conn.commit()
         conn.close()
     except sqlite3.DatabaseError:
         AddToLog("Database Error")
示例#14
0
文件: DM.py 项目: welir/TCP-PYTHON
    def sql_update(self, table, Row, where_, values):

        conn = sqlite3.connect(self.base)
        c = conn.cursor()
        c.execute(
            '''UPDATE ''' + table + ''' SET ''' + Row +
            '''  =  :v1 where   ''' + where_ + ''' = :v2  ''', values)
        conn.commit()
        conn.close()
        AddToLog('---' + "Update base ... Ок")
示例#15
0
    def data_parse(self):
        s = 'data//'

        if self.sess.data == 'data//status\r\n':
            for i in range(1, count_relay + 1):
                s += 'R' + str(i) + '-' + self.Relay.Position[i - 1]
            self.channel.send(bytes(s, 'utf-8'))
            AddToLog(s)

        for i in range(1, count_relay + 1):
            if self.sess.data == 'data//R' + str(i) + '-on\r\n':
                self.Relay.setPositionRelay(i, 'on')
                self.channel.send(
                    bytes(
                        'R' + str(i) + '-' + self.Relay.Position[i - 1] +
                        "\r\n", 'utf-8'))
                AddToLog('R' + str(i) + '-' + self.Relay.Position[i - 1])
                self.sess.data = ''
            if self.sess.data == 'data//R' + str(i) + '-off\r\n':
                self.Relay.setPositionRelay(i, 'off')
                self.channel.send(
                    bytes(
                        'R' + str(i) + '-' + self.Relay.Position[i - 1] +
                        "\r\n", 'utf-8'))
                AddToLog('R' + str(i) + '-' + self.Relay.Position[i - 1])
                self.sess.data = ''

        if self.sess.data == 'data//relays-off\r\n':
            self.Relay.setPositionAll('off')
            AddToLog('data//relays-off')
            self.channel.send(bytes('relays-off', 'utf-8'))
            self.sess.data = ''
        if self.sess.data == 'data//relays-on\r\n':
            self.Relay.setPositionAll('on')
            AddToLog('data//relays-on')
            self.channel.send(bytes('relays-on', 'utf-8'))

            self.sess.data = ''
        if self.sess.data == 'data//temp\r\n':
            self.channel.send(bytes(self.Tmpr.GetTempandVlaga, 'utf-8'))
            AddToLog(self.Tmpr.GetTempandVlaga)
        for i in range(count_relay):
            if self.sess.data == 'data//R' + str(i) + '-status\r\n':
                self.channel.send(
                    bytes(
                        'data//R' + str(i) + '-' + self.Relay.Position[i - 1] +
                        "\r\n", 'utf-8'))
                AddToLog('data//R' + str(i) + '-' + self.Relay.Position[i - 1])
                self.sess.data = ''