Ejemplo n.º 1
0
 def _chooseTargetDir(self):
     defaultDir = os.path.expanduser('~/Desktop')
     if not os.path.isdir(defaultDir):
         defaultDir = QString()
     dir = localSettings().getString('Settings/FileReceiverSaveDir')
     if (not dir) or (not os.path.isdir(dir)):
         dir = defaultDir
     while True:
         dir = QFileDialog.getExistingDirectory(
             self, 'Choose directory to save the file(s)', dir)
         if dir.isEmpty(): return None
         dir = str(dir)
         existing = []
         for f in self.files:
             if os.path.exists(os.path.join(dir, f)): existing.append(f)
         if not existing: break
         msg = 'The following file(s) already exist in\n%s.\nWould you like to overwrite?\n%s' % (
             dir, '\n'.join(existing))
         result = QMessageBox.question(
             self, 'Overwrite Prompt', msg, QMessageBox.Yes, QMessageBox.No,
             QMessageBox.Cancel | QMessageBox.Escape)
         if result == QMessageBox.Yes: break
         if result == QMessageBox.No: continue
         assert result == QMessageBox.Cancel
         return None
     localSettings().setString('Settings/FileReceiverSaveDir', dir)
     return dir
Ejemplo n.º 2
0
 def _onAddClicked( self ) :
     defaultDir = os.path.expanduser( '~/Desktop' )
     if not os.path.isdir(defaultDir) :
         defaultDir = ''
     openDir = localSettings().getString( 'Settings/FileSenderOpenDir' )
     if (not openDir) or (not os.path.isdir(openDir)) :
         openDir = defaultDir
     fileList = QFileDialog.getOpenFileNames( self, 'Select file(s) to add...', openDir )
     for f in fileList :
         self._addFile( str(f) )
     if len(fileList) :
         openDir = os.path.split( str(fileList[0]) )[0]
         localSettings().setString( 'Settings/FileSenderOpenDir', openDir )
     self._onFileSelectionChanged()
Ejemplo n.º 3
0
def main() :
    try :
        nodeAddr = readAddr( sys.argv[1] )
    except :
        nodeAddr = ('208.78.96.185', 10001) # ('210.210.1.102',10001) 
    seedNodes = [nodeAddr]
    app = QApplication( sys.argv )
    icon = QIcon()
    for iconSize in [48,32,24,16] :
        icon.addPixmap( QPixmap(':/images/cspace%d.png'%iconSize) )
    app.setWindowIcon( icon )
    app.setQuitOnLastWindowClosed( False )
    reactor = Qt4Reactor()
    if not checkSettingsVersion() :
        return
    logFile = LogFile( localSettings() )
    sys.stdout = logFile
    sys.stderr = logFile
    logging.getLogger().addHandler( logging.StreamHandler() )
    initdelaygc( reactor )
    mainWin = MainWindow( seedNodes, reactor )
    mainWin.show()
    app.exec_()
    global execFileAfterExit
    if execFileAfterExit is not None :
        p = execFileAfterExit
        args = [p]
        startingDir = os.path.split( p )[0]
        spawnProcess( p, args, os.environ, startingDir, 0 )
Ejemplo n.º 4
0
 def _onAddClicked(self):
     defaultDir = os.path.expanduser('~/Desktop')
     if not os.path.isdir(defaultDir):
         defaultDir = ''
     openDir = localSettings().getString('Settings/FileSenderOpenDir')
     if (not openDir) or (not os.path.isdir(openDir)):
         openDir = defaultDir
     fileList = QFileDialog.getOpenFileNames(self,
                                             'Select file(s) to add...',
                                             openDir)
     for f in fileList:
         self._addFile(str(f))
     if len(fileList):
         openDir = os.path.split(str(fileList[0]))[0]
         localSettings().setString('Settings/FileSenderOpenDir', openDir)
     self._onFileSelectionChanged()
