Permalink
Browse files

fixed pylint and pep8 warnings

  • Loading branch information...
1 parent a1e4d79 commit 6c7c0a6519ac99ef559f3654bb67625a804c733f @trey0 trey0 committed Sep 21, 2011
@@ -4,15 +4,21 @@
# All Rights Reserved.
# __END_LICENSE__
+# disable bogus pylint warnings about missing class members
+# pylint: disable=E1101
+
from geocamPycroraptor.Printable import Printable
from geocamPycroraptor.SubscriberSet import SubscriberSet
+
class BaseTask(Printable):
def __init__(self, name, parent):
+ # pylint: disable=W0231
self.name = name
self._parent = parent
self._env = parent._env['settings']['tasks'][name]
self._statusSubscribers = SubscriberSet()
+ self.status = None
def setStatus(self, status):
self.status = status
@@ -22,7 +28,7 @@ def isRunning(self):
return self.status != None and self.status['status'] == 'running'
def isLocal(self):
- pass # implement in derived class
+ pass # implement in derived class
def _getConfig(self, field):
return self._expandWithPid(self._env[field])
@@ -31,8 +37,10 @@ def _getConfig(self, field):
# functions to be called from client
######################################################################
- def start(self, params={}):
+ def start(self, params=None):
'''return 1 if a task was started'''
+ if params == None:
+ params = {}
if self.isRunning():
return 0
else:
@@ -46,8 +54,8 @@ def stop(self):
return 1
else:
return 0
-
- def restart(self, params={}):
+
+ def restart(self, params=None):
'''return status before restart'''
pass
@@ -63,5 +71,3 @@ def writeStdin(self, text):
def cleanup(self):
pass
-
-
@@ -4,19 +4,24 @@
# All Rights Reserved.
# __END_LICENSE__
-import optparse, sys, code, platform, os
-
+import sys
+import platform
+import os
from cStringIO import StringIO
+
from geocamPycroCom.Dispatcher import Dispatcher
from geocamPycroCom.SharedScheduler import scheduler, ExitSchedulerLoop
from geocamPycroraptor import commandLineOptions
from geocamPycroraptor.DaemonProxy import DaemonProxy
from geocamPycroraptor import anyjson as json
+
class Client:
def __init__(self, opts=None):
self._opts = opts
self._needPrompt = True
+ self._com = None
+ self._proxy = None
def _printIfInteractive(self, text):
if self._opts.startupCommand == None:
@@ -28,7 +33,7 @@ def _prompt(self):
def _queuePrompt(self):
self._needPrompt = True
- scheduler.enterSimple(delay = 0.05, action = self._checkPrompt)
+ scheduler.enterSimple(delay=0.05, action=self._checkPrompt)
def _checkPrompt(self):
if self._needPrompt:
@@ -52,7 +57,7 @@ def handleDaemonConnect(self, sock):
def makeStatusHumanReadable(self, result):
statusDict = result['status']
statusPairs = statusDict.items()
- statusPairs.sort(key = lambda pair: pair[0].lower())
+ statusPairs.sort(key=lambda pair: pair[0].lower())
if len(statusPairs) == 1:
return '%s' % statusPairs[0][1]
else:
@@ -61,7 +66,7 @@ def makeStatusHumanReadable(self, result):
for taskName, info in statusPairs:
secondaryInfo = ['%s=%s' % (k, info[k])
for k in ('pid', 'sigName', 'sigVerbose', 'returnValue')
- if info.has_key(k)]
+ if k in info]
out.write(' %-20s %-11s %s\n' % (taskName, info['procStatus'],
' '.join(secondaryInfo)))
out.write('\n')
@@ -70,7 +75,7 @@ def makeStatusHumanReadable(self, result):
def makeOkResponseHumanReadable(self, result):
if isinstance(result, dict) and len(result) == 1:
- if result.has_key('status'):
+ if 'status' in result:
return self.makeStatusHumanReadable(result)
else:
return '%s' % result.values()[0]
@@ -79,19 +84,19 @@ def makeOkResponseHumanReadable(self, result):
return 'ok'
else:
return 'ok %s' % result
-
+
def makeHumanReadable(self, line):
if line.startswith('#'):
return line
else:
cmd = json.loads(line)
if (cmd and cmd[0] == 'response'):
- response, lineId, returnCode = cmd[:3]
+ _response, _lineId, returnCode = cmd[:3]
result = cmd[3:]
if returnCode == 'ok':
return self.makeOkResponseHumanReadable(result[0])
else:
- return ' '.join([returnCode] + result)
+ return ' '.join([returnCode] + result)
else:
return line
@@ -101,18 +106,18 @@ def handleDaemonLine(self, sock, line):
self._queuePrompt()
def runx(self):
- self._com = Dispatcher(moduleName = 'client-%s-%d' % (platform.node(), os.getpid()))
+ self._com = Dispatcher(moduleName='client-%s-%d' % (platform.node(), os.getpid()))
self._proxy = DaemonProxy(self._opts,
- dispatcher = self._com,
- lineHandler = self.handleDaemonLine,
- connectHandler = self.handleDaemonConnect)
+ dispatcher=self._com,
+ lineHandler=self.handleDaemonLine,
+ connectHandler=self.handleDaemonConnect)
self._proxy.open()
- self._com.connect('console:', lineHandler = self.handleStdinLine)
+ self._com.connect('console:', lineHandler=self.handleStdinLine)
self._printIfInteractive('example commands: "start bc", "stop bc", "get status.bc"\n')
self._prompt()
self._com.runForever()
@staticmethod
def run(argv):
- opts, args = commandLineOptions.getClientOptsArgs(argv)
+ opts, _args = commandLineOptions.getClientOptsArgs(argv)
Client(opts).runx()
@@ -6,38 +6,50 @@
from geocamPycroraptor.Printable import Printable
+
class ConfigDict(Printable):
def __init__(self, updateDict=None, **kwargs):
+ # pylint: disable=W0231
self.__dict__['_contents'] = {}
self.plusEquals(updateDict, **kwargs)
+
def plusEquals(self, updateDict=None, **kwargs):
if updateDict != None:
self._contents.update(updateDict)
self._contents.update(**kwargs)
return self
+
def copy(self):
return ConfigDict(self)
+
def plus(self, updateDict=None, **kwargs):
return self.copy().plusEquals(updateDict, **kwargs)
def __getitem__(self, k):
return self._contents.__getitem__(k)
+
def __setitem__(self, k, v):
self._contents.__setitem__(k, v)
+
def __delitem__(self, k):
self._contents.__delitem__(k)
+
def __contains__(self, k):
return self._contents.__contains__(k)
+
def __iter__(self):
return self._contents.__iter__()
+
def asDict(self):
return self._contents
+
def keys(self):
"""needed for myDict.update(myConfigDict) to work right. generally speaking,
can access dict methods using asDict(), e.g. myConfigDict.asDict().values()"""
return self._contents.keys()
def __getattr__(self, k):
return self._contents[k]
+
def __setattr__(self, k, v):
self._contents[k] = v
@@ -4,14 +4,12 @@
# All Rights Reserved.
# __END_LICENSE__
-from geocamPycroraptor.Printable import Printable
from geocamPycroraptor.ConfigDict import ConfigDict
-defaultProcessConfig = ConfigDict(cmd = '$name',
- workingDir = '/tmp',
- env = {},
- log = None,
- stopCmd = 'kill -TERM $pid',
- stopBackupCmd = 'kill -KILL $pid',
- stopBackupDelay = 5)
-
+defaultProcessConfig = ConfigDict(cmd='$name',
+ workingDir='/tmp',
+ env={},
+ log=None,
+ stopCmd='kill -TERM $pid',
+ stopBackupCmd='kill -KILL $pid',
+ stopBackupDelay=5)
Oops, something went wrong.

0 comments on commit 6c7c0a6

Please sign in to comment.