Esempio n. 1
0
        def _exct_cmd():
            t = s.TimeNow()

            def complete_print(strDesc):
                print('    Set  %-13s for engine "%s" completed...\
                        ' % ('"%s"' % strDesc, self._host))
                time.sleep(0.25)

            try:
                # Set Time
                if self._TN_Conn.exctCMD('rtc set time %d %d %d' %
                                         (t.h(), t.mi(), t.s())):
                    complete_print('Time')
                    # Set Date
                    if self._TN_Conn.exctCMD('rtc set date %d %d %d' %
                                             (t.y() - 2000, t.mo(), t.d())):
                        complete_print('Date')
                        # Set Day of the Week
                        DoW = t.wd() + 2
                        if DoW == 8:
                            DoW - 7
                        if self._TN_Conn.exctCMD('rtc set day %d' % DoW):
                            complete_print('Day_of_Week')
                return True
            except Exception as E:
                s.ShowErr(
                    self.__class__.__name__,
                    sys._getframe().f_code.co_name,
                    'rtc set faild for engine "{}" with error:'.format(
                        self._host), '"{}"'.format(E))
Esempio n. 2
0
 def _conn():
     try:
         ftp.connect(self._host, self._port, self._timeout)
         self._connected = ftp
         return True
     except Exception as E:
         s.ShowErr(self.__class__.__name__,
                   sys._getframe().f_code.co_name,
                   'FTP connect to "{}" failed with error:'.format(
                       self._host),
                   '"{}"'.format(E))
Esempio n. 3
0
 def _login():
     try:
         ftp.login(self._username, self._password)
         self._logined = ftp
         return True
     except Exception as E:
         # print(E)
         s.ShowErr(self.__class__.__name__,
                   sys._getframe().f_code.co_name,
                   'FTP login to "{}" failed with error:'.format(
                       self._host),
                   '"{}"'.format(E))
Esempio n. 4
0
 def _connect(self):
     try:
         objTelnetConnect = telnetlib.Telnet(
             self._host, self._port, self._timeout)
         objTelnetConnect.read_until(
             self._strLoginPrompt.encode(encoding="utf-8"), timeout=1)
         objTelnetConnect.write(self._password.encode(encoding="utf-8"))
         objTelnetConnect.write(b'\r')
         objTelnetConnect.read_until(
             self._strMainMenuPrompt.encode(encoding="utf-8"), timeout=1)
         self.Connection = objTelnetConnect
         return True
     except Exception as E:
         s.ShowErr(self.__class__.__name__,
                   sys._getframe().f_code.co_name,
                   'Telnet connect to "{}" failed with error:'.format(
                       self._host),
                   '"{}"'.format(E))
Esempio n. 5
0
 def _putfile():
     try:
         ftp = self._Connection
         # print(ftp.getwelcome())
         ftp.cwd(strRemoteFolder)
         objOpenLocalFile = open('{}/{}'.format(
             strLocalFolder, strLocalFileName), 'rb')
         if FTPtype == 'bin':
             ftp.storbinary('STOR {}'.format(strRemoteFileName),
                            objOpenLocalFile, intBufSize)
         elif FTPtype == 'asc':
             ftp.storlines('STOR {}'.format(
                 strRemoteFileName), objOpenLocalFile)
         ftp.set_debuglevel(0)
         objOpenLocalFile.close()
         return True
     except Exception as E:
         s.ShowErr(self.__class__.__name__,
                   sys._getframe().f_code.co_name,
                   'FTP upload "{}" failed with error:'.format(
                       self._host),
                   '"{}"'.format(E))
Esempio n. 6
0
 def _getfile():
     try:
         ftp = self._Connection
         # print(ftp.getwelcome())
         ftp.cwd(strRemoteFolder)
         objOpenLocalFile = open('{}/{}'.format(
             strLocalFolder, strLocalFileName), "wb")
         if FTPtype == 'bin':
             ftp.retrbinary('RETR {}'.format(strRemoteFileName),
                            objOpenLocalFile.write)
         elif FTPtype == 'asc':
             ftp.retrlines('RETR {}'.format(strRemoteFileName),
                           objOpenLocalFile.write)
         objOpenLocalFile.close()
         ftp.cwd('/')
         return True
     except Exception as E:
         s.ShowErr(self.__class__.__name__,
                   sys._getframe().f_code.co_name,
                   'FTP download "{}" failed with error:'.format(
                       self._host),
                   '"{}"'.format(E))
Esempio n. 7
0
def test_ShowErr():
    assert sun.ShowErr('a', 'b', 'c', 'd', 'e') == None