Ejemplo n.º 5
0
def main():
    global logger, reactor
    options, args = _parseCommandLine()
    settings = localSettings()

    if not options.debug:
        sys.stdout = sys.stderr = LogFile(settings)
        logger.setLevel(logging.INFO)
    else:
        logger.setLevel(logging.DEBUG)
    logger.addHandler(logging.StreamHandler())
    logging.getLogger("nitro.selectreactor").addHandler(logging.StreamHandler())

    reactor = SelectReactor()
    seedNodes = [(options.dhtnode, options.dhtport)]
    service = CSpaceService(seedNodes, settings, reactor)
    server = SimpleXMLRPCServer(("localhost", options.xmlport))
    reactor.addReadCallback(server, server.handle_request)
    server.register_instance(service, allow_dotted_names=True)

    xmlrpcport = server.socket.getsockname()[1]
    logger.info("rpcserver listenport = %i" % xmlrpcport)
    appletport = service.appletServer.listenPort
    logger.info("seed nodes = (%s:%i)" % (options.dhtnode, options.dhtport))
    _writePID(xmlrpcport, appletport)
    service.run()
    _deletePID()
    logger.info("server stopped.")
Ejemplo n.º 6
0
def main() :
    try :
        nodeAddr = readAddr( sys.argv[1] )
    except :
        nodeAddr = ('210.210.1.102',10001)
    seedNodes = [nodeAddr]
    app = QApplication( sys.argv )
    icon = QIcon()
    for iconSize in [48,32,24,16] :
        icon.addPixmap( QPixmap(':/images/cspace%d.png'%iconSize) )
    app.setWindowIcon( icon )
    app.setQuitOnLastWindowClosed( False )
    reactor = Qt4Reactor()
    if not checkSettingsVersion() :
        return
    logFile = LogFile( localSettings() )
    sys.stdout = logFile
    sys.stderr = logFile
    logging.getLogger().addHandler( logging.StreamHandler() )
    initdelaygc( reactor )
    mainWin = MainWindow( seedNodes, reactor )
    mainWin.show()
    app.exec_()
    global execFileAfterExit
    if execFileAfterExit is not None :
        p = execFileAfterExit
        args = [p]
        startingDir = os.path.split( p )[0]
        spawnProcess( p, args, os.environ, startingDir, 0 )
Ejemplo n.º 7
0
 def __init__(self, fileName):
     configDir = localSettings().getConfigDir()
     logFile = os.path.join(configDir, fileName)
     try:
         if os.path.getsize(logFile) >= 1024 * 1024:
             os.remove(logFile)
     except OSError:
         pass
     self.f = file(logFile, 'a')
Ejemplo n.º 8
0
 def __init__( self, fileName ) :
     configDir = localSettings().getConfigDir()
     logFile = os.path.join( configDir, fileName )
     try :
         if os.path.getsize(logFile) >= 1024*1024 :
             os.remove( logFile )
     except OSError :
         pass
     self.f = file( logFile, 'a' )
Ejemplo n.º 9
0
def _loadNodeCache( nodeTable ) :
    data = localSettings().getData( 'NodeCache', '' )
    for addr in data.split() :
        try :
            ip,port = addr.split( ':' )
            port = int(port)
            nodeAddr = (ip,port)
            validateInetAddress( nodeAddr )
        except :
            continue
        nodeTable.addNode( nodeAddr )
Ejemplo n.º 10
0
def _loadNodeCache(nodeTable):
    data = localSettings().getData('NodeCache', '')
    for addr in data.split():
        try:
            ip, port = addr.split(':')
            port = int(port)
            nodeAddr = (ip, port)
            validateInetAddress(nodeAddr)
        except:
            continue
        nodeTable.addNode(nodeAddr)
Ejemplo n.º 11
0
 def __init__(self, settings=None, appName="CSpace"):
     if settings is None:
         settings = localSettings()
     configDir = settings.getConfigDir()
     logFile = os.path.join(configDir, "%s.log" % appName)
     try:
         if os.path.getsize(logFile) >= 1024 * 1024:
             os.remove(logFile)
     except OSError:
         pass
     self.f = file(logFile, "a")
Ejemplo n.º 12
0
 def _chooseTargetDir( self ) :
     defaultDir = os.path.expanduser( '~/Desktop' )
     if not os.path.isdir(defaultDir) :
         defaultDir = QString()
     dir = localSettings().getString( 'Settings/FileReceiverSaveDir' )
     if (not dir) or (not os.path.isdir(dir)) :
         dir = defaultDir
     while True :
         dir = QFileDialog.getExistingDirectory( self, 'Choose directory to save the file(s)',
                 dir )
         if dir.isEmpty() : return None
         dir = str(dir)
         existing = []
         for f in self.files :
             if os.path.exists(os.path.join(dir,f)) : existing.append(f)
         if not existing : break
         msg = 'The following file(s) already exist in\n%s.\nWould you like to overwrite?\n%s' % (dir,'\n'.join(existing))
         result = QMessageBox.question( self, 'Overwrite Prompt', msg, QMessageBox.Yes, QMessageBox.No, QMessageBox.Cancel|QMessageBox.Escape )
         if result == QMessageBox.Yes : break
         if result == QMessageBox.No : continue
         assert result == QMessageBox.Cancel
         return None
     localSettings().setString( 'Settings/FileReceiverSaveDir', dir )
     return dir
