示例#1
0
 def __computeMd5sum(self):
     """update md5sum file. If it changed, return True.
     If unchanged or no ogg files exist, remove archive and md5sum and return False.
     If ogg files exist but no archive, return True."""
     if self.__md5sum:
         # we already checked
         return
     md5FileName = os.path.join(self.directory, 'md5sum')
     archiveExists = os.path.exists(self.archiveName())
     ogg = self.oggFiles()
     if not ogg:
         removeIfExists(self.archiveName())
         removeIfExists(md5FileName)
         self.__md5sum = None
         logDebug('no ogg files in %s' % self)
         return
     md5sum = md5()
     for oggFile in ogg:
         md5sum.update(
             open(os.path.join(self.directory, oggFile), 'rb').read())
     # the md5 stamp goes into the old archive directory 'username'
     self.__md5sum = md5sum.hexdigest()
     existingMd5sum = self.savedmd5Sum()
     md5Name = self.md5FileName()
     if self.__md5sum != existingMd5sum:
         if Debug.sound:
             if not os.path.exists(md5Name):
                 logDebug('creating new %s' % md5Name)
             else:
                 logDebug('md5sum %s changed, rewriting %s with %s' %
                          (existingMd5sum, md5Name, self.__md5sum))
         try:
             open(md5Name, 'w').write('%s\n' % self.__md5sum)
         except BaseException as exception:
             logException('\n'.join([
                 i18n('cannot write <filename>%1</filename>: %2', md5Name,
                      str(exception)),
                 i18n(
                     'The voice files have changed, their checksum has changed.'
                 ),
                 i18n(
                     'Please reinstall kajongg or do, with sufficient permissions:'
                 ), 'cd {} ; cat *.ogg | md5sum > md5sum'.format(
                     self.directory)
             ]))
     if archiveExists:
         archiveIsOlder = os.path.getmtime(md5Name) > os.path.getmtime(
             self.archiveName())
         if self.__md5sum != existingMd5sum or archiveIsOlder:
             os.remove(self.archiveName())
示例#2
0
文件: login.py 项目: zero804/kajongg
 def _loginReallyFailed(self, failure):
     """login failed, not fixable by adding missing user"""
     msg = None
     if not isAlive(Internal.mainWindow):
         raise CancelledError
     if failure.check(CancelledError):
         pass
     elif failure.check(twisted.internet.error.TimeoutError):
         msg = i18n('Server %1 did not answer', self.url)
     elif failure.check(twisted.internet.error.ConnectionRefusedError):
         msg = i18n('Server %1 refused connection', self.url)
     elif failure.check(twisted.internet.error.ConnectionLost):
         msg = i18n('Server %1 does not run a kajongg server', self.url)
     elif failure.check(twisted.internet.error.DNSLookupError):
         msg = i18n('Address for server %1 cannot be found', self.url)
     elif failure.check(twisted.internet.error.ConnectError):
         msg = i18n(
             'Login to server %1 failed: You have no network connection',
             self.url)
     else:
         msg = 'Login to server {} failed: {}/{} Callstack:{}'.format(
             self.url, failure.value.__class__.__name__,
             failure.getErrorMessage(), failure.getTraceback())
     # Maybe the server is running but something is wrong with it
     if self.url and self.url.useSocket:
         if removeIfExists(socketName()):
             logInfo(
                 i18n('removed stale socket <filename>%1</filename>',
                      socketName()))
         msg += '\n\n\n' + i18n('Please try again')
     self.dlg = None
     if msg:
         logWarning(msg)
     raise CancelledError
示例#3
0
 def serverListening(self):
     """is somebody listening on that port?"""
     if self.useSocket and os.name != 'nt':
         sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
         sock.settimeout(1)
         try:
             sock.connect(socketName())
         except socket.error as exception:
             if os.path.exists(socketName()):
                 # try again, avoiding a race
                 try:
                     sock.connect(socketName())
                 except socket.error as exception:
                     if removeIfExists(socketName()):
                         logInfo(m18n('removed stale socket <filename>%1</filename>', socketName()))
                     logInfo('socket error:%s' % str(exception))
                     return False
                 else:
                     return True
         else:
             return True
     else:
         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         sock.settimeout(1)
         try:
             sock.connect((self.dlg.host, self.dlg.port))
         except socket.error:
             return False
         else:
             return True
示例#4
0
文件: login.py 项目: zero804/kajongg
 def __startLocalServer(self):
     """start a local server"""
     try:
         args = self.__findServerProgram()
         if self.useSocket or os.name == 'nt':  # for nt --socket tells the server to bind to 127.0.0.1
             args.append('--socket=%s' % socketName())
             if removeIfExists(socketName()):
                 logInfo(
                     i18n('removed stale socket <filename>%1</filename>',
                          socketName()))
         if not self.useSocket:
             args.append('--port=%d' % self.port)
         if self.isLocalGame:
             args.append('--db={}'.format(
                 os.path.normpath(os.path.join(appdataDir(), 'local3.db'))))
         if Debug.argString:
             args.append('--debug=%s' % Debug.argString)
         if os.name == 'nt':
             startupinfo = subprocess.STARTUPINFO()
             startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
         else:
             startupinfo = None
         process = subprocess.Popen(
             args, startupinfo=startupinfo)  # , shell=os.name == 'nt')
         if Debug.connections:
             logDebug(
                 i18n(
                     'started the local kajongg server: pid=<numid>%1</numid> %2',
                     process.pid, ' '.join(args)))
     except OSError as exc:
         exc.filename = ' '.join(args)
         logException(exc)
