Josh VanderLinden avatar Josh VanderLinden committed 9717745

Making the port strictly a config file option

Comments (0)

Files changed (6)

 syntax: glob
+dist/
 *.pyc
 *.swp
 clip2zeus/globals.py
 clip2zeus/gui.py
 clip2zeus/linux.py
+clip2zeus/linux_gtk.py
+clip2zeus/linux_kde.py
 clip2zeus/main.py
 clip2zeus/osx.py
 clip2zeus/win32.py

clip2zeus/__init__.py

 APP_TITLE = 'Clip2Zeus'
 __author__ = 'Josh VanderLinden'
-__version__ = '1.5a'
+__version__ = '1.6a'
 

clip2zeus/clip2zeus_ctl.py

 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
-from clip2zeus.common import Clip2ZeusApp, Clip2ZeusCtl, DEFAULT_PORT
+from clip2zeus.common import Clip2ZeusApp, Clip2ZeusCtl
 
 def main():
     from optparse import OptionParser
     import sys
 
     parser = OptionParser()
-    parser.add_option('-p', '--port', dest='port', default=DEFAULT_PORT, help='The port for the daemon to listen on')
     options, args = parser.parse_args()
 
     if len(args) < 1:
         sys.exit('Please specify a command: %s' % ', '.join(Clip2ZeusApp.EXPOSED))
 
-    params = dict(
-        port=options.port,
-    )
-
-    Clip2ZeusCtl(**params).execute_command(args.pop(0), args)
+    Clip2ZeusCtl().execute_command(args.pop(0), args)
 
 if __name__ == '__main__':
     main()

clip2zeus/common.py

     EXPOSED = ('help', 'get_version', 'get_interval', 'set_interval',
                'shorten_urls', 'quit', 'get_api_key', 'set_api_key')
 
-    def __init__(self, port=DEFAULT_PORT):
+    def __init__(self):
         """Creates the container for common functionality"""
 
         logger.debug('Welcome to %s v%s' % (APP_TITLE, __version__))
         logger.debug('** Using class %s **' % (self.__class__.__name__,))
 
-        try:
-            self.port = int(port)
-        except ValueError:
-            self.port = DEFAULT_PORT
-
         self.data = ''
         self.server = None
         self._has_connection = False
         self.last_check = None
         self.interval = config.getint('main', 'interval', 1)
         self.api_key = config.get('main', 'api_key', '').replace('|', ':')
+        self.port = config.getint('main', 'port', DEFAULT_PORT)
 
         logging.debug('API Key: %s' % self.api_key)
 
     after backgrounding it.
     """
 
-    def __init__(self, port=DEFAULT_PORT):
-        self.port = port
+    def __init__(self):
+        self.port = config.getint('main', 'port', DEFAULT_PORT)
         self.proxy = None
         self.connect()
 
         except xmlrpclib.Fault, fault:
             self.notify('%s' % (fault, ))
 
-    def connect(self, port=DEFAULT_PORT):
+    def connect(self):
         """Attempt to connect to the XML-RPC server"""
 
         logger.debug('Connecting to XML-RPC server')
-        if port_is_free(port):
+        if port_is_free(self.port):
             logger.error('Port is not in use')
             sys.exit(1)
 
         try:
-            port = port or self.port
-            self.proxy = xmlrpclib.ServerProxy('http://localhost:%s/' % port, allow_none=True)
+            self.proxy = xmlrpclib.ServerProxy('http://localhost:%s/' % self.port, allow_none=True)
         except Exception, e:
             logger.error('%s' % (e, ))
             raise e
-        else:
-            self.port = port
 
     def help(self, func=None):
         """Calls the help function on the server"""

clip2zeus/main.py

 using 2ze.us
 """
 
-from clip2zeus.common import *
+from clip2zeus.common import Clip2ZeusApp
 
 def main():
-    from optparse import OptionParser
-
-    parser = OptionParser()
-    parser.add_option('-p', '--port', dest='port', default=DEFAULT_PORT, help='The port for the daemon to listen on')
-    options, args = parser.parse_args()
-
-    params = dict(
-        port=options.port,
-    )
-
     clip2zeus = Clip2ZeusApp.for_platform()
-    clip2zeus(**params).start()
+    clip2zeus().start()
 
 if __name__ == '__main__':
     main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.