Ejemplo n.º 13
0
 def on_actionExit_triggered( self ) :
     self._cancelReconnect()
     if self.sm.current() == self.ONLINE :
         self.exitAfterOffline = True
         self.session.goOffline()
     else :
         self.exitAfterOffline = False
         self.appletServer.shutdown()
         self.session.shutdown()
         if self.trayIcon is not None :
             self.trayIcon.hide()
         st = localSettings()
         st.setInt( 'Settings/WindowWidth', self.width() )
         st.setInt( 'Settings/WindowHeight', self.height() )
         qApp.exit( 0 )
Ejemplo n.º 14
0
 def on_actionExit_triggered( self ) :
     self._cancelReconnect()
     if self.sm.current() == self.ONLINE :
         self.exitAfterOffline = True
         self.session.goOffline()
     else :
         self.exitAfterOffline = False
         self.appletServer.shutdown()
         self.session.shutdown()
         if self.trayIcon is not None :
             self.trayIcon.hide()
         st = localSettings()
         st.setInt( 'Settings/WindowWidth', self.width() )
         st.setInt( 'Settings/WindowHeight', self.height() )
         qApp.exit( 0 )
Ejemplo n.º 15
0
 def _doCheckSettings( self ) :
     st = localSettings()
     windowWidth = st.getInt( 'Settings/WindowWidth', 0 )
     windowHeight = st.getInt( 'Settings/WindowHeight', 0 )
     if (windowWidth > 0) and (windowHeight > 0) :
         windowWidth = max( windowWidth, 100 )
         windowHeight = max( windowHeight, 100 )
         self.resize( QSize(windowWidth,windowHeight).expandedTo(self.minimumSizeHint()) )
     profiles = listProfiles()
     entries = [entry for userName,keyId,entry in profiles]
     if st.getInt('Settings/RememberKey',0) :
         entry = st.getString('Settings/SavedProfile')
         password = st.getString('Settings/SavedPassword')
         if entry and password and (entry in entries) :
             profile = loadProfile( entry, password )
             if profile :
                 self._doGoOnline( profile )
Ejemplo n.º 16
0
 def _doCheckSettings( self ) :
     st = localSettings()
     windowWidth = st.getInt( 'Settings/WindowWidth', 0 )
     windowHeight = st.getInt( 'Settings/WindowHeight', 0 )
     if (windowWidth > 0) and (windowHeight > 0) :
         windowWidth = max( windowWidth, 100 )
         windowHeight = max( windowHeight, 100 )
         self.resize( QSize(windowWidth,windowHeight).expandedTo(self.minimumSizeHint()) )
     profiles = listProfiles()
     entries = [entry for userName,keyId,entry in profiles]
     if st.getInt('Settings/RememberKey',0) :
         entry = st.getString('Settings/SavedProfile')
         password = st.getString('Settings/SavedPassword')
         if entry and password and (entry in entries) :
             profile = loadProfile( entry, password )
             if profile :
                 self._doGoOnline( profile )
Ejemplo n.º 17
0
 def __init__( self, parent ) :
     QDialog.__init__( self, parent )
     self.ui = Ui_GoOnlineDialog()
     self.ui.setupUi( self )
     self.profiles = listProfiles()
     for userName,keyId,entry in self.profiles :
         text = userName
         if keyId :
             text += ' (KeyID: %s)' % keyId
         self.ui.keys.addItem( QString(text) )
     entries = [entry for userName,keyId,entry in self.profiles]
     st = localSettings()
     if st.getInt('Settings/RememberKey',0) :
         self.ui.rememberKey.setChecked( True )
         entry = st.getString( 'Settings/SavedProfile' )
         password = st.getString( 'Settings/SavedPassword' )
         if entry and password and (entry in entries) :
             self.ui.keys.setCurrentIndex( entries.index(entry) )
             self.ui.password.setText( password )
     else :
         self.ui.rememberKey.setChecked( False )