示例#5
0
 def serverListening(self):
     """is somebody listening on that port?"""
     if self.useSocket and os.name != 'nt':
         sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
         sock.settimeout(1)
         try:
             sock.connect(socketName())
         except socket.error as exception:
             if os.path.exists(socketName()):
                 # try again, avoiding a race
                 try:
                     sock.connect(socketName())
                 except socket.error as exception:
                     if removeIfExists(socketName()):
                         logInfo(
                             m18n(
                                 'removed stale socket <filename>%1</filename>',
                                 socketName()))
                     logInfo('socket error:%s' % str(exception))
                     return False
                 else:
                     return True
         else:
             return True
     else:
         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         sock.settimeout(1)
         try:
             sock.connect((self.dlg.host, self.dlg.port))
         except socket.error:
             return False
         else:
             return True
示例#6
0
 def stop(self, job=None):
     """maybe stop the server"""
     if self not in self.servers:
         # already stopped
         return
     if job:
         self.jobs.remove(job)
     if len(self.jobs) == 0:
         self.servers.remove(self)
         if self.process:
             try:
                 self.process.terminate()
                 self.process.wait()
             except OSError:
                 pass
             print('{} killed'.format(self))
         if self.socketName:
             removeIfExists(self.socketName)
示例#7
0
 def _loginReallyFailed(self, failure):
     """login failed, not fixable by adding missing user"""
     msg = self._prettifyErrorMessage(failure)
     if failure.check(CancelledError):
         # show no warning, just leave
         return failure
     if 'Errno 5' in msg:
         # The server is running but something is wrong with it
         if self.useSocket and os.name != 'nt':
             if removeIfExists(socketName()):
                 logInfo(m18n('removed stale socket <filename>%1</filename>', socketName()))
             msg += '\n\n\n' + m18n('Please try again')
     logWarning(msg)
     return failure
示例#8
0
 def __computeMd5sum(self):
     """update md5sum file. If it changed, return True.
     If unchanged or no ogg files exist, remove archive and md5sum and return False.
     If ogg files exist but no archive, return True."""
     if self.__md5sum:
         # we already checked
         return
     md5FileName = os.path.join(self.directory, 'md5sum')
     archiveExists = os.path.exists(self.archiveName())
     ogg = self.oggFiles()
     if not ogg:
         removeIfExists(self.archiveName())
         removeIfExists(md5FileName)
         self.__md5sum = None
         logDebug('no ogg files in %s' % self)
         return
     md5sum = md5()
     for oggFile in ogg:
         md5sum.update(open(os.path.join(self.directory, oggFile)).read())
     # the md5 stamp goes into the old archive directory 'username'
     self.__md5sum = md5sum.hexdigest()
     existingMd5sum = self.savedmd5Sum()
     md5Name = self.md5FileName()
     if self.__md5sum != existingMd5sum:
         if Debug.sound:
             if not os.path.exists(md5Name):
                 logDebug('creating new %s' % md5Name)
             else:
                 logDebug('md5sum %s changed, rewriting %s with %s' % (existingMd5sum, md5Name, self.__md5sum))
         try:
             open(md5Name, 'w').write('%s\n' % self.__md5sum)
         except BaseException as exception:
             logException(m18n('cannot write <filename>%1</filename>: %2', md5Name, str(exception)))
     if archiveExists:
         archiveIsOlder = os.path.getmtime(md5Name) > os.path.getmtime(self.archiveName())
         if self.__md5sum != existingMd5sum or archiveIsOlder:
             os.remove(self.archiveName())
示例#9
0
 def _loginReallyFailed(self, failure):
     """login failed, not fixable by adding missing user"""
     msg = self._prettifyErrorMessage(failure)
     if failure.check(CancelledError):
         # show no warning, just leave
         return failure
     if 'Errno 5' in msg:
         # The server is running but something is wrong with it
         if self.useSocket and os.name != 'nt':
             if removeIfExists(socketName()):
                 logInfo(
                     m18n('removed stale socket <filename>%1</filename>',
                          socketName()))
             msg += '\n\n\n' + m18n('Please try again')
     logWarning(msg)
     return failure
示例#10
0
def stopServers(serverProcesses):
    """stop server processes"""
    for process, socketName in serverProcesses:
        process.terminate()
        _ = process.wait()
        removeIfExists(socketName)
示例#11
0
def stopServers(serverProcesses):
    """stop server processes"""
    for process, socketName in serverProcesses:
        process.terminate()
        _ = process.wait()
        removeIfExists(socketName)