Skip to content
Permalink
Browse files

Fix #1839 -- limit sys.exit() usage

There are some more left over, but I can’t change that without
(a) a large restructuring; or
(b) messy code everywhere.

Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jun 24, 2015
1 parent 35f8014 commit 214a961d0587f7c200ac62551e33bfa2a90d13e5
@@ -124,10 +124,10 @@ def main(args=None):
if os.path.exists(conf_filename):
msg = traceback.format_exc(0)
LOGGER.error('"{0}" cannot be parsed.\n{1}'.format(conf_filename, msg))
sys.exit(1)
return 1
elif needs_config_file and conf_filename_changed:
LOGGER.error('Cannot find configuration file "{0}".'.format(conf_filename))
sys.exit(1)
return 1
config = {}

if conf_filename_changed:
@@ -122,7 +122,7 @@ def execute(self, options=None, args=None):
if self.needs_config and not self.site.configured:
LOGGER.error("This command needs to run inside an existing Nikola site.")
return False
self._execute(options, args)
return self._execute(options, args)

def _execute(self, options, args):
"""Do whatever this command does.
@@ -73,7 +73,7 @@ def _execute(self, options, args):
swatch = options['swatch']
if not swatch:
LOGGER.error('The -s option is mandatory')
sys.exit(1)
return 1
parent = options['parent']
version = ''

@@ -163,7 +163,7 @@ def _execute(self, options, args):
if options['clean']:
failure = self.clean_files()
if failure:
sys.exit(1)
return 1

existing_targets = set([])
checked_remote_targets = {}
@@ -85,7 +85,7 @@ def _execute(self, command, args):
self.site.config['DEPLOY_COMMANDS'][preset]
except:
self.logger.error('No such preset: {0}'.format(preset))
sys.exit(255)
return 255

for preset in presets:
self.logger.info("=> preset '{0}'".format(preset))
@@ -96,7 +96,7 @@ def _execute(self, command, args):
except subprocess.CalledProcessError as e:
self.logger.error('Failed deployment — command {0} '
'returned {1}'.format(e.cmd, e.returncode))
sys.exit(e.returncode)
return e.returncode

self.logger.info("Successful deployment")
try:
@@ -83,7 +83,7 @@ def _execute(self, command, args):
build = main(['build'])
if build != 0:
self.logger.error('Build failed, not deploying to GitHub')
sys.exit(build)
return build

# Clean non-target files
only_on_output, _ = real_scan_files(self.site)
@@ -119,7 +119,7 @@ def _commit_and_push(self):
'Failed GitHub deployment — command {0} '
'returned {1}'.format(e.cmd, e.returncode)
)
sys.exit(e.returncode)
return e.returncode

self.logger.info("Successful deployment")

@@ -90,7 +90,7 @@ def _execute(self, options, args):
print(path)
else:
print('not installed')
exit(0)
return 0

if name is None and not listing:
LOGGER.error("This command needs either a theme name or the -l option.")
@@ -61,7 +61,7 @@ def filter_post_pages(compiler, is_post, compilers, post_pages, compiler_objs, c
else:
LOGGER.error('Unknown format {0}'.format(compiler))
print_compilers(compilers_raw, post_pages, compiler_objs)
sys.exit(1)
return False

# Throw away the post_pages with the wrong extensions
filtered = [entry for entry in filtered if any([ext in entry[0] for ext in
@@ -75,7 +75,7 @@ def filter_post_pages(compiler, is_post, compilers, post_pages, compiler_objs, c
type_name, compiler, type_name.upper()))
LOGGER.info("Read more: {0}".format(COMPILERS_DOC_LINK))

sys.exit(1)
return False
return filtered[0]


@@ -372,6 +372,9 @@ def _execute(self, options, args):
self.site.compilers,
self.site.config['_COMPILERS_RAW'])

if entry is False:
return 1

if import_file:
print("Importing Existing {xx}".format(xx=content_type.title()))
print("-----------------------\n")
@@ -442,7 +445,7 @@ def _execute(self, options, args):
signal('existing_' + content_type).send(self, **event)

LOGGER.error("The title already exists!")
exit(8)
return 8

d_name = os.path.dirname(txt_path)
utils.makedirs(d_name)
@@ -64,6 +64,6 @@ def _execute(self, options, args):
html = b'<!DOCTYPE html>\n' + lxml.html.tostring(doc, encoding='utf8', method='html', pretty_print=True)
print(html)
if error_level < 3:
exit(0)
return 0
else:
exit(1)
return 1
@@ -121,7 +121,7 @@ def _execute(self, options, args):
httpd.serve_forever()
except KeyboardInterrupt:
self.logger.info("Server is shutting down.")
exit(130)
return 130


class OurHTTPRequestHandler(SimpleHTTPRequestHandler):

0 comments on commit 214a961

Please sign in to comment.
You can’t perform that action at this time.