Ejemplo n.º 18
0
 def __init__(self, parent):
     QDialog.__init__(self, parent)
     self.ui = Ui_GoOnlineDialog()
     self.ui.setupUi(self)
     self.profiles = listProfiles()
     for userName, keyId, entry in self.profiles:
         text = userName
         if keyId:
             text += ' (KeyID: %s)' % keyId
         self.ui.keys.addItem(QString(text))
     entries = [entry for userName, keyId, entry in self.profiles]
     st = localSettings()
     if st.getInt('Settings/RememberKey', 0):
         self.ui.rememberKey.setChecked(True)
         entry = st.getString('Settings/SavedProfile')
         password = st.getString('Settings/SavedPassword')
         if entry and password and (entry in entries):
             self.ui.keys.setCurrentIndex(entries.index(entry))
             self.ui.password.setText(password)
     else:
         self.ui.rememberKey.setChecked(False)
Ejemplo n.º 19
0
 def on_goOnlineButton_clicked( self ) :
     entryIndex = self.ui.keys.currentIndex()
     if entryIndex < 0 : return
     entry = self.profiles[entryIndex][2]
     password = unicode(self.ui.password.text()).encode('utf8')
     profile = loadProfile( entry, password )
     if profile is None :
         QMessageBox.critical( self, 'Error', 'Invalid Password.' )
         self.ui.password.setFocus()
         self.ui.password.selectAll()
         return
     self.profile = profile
     st = localSettings()
     if self.ui.rememberKey.isChecked() :
         st.setInt( 'Settings/RememberKey', 1 )
         st.setString( 'Settings/SavedProfile', profile.storeEntry )
         st.setString( 'Settings/SavedPassword', password )
     else :
         st.setInt( 'Settings/RememberKey', 0 )
         st.remove( 'Settings/SavedProfile' )
         st.remove( 'Settings/SavedPassword' )
     self.accept()
Ejemplo n.º 20
0
 def on_goOnlineButton_clicked(self):
     entryIndex = self.ui.keys.currentIndex()
     if entryIndex < 0: return
     entry = self.profiles[entryIndex][2]
     password = unicode(self.ui.password.text()).encode('utf8')
     profile = loadProfile(entry, password)
     if profile is None:
         QMessageBox.critical(self, 'Error', 'Invalid Password.')
         self.ui.password.setFocus()
         self.ui.password.selectAll()
         return
     self.profile = profile
     st = localSettings()
     if self.ui.rememberKey.isChecked():
         st.setInt('Settings/RememberKey', 1)
         st.setString('Settings/SavedProfile', profile.storeEntry)
         st.setString('Settings/SavedPassword', password)
     else:
         st.setInt('Settings/RememberKey', 0)
         st.remove('Settings/SavedProfile')
         st.remove('Settings/SavedPassword')
     self.accept()
Ejemplo n.º 21
0
    def __init__(self, seedNodes, settings=None, reactor=None):
        global logger
        logger.info("CSpaceService init")
        if reactor is None:
            reactor = SelectReactor()

        if settings is None:
            settings = localSettings()

        self.reactor = reactor
        self.settings = settings
        self.dispatcher = Eventer()
        self.seedNodes = seedNodes

        # Session Manager
        self.session = UserSession(self.seedNodes, reactor)

        # Our user profile
        self.profile = None

        # Session status State Machine
        self.sm = self.session.sm
        # Make sure we handle the edges/state transitions
        self.sm.insertCallback(self._onStateChange)
        # Manage actions
        self.actionManager = ActionManager()
        # Loads applets in subprocesses
        self.appletServer = AppletServer(self.session, self.actionManager, self.reactor)

        # Our contacts' statii
        self.statusProbe = ContactStatusChecker(self, reactor)

        # Our current status
        self.status = self.sm.current()
        self.statusmsg = self.STATII[self.status]
        self.exitAfterOffline = False

        self.reactor.callLater(0, self._onStarted)
Ejemplo n.º 22
0
def checkSettingsVersion() :
    s = localSettings()
    if not s.listEntries('') :
        s.setInt( 'SettingsVersion', SETTINGS_VERSION )
        return True
    version = s.getInt( 'SettingsVersion', -1 )
    if version == SETTINGS_VERSION : return True
    result = QMessageBox.information( None, 'Settings Update',
            'CSpace Settings format has changed. Old settings will be removed.\n' +
            'Press OK to remove data and continue.\n' +
            'Press CANCEL to exit CSpace.\n' +
            'Remove data in %s?' % s.getConfigDir(),
            QMessageBox.Ok,
            QMessageBox.Cancel | QMessageBox.Escape )
    if result != QMessageBox.Ok : return False
    for entry in s.listEntries('') :
        result = s.remove( entry )
        if not result :
            QMessageBox.critical( None, 'Error',
                    'Unable to delete entry: %s' % entry )
            return False
    s.setInt( 'SettingsVersion', SETTINGS_VERSION )
    return True
