Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 214a961
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions nikola/__main__.py
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion nikola/plugin_categories.py
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion nikola/plugins/command/bootswatch_theme.py
Expand Up @@ -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 = ''

Expand Down
2 changes: 1 addition & 1 deletion nikola/plugins/command/check.py
Expand Up @@ -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 = {}
Expand Down
4 changes: 2 additions & 2 deletions nikola/plugins/command/deploy.py
Expand Up @@ -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))
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions nikola/plugins/command/github_deploy.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion nikola/plugins/command/install_theme.py
Expand Up @@ -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.")
Expand Down
9 changes: 6 additions & 3 deletions nikola/plugins/command/new_post.py
Expand Up @@ -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
Expand All @@ -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]


Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions nikola/plugins/command/rst2html/__init__.py
Expand Up @@ -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
2 changes: 1 addition & 1 deletion nikola/plugins/command/serve.py
Expand Up @@ -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):
Expand Down

0 comments on commit 214a961

Please sign in to comment.