Replace sys.exit() in non-main functions by exceptions

Also move all exceptions into one module
This commit is contained in:
Torsten Grote 2017-05-22 16:33:52 -03:00
parent a8420817cb
commit 1fcd8e63a3
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
17 changed files with 119 additions and 141 deletions

View file

@ -18,7 +18,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import binascii
import sys
import os
import shutil
import urllib.request
@ -28,6 +27,7 @@ import logging
from . import common
from . import metadata
from .exception import FDroidException
# Get the repo type and address from the given web page. The page is scanned
@ -123,8 +123,7 @@ def get_metadata_from_url(app, url):
# Figure out the repo type and adddress...
repotype, repo = getrepofrompage(app.SourceCode)
if not repotype:
logging.error("Unable to determine vcs type. " + repo)
sys.exit(1)
raise FDroidException("Unable to determine vcs type. " + repo)
elif url.startswith('https://') and url.endswith('.git'):
projecttype = 'git'
repo = url
@ -132,10 +131,10 @@ def get_metadata_from_url(app, url):
app.SourceCode = ""
app.WebSite = ""
if not projecttype:
logging.error("Unable to determine the project type.")
logging.error("The URL you supplied was not in one of the supported formats. Please consult")
logging.error("the manual for a list of supported formats, and supply one of those.")
sys.exit(1)
raise FDroidException("Unable to determine the project type. " +
"The URL you supplied was not in one of the supported formats. " +
"Please consult the manual for a list of supported formats, " +
"and supply one of those.")
# Ensure we have a sensible-looking repo address at this point. If not, we
# might have got a page format we weren't expecting. (Note that we
@ -144,8 +143,7 @@ def get_metadata_from_url(app, url):
not repo.startswith('https://') and
not repo.startswith('git://'))) or
' ' in repo):
logging.error("Repo address '{0}' does not seem to be valid".format(repo))
sys.exit(1)
raise FDroidException("Repo address '{0}' does not seem to be valid".format(repo))
# Get a copy of the source so we can extract some info...
logging.info('Getting source from ' + repotype + ' repo at ' + repo)
@ -205,8 +203,7 @@ def main():
local_metadata_files = common.get_local_metadata_files()
if local_metadata_files != []:
logging.error("This repo already has local metadata: %s" % local_metadata_files[0])
sys.exit(1)
raise FDroidException("This repo already has local metadata: %s" % local_metadata_files[0])
if options.url is None and os.path.isdir('.git'):
app.AutoName = os.path.basename(os.getcwd())
@ -236,8 +233,7 @@ def main():
build.disable = 'Generated by import.py - check/set version fields and commit id'
write_local_file = False
else:
logging.error("Specify project url.")
sys.exit(1)
raise FDroidException("Specify project url.")
# Extract some information...
paths = common.manifest_paths(root_dir, [])
@ -245,8 +241,7 @@ def main():
versionName, versionCode, package = common.parse_androidmanifests(paths, app)
if not package:
logging.error("Couldn't find package ID")
sys.exit(1)
raise FDroidException("Couldn't find package ID")
if not versionName:
logging.warn("Couldn't find latest version name")
if not versionCode:
@ -262,13 +257,11 @@ def main():
versionName = bconfig.get('app', 'version')
versionCode = None
else:
logging.error("No android or kivy project could be found. Specify --subdir?")
sys.exit(1)
raise FDroidException("No android or kivy project could be found. Specify --subdir?")
# Make sure it's actually new...
if package in apps:
logging.error("Package " + package + " already exists")
sys.exit(1)
raise FDroidException("Package " + package + " already exists")
# Create a build line...
build.versionName = versionName or '?'