Ejemplo n.º 23
0
def checkSettingsVersion() :
    s = localSettings()
    if not s.listEntries('') :
        s.setInt( 'SettingsVersion', SETTINGS_VERSION )
        return True
    version = s.getInt( 'SettingsVersion', -1 )
    if version == SETTINGS_VERSION : return True
    result = QMessageBox.information( None, 'Settings Update',
            'CSpace Settings format has changed. Old settings will be removed.\n' +
            'Press OK to remove data and continue.\n' +
            'Press CANCEL to exit CSpace.\n' +
            'Remove data in %s?' % s.getConfigDir(),
            QMessageBox.Ok,
            QMessageBox.Cancel | QMessageBox.Escape )
    if result != QMessageBox.Ok : return False
    for entry in s.listEntries('') :
        result = s.remove( entry )
        if not result :
            QMessageBox.critical( None, 'Error',
                    'Unable to delete entry: %s' % entry )
            return False
    s.setInt( 'SettingsVersion', SETTINGS_VERSION )
    return True
Ejemplo n.º 24
0
 def on_actionCreateKey_triggered( self ) :
     self._cancelReconnect()
     dlg = CreateKeyDialog( self, self.reactor )
     result = dlg.exec_()
     if result == QDialog.Rejected : return
     userName = dlg.userName
     password = dlg.password
     rsaKey = dlg.rsaKey
     keyId = dlg.keyId
     profile = createProfile( rsaKey, password, userName, keyId )
     dlg = CreateKeyDoneDialog( self, keyId )
     result = dlg.exec_()
     if result == QDialog.Rejected : return
     st = localSettings()
     if dlg.rememberKey :
         st.setInt( 'Settings/RememberKey', 1 )
         st.setString( 'Settings/SavedProfile', profile.storeEntry )
         st.setString( 'Settings/SavedPassword', password )
     else :
         st.setInt( 'Settings/RememberKey', 0 )
         st.remove( 'Settings/SavedProfile' )
         st.remove( 'Settings/SavedPassword' )
     self._updateUI()
     self._doGoOnline( profile )
Ejemplo n.º 25
0
 def on_actionCreateKey_triggered( self ) :
     self._cancelReconnect()
     dlg = CreateKeyDialog( self, self.reactor )
     result = dlg.exec_()
     if result == QDialog.Rejected : return
     userName = dlg.userName
     password = dlg.password
     rsaKey = dlg.rsaKey
     keyId = dlg.keyId
     profile = createProfile( rsaKey, password, userName, keyId )
     dlg = CreateKeyDoneDialog( self, keyId )
     result = dlg.exec_()
     if result == QDialog.Rejected : return
     st = localSettings()
     if dlg.rememberKey :
         st.setInt( 'Settings/RememberKey', 1 )
         st.setString( 'Settings/SavedProfile', profile.storeEntry )
         st.setString( 'Settings/SavedPassword', password )
     else :
         st.setInt( 'Settings/RememberKey', 0 )
         st.remove( 'Settings/SavedProfile' )
         st.remove( 'Settings/SavedPassword' )
     self._updateUI()
     self._doGoOnline( profile )
Ejemplo n.º 26
0
def _saveNodeCache( nodeTable ) :
    out = StringIO.StringIO()
    for addr in nodeTable.getAllNonSeedNodes() :
        print>>out, '%s:%d' % addr
    return localSettings().setData( 'NodeCache', out.getvalue() )
Ejemplo n.º 27
0
 def listUserServices( self ) :
     return self._listServices( localSettings() )
Ejemplo n.º 28
0
 def listUserActions( self ) :
     return self._listActions( localSettings() )
Ejemplo n.º 29
0
def _saveNodeCache(nodeTable):
    out = StringIO.StringIO()
    for addr in nodeTable.getAllNonSeedNodes():
        print >> out, '%s:%d' % addr
    return localSettings().setData('NodeCache', out.getvalue())