From be74286bd9ed428d77080ff66ebc7749929af2a3 Mon Sep 17 00:00:00 2001 From: Marco Mariani Date: Fri, 31 Oct 2014 12:20:18 +0100 Subject: [PATCH] removed dead code, petty cleanup --- slapos/cli/console.py | 2 -- slapos/cli/supervisorctl.py | 2 -- slapos/format.py | 2 -- slapos/grid/SlapObject.py | 4 ++-- slapos/grid/slapgrid.py | 16 +++++++++------- slapos/slap/slap.py | 15 ++++----------- 6 files changed, 15 insertions(+), 26 deletions(-) diff --git a/slapos/cli/console.py b/slapos/cli/console.py index dd421c3db..e0c33d217 100644 --- a/slapos/cli/console.py +++ b/slapos/cli/console.py @@ -27,8 +27,6 @@ # ############################################################################## -import textwrap - from slapos.cli.config import ClientConfigCommand from slapos.client import init, do_console, ClientConfig diff --git a/slapos/cli/supervisorctl.py b/slapos/cli/supervisorctl.py index 7cc38f83a..971b7e09c 100644 --- a/slapos/cli/supervisorctl.py +++ b/slapos/cli/supervisorctl.py @@ -34,8 +34,6 @@ from slapos.cli.command import check_root_user from slapos.cli.config import ConfigCommand from slapos.grid.svcbackend import launchSupervisord -from slapos.util import string_to_boolean - import supervisor.supervisorctl diff --git a/slapos/format.py b/slapos/format.py index 82f77f4a0..eaed8254d 100644 --- a/slapos/format.py +++ b/slapos/format.py @@ -46,7 +46,6 @@ import subprocess import sys import threading import time -import traceback import zipfile import lxml.etree @@ -1210,7 +1209,6 @@ class FormatConfig(object): attr = getattr(self, option) if isinstance(attr, str): if attr.lower() == 'true': - root_needed = True setattr(self, option, True) elif attr.lower() == 'false': setattr(self, option, False) diff --git a/slapos/grid/SlapObject.py b/slapos/grid/SlapObject.py index 2de23ce9d..4d6fec8fc 100644 --- a/slapos/grid/SlapObject.py +++ b/slapos/grid/SlapObject.py @@ -468,7 +468,7 @@ class Partition(object): self.logger.warning("Falling back to default buildout %r" % buildout_binary) else: - if len(bootstrap_candidate_list) != 1: + if len(bootstrap_candidate_list) > 1: raise ValueError('More than one bootstrap candidate found.') # Reads uid/gid of path, launches buildout with thoses privileges bootstrap_file = os.path.abspath(os.path.join(bootstrap_candidate_dir, @@ -529,7 +529,7 @@ class Partition(object): if os.path.exists(self.service_path): if os.path.isdir(self.service_path): service_list = os.listdir(self.service_path) - if len(runner_list) == 0 and len(service_list) == 0: + if not runner_list and not service_list: self.logger.warning('No runners nor services found for partition %r' % self.partition_id) if os.path.exists(self.supervisord_partition_configuration_path): diff --git a/slapos/grid/slapgrid.py b/slapos/grid/slapgrid.py index 4946e17ed..f3a10da95 100644 --- a/slapos/grid/slapgrid.py +++ b/slapos/grid/slapgrid.py @@ -329,15 +329,17 @@ class Slapgrid(object): self.buildout = buildout self.promise_timeout = promise_timeout self.develop = develop - if software_release_filter_list is not None: + + self.software_release_filter_list = [] + if software_release_filter_list: self.software_release_filter_list = \ software_release_filter_list.split(",") - else: - self.software_release_filter_list = [] + self.computer_partition_filter_list = [] - if computer_partition_filter_list is not None: + if computer_partition_filter_list: self.computer_partition_filter_list = \ computer_partition_filter_list.split(",") + self.maximum_periodicity = maximum_periodicity def getWatchdogLine(self): @@ -559,7 +561,7 @@ class Slapgrid(object): # Check if we defined explicit list of partitions to process. # If so, if current partition not in this list, skip. - if len(self.computer_partition_filter_list) > 0 and \ + if self.computer_partition_filter_list and \ (computer_partition_id not in self.computer_partition_filter_list): return @@ -877,7 +879,7 @@ class Slapgrid(object): self.logger.error(UnicodeError) raise UnicodeError("Failed to read %s: %s" % (computer_partition_usage.usage, exc)) except (etree.XMLSyntaxError, etree.DocumentInvalid) as exc: - self.logger.info("Failed to parse %s." % (computer_partition_usage.usage)) + self.logger.info("Failed to parse %s." % computer_partition_usage.usage) self.logger.error(exc) raise _formatXMLError(exc) except Exception as exc: @@ -985,7 +987,7 @@ class Slapgrid(object): clean_run = False failed_script_list.append("Script %r failed." % script) self.logger.warning('Failed to run %r' % invocation_list) - if len(failed_script_list): + if failed_script_list: computer_partition.error('\n'.join(failed_script_list), logger=self.logger) # Whatever happens, don't stop processing other instances except Exception: diff --git a/slapos/slap/slap.py b/slapos/slap/slap.py index 3465b68f0..751caa992 100644 --- a/slapos/slap/slap.py +++ b/slapos/slap/slap.py @@ -51,13 +51,6 @@ urllib3_logger = logging.getLogger('requests.packages.urllib3') urllib3_logger.setLevel(logging.WARNING) -# XXX fallback_logger to be deprecated together with the old CLI entry points. -fallback_logger = logging.getLogger(__name__) -fallback_handler = logging.StreamHandler() -fallback_logger.setLevel(logging.INFO) -fallback_logger.addHandler(fallback_handler) - - DEFAULT_SOFTWARE_TYPE = 'RootSoftwareInstance' class SlapDocument: @@ -133,7 +126,7 @@ class SoftwareRelease(SlapDocument): else: return self._software_release - def error(self, error_log, logger=None): + def error(self, error_log, logger): try: # Does not follow interface self._connection_helper.POST('softwareReleaseError', data={ @@ -141,7 +134,7 @@ class SoftwareRelease(SlapDocument): 'computer_id': self.getComputerId(), 'error_log': error_log}) except Exception: - (logger or fallback_logger).exception('') + logger.exception('') def available(self): self._connection_helper.POST('availableSoftwareRelease', data={ @@ -439,14 +432,14 @@ class ComputerPartition(SlapRequester): 'computer_partition_id': self.getId(), }) - def error(self, error_log, logger=None): + def error(self, error_log, logger): try: self._connection_helper.POST('softwareInstanceError', data={ 'computer_id': self._computer_id, 'computer_partition_id': self.getId(), 'error_log': error_log}) except Exception: - (logger or fallback_logger).exception('') + logger.exception('') def bang(self, message): self._connection_helper.POST('softwareInstanceBang', data={ -- 2.30.9