mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-09-14 23:12:46 +03:00
Throw exceptions instead of exiting
This commit is contained in:
parent
dee53ffb72
commit
e4e2d46847
1 changed files with 50 additions and 54 deletions
104
common.py
104
common.py
|
@ -29,8 +29,7 @@ def getvcs(vcstype, remote, local):
|
||||||
return vcs_hg(remote,local)
|
return vcs_hg(remote,local)
|
||||||
elif vcstype == 'bzr':
|
elif vcstype == 'bzr':
|
||||||
return vcs_bzr(remote,local)
|
return vcs_bzr(remote,local)
|
||||||
print "Invalid vcs type " + vcstype
|
raise VCSException("Invalid vcs type " + vcstype)
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
class vcs:
|
class vcs:
|
||||||
def __init__(self, remote, local):
|
def __init__(self, remote, local):
|
||||||
|
@ -44,8 +43,7 @@ class vcs:
|
||||||
remote = remote[index+1:]
|
remote = remote[index+1:]
|
||||||
index = self.username.find(':')
|
index = self.username.find(':')
|
||||||
if index == -1:
|
if index == -1:
|
||||||
print "Password required with username"
|
raise VCSException("Password required with username")
|
||||||
sys.exit(1)
|
|
||||||
self.password = self.username[index+1:]
|
self.password = self.username[index+1:]
|
||||||
self.username = self.username[:index]
|
self.username = self.username[:index]
|
||||||
else:
|
else:
|
||||||
|
@ -86,41 +84,34 @@ class vcs_git(vcs):
|
||||||
|
|
||||||
def clone(self):
|
def clone(self):
|
||||||
if subprocess.call(['git', 'clone', self.remote, self.local]) != 0:
|
if subprocess.call(['git', 'clone', self.remote, self.local]) != 0:
|
||||||
print "Git clone failed"
|
raise VCSException("Git clone failed")
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def reset(self, rev=None):
|
def reset(self, rev=None):
|
||||||
if rev is None:
|
if rev is None:
|
||||||
rev = 'origin'
|
rev = 'origin'
|
||||||
if subprocess.call(['git', 'reset', '--hard', rev],
|
if subprocess.call(['git', 'reset', '--hard', rev],
|
||||||
cwd=self.local) != 0:
|
cwd=self.local) != 0:
|
||||||
print "Git reset failed"
|
raise VCSException("Git reset failed")
|
||||||
sys.exit(1)
|
|
||||||
if subprocess.call(['git', 'clean', '-dfx'],
|
if subprocess.call(['git', 'clean', '-dfx'],
|
||||||
cwd=self.local) != 0:
|
cwd=self.local) != 0:
|
||||||
print "Git clean failed"
|
raise VCSException("Git clean failed")
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def pull(self):
|
def pull(self):
|
||||||
if subprocess.call(['git', 'pull', 'origin'],
|
if subprocess.call(['git', 'pull', 'origin'],
|
||||||
cwd=self.local) != 0:
|
cwd=self.local) != 0:
|
||||||
print "Git pull failed"
|
raise VCSException("Git pull failed")
|
||||||
sys.exit(1)
|
|
||||||
# Might need tags that aren't on a branch.
|
# Might need tags that aren't on a branch.
|
||||||
if subprocess.call(['git', 'fetch', '--tags', 'origin'],
|
if subprocess.call(['git', 'fetch', '--tags', 'origin'],
|
||||||
cwd=self.local) != 0:
|
cwd=self.local) != 0:
|
||||||
print "Git fetch failed"
|
raise VCSException("Git fetch failed")
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def initsubmodules(self):
|
def initsubmodules(self):
|
||||||
if subprocess.call(['git', 'submodule', 'init'],
|
if subprocess.call(['git', 'submodule', 'init'],
|
||||||
cwd=self.local) != 0:
|
cwd=self.local) != 0:
|
||||||
print "Git submodule init failed"
|
raise VCSException("Git submodule init failed")
|
||||||
sys.exit(1)
|
|
||||||
if subprocess.call(['git', 'submodule', 'update'],
|
if subprocess.call(['git', 'submodule', 'update'],
|
||||||
cwd=self.local) != 0:
|
cwd=self.local) != 0:
|
||||||
print "Git submodule update failed"
|
raise VCSException("Git submodule update failed")
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -128,7 +119,7 @@ class vcs_svn(vcs):
|
||||||
|
|
||||||
def userargs(self):
|
def userargs(self):
|
||||||
if self.username is None:
|
if self.username is None:
|
||||||
return []
|
return ['--non-interactive']
|
||||||
return ['--username', self.username,
|
return ['--username', self.username,
|
||||||
'--password', self.password,
|
'--password', self.password,
|
||||||
'--non-interactive']
|
'--non-interactive']
|
||||||
|
@ -136,8 +127,7 @@ class vcs_svn(vcs):
|
||||||
def clone(self):
|
def clone(self):
|
||||||
if subprocess.call(['svn', 'checkout', self.remote, self.local] +
|
if subprocess.call(['svn', 'checkout', self.remote, self.local] +
|
||||||
self.userargs()) != 0:
|
self.userargs()) != 0:
|
||||||
print "Svn checkout failed"
|
raise VCSException("Svn checkout failed")
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def reset(self, rev=None):
|
def reset(self, rev=None):
|
||||||
if rev is None:
|
if rev is None:
|
||||||
|
@ -149,25 +139,21 @@ class vcs_svn(vcs):
|
||||||
r"svn status | awk '/\?/ {print $2}' | xargs rm -rf"):
|
r"svn status | awk '/\?/ {print $2}' | xargs rm -rf"):
|
||||||
if subprocess.call(svncommand, cwd=self.local,
|
if subprocess.call(svncommand, cwd=self.local,
|
||||||
shell=True) != 0:
|
shell=True) != 0:
|
||||||
print "Svn reset failed"
|
raise VCSException("Svn reset failed")
|
||||||
sys.exit(1)
|
|
||||||
if subprocess.call(['svn', 'update', '--force'] + revargs +
|
if subprocess.call(['svn', 'update', '--force'] + revargs +
|
||||||
self.userargs(), cwd=self.local) != 0:
|
self.userargs(), cwd=self.local) != 0:
|
||||||
print "Svn update failed"
|
raise VCSException("Svn update failed")
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def pull(self):
|
def pull(self):
|
||||||
if subprocess.call(['svn', 'update'] +
|
if subprocess.call(['svn', 'update'] +
|
||||||
self.userargs(), cwd=self.local) != 0:
|
self.userargs(), cwd=self.local) != 0:
|
||||||
print "Svn update failed"
|
raise VCSException("Svn update failed")
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
class vcs_hg(vcs):
|
class vcs_hg(vcs):
|
||||||
|
|
||||||
def clone(self):
|
def clone(self):
|
||||||
if subprocess.call(['hg', 'clone', self.remote, self.local]) !=0:
|
if subprocess.call(['hg', 'clone', self.remote, self.local]) !=0:
|
||||||
print "Hg clone failed"
|
raise VCSException("Hg clone failed")
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def reset(self, rev=None):
|
def reset(self, rev=None):
|
||||||
if rev is None:
|
if rev is None:
|
||||||
|
@ -176,25 +162,21 @@ class vcs_hg(vcs):
|
||||||
revargs = [rev]
|
revargs = [rev]
|
||||||
if subprocess.call('hg status -u | xargs rm -rf',
|
if subprocess.call('hg status -u | xargs rm -rf',
|
||||||
cwd=self.local, shell=True) != 0:
|
cwd=self.local, shell=True) != 0:
|
||||||
print "Hg clean failed"
|
raise VCSException("Hg clean failed")
|
||||||
sys.exit(1)
|
|
||||||
if subprocess.call(['hg', 'checkout', '-C'] + revargs,
|
if subprocess.call(['hg', 'checkout', '-C'] + revargs,
|
||||||
cwd=self.local) != 0:
|
cwd=self.local) != 0:
|
||||||
print "Hg checkout failed"
|
raise VCSException("Hg checkout failed")
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def pull(self):
|
def pull(self):
|
||||||
if subprocess.call(['hg', 'pull'],
|
if subprocess.call(['hg', 'pull'],
|
||||||
cwd=self.local) != 0:
|
cwd=self.local) != 0:
|
||||||
print "Hg pull failed"
|
raise VCSException("Hg pull failed")
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
class vcs_bzr(vcs):
|
class vcs_bzr(vcs):
|
||||||
|
|
||||||
def clone(self):
|
def clone(self):
|
||||||
if subprocess.call(['bzr', 'branch', self.remote, self.local]) != 0:
|
if subprocess.call(['bzr', 'branch', self.remote, self.local]) != 0:
|
||||||
print "Bzr branch failed"
|
raise VCSException("Bzr branch failed")
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def reset(self, rev=None):
|
def reset(self, rev=None):
|
||||||
if rev is None:
|
if rev is None:
|
||||||
|
@ -203,18 +185,15 @@ class vcs_bzr(vcs):
|
||||||
revargs = ['-r', rev]
|
revargs = ['-r', rev]
|
||||||
if subprocess.call(['bzr', 'clean-tree', '--force',
|
if subprocess.call(['bzr', 'clean-tree', '--force',
|
||||||
'--unknown', '--ignored'], cwd=self.local) != 0:
|
'--unknown', '--ignored'], cwd=self.local) != 0:
|
||||||
print "Bzr revert failed"
|
raise VCSException("Bzr revert failed")
|
||||||
sys.exit(1)
|
|
||||||
if subprocess.call(['bzr', 'revert'] + revargs,
|
if subprocess.call(['bzr', 'revert'] + revargs,
|
||||||
cwd=self.local) != 0:
|
cwd=self.local) != 0:
|
||||||
print "Bzr revert failed"
|
raise VCSException("Bzr revert failed")
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def pull(self):
|
def pull(self):
|
||||||
if subprocess.call(['bzr', 'pull'],
|
if subprocess.call(['bzr', 'pull'],
|
||||||
cwd=self.local) != 0:
|
cwd=self.local) != 0:
|
||||||
print "Bzr update failed"
|
raise VCSException("Bzr update failed")
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -224,8 +203,7 @@ def parse_metadata(metafile, **kw):
|
||||||
parts = [p.replace("\\,", ",")
|
parts = [p.replace("\\,", ",")
|
||||||
for p in re.split(r"(?<!\\),", value)]
|
for p in re.split(r"(?<!\\),", value)]
|
||||||
if len(parts) < 3:
|
if len(parts) < 3:
|
||||||
print "Invalid build format: " + value + " in " + metafile.name
|
raise MetaDataException("Invalid build format: " + value + " in " + metafile.name)
|
||||||
sys.exit(1)
|
|
||||||
thisbuild = {}
|
thisbuild = {}
|
||||||
thisbuild['version'] = parts[0]
|
thisbuild['version'] = parts[0]
|
||||||
thisbuild['vercode'] = parts[1]
|
thisbuild['vercode'] = parts[1]
|
||||||
|
@ -268,8 +246,7 @@ def parse_metadata(metafile, **kw):
|
||||||
continue
|
continue
|
||||||
index = line.find(':')
|
index = line.find(':')
|
||||||
if index == -1:
|
if index == -1:
|
||||||
print "Invalid metadata in " + metafile.name + " at: " + line
|
raise MetaDataException("Invalid metadata in " + metafile.name + " at: " + line)
|
||||||
sys.exit(1)
|
|
||||||
field = line[:index]
|
field = line[:index]
|
||||||
value = line[index+1:]
|
value = line[index+1:]
|
||||||
if field == 'Description':
|
if field == 'Description':
|
||||||
|
@ -302,9 +279,8 @@ def parse_metadata(metafile, **kw):
|
||||||
part != "NonFreeNet" and
|
part != "NonFreeNet" and
|
||||||
part != "NonFreeDep" and
|
part != "NonFreeDep" and
|
||||||
part != "NonFreeAdd"):
|
part != "NonFreeAdd"):
|
||||||
print "Unrecognised antifeature '" + part + "' in " \
|
raise MetaDataException("Unrecognised antifeature '" + part + "' in " \
|
||||||
+ metafile.name
|
+ metafile.name)
|
||||||
sys.exit(1)
|
|
||||||
thisinfo['antifeatures'] = value
|
thisinfo['antifeatures'] = value
|
||||||
elif field == 'Market Version':
|
elif field == 'Market Version':
|
||||||
thisinfo['marketversion'] = value
|
thisinfo['marketversion'] = value
|
||||||
|
@ -324,8 +300,7 @@ def parse_metadata(metafile, **kw):
|
||||||
if value == "Yes":
|
if value == "Yes":
|
||||||
thisinfo['requiresroot'] = True
|
thisinfo['requiresroot'] = True
|
||||||
else:
|
else:
|
||||||
print "Unrecognised field " + field + " in " + metafile.name
|
raise MetaDataException("Unrecognised field " + field + " in " + metafile.name)
|
||||||
sys.exit(1)
|
|
||||||
elif mode == 1: # multi-line description
|
elif mode == 1: # multi-line description
|
||||||
if line == '.':
|
if line == '.':
|
||||||
mode = 0
|
mode = 0
|
||||||
|
@ -346,8 +321,7 @@ def parse_metadata(metafile, **kw):
|
||||||
parse_buildline("".join(buildline)))
|
parse_buildline("".join(buildline)))
|
||||||
mode = 0
|
mode = 0
|
||||||
if mode == 1:
|
if mode == 1:
|
||||||
print "Description not terminated in " + metafile.name
|
raise MetaDataException("Description not terminated in " + metafile.name)
|
||||||
sys.exit(1)
|
|
||||||
if len(thisinfo['description']) == 0:
|
if len(thisinfo['description']) == 0:
|
||||||
thisinfo['description'] = 'No description available'
|
thisinfo['description'] = 'No description available'
|
||||||
return thisinfo
|
return thisinfo
|
||||||
|
@ -359,3 +333,25 @@ def read_metadata(verbose=False):
|
||||||
print "Reading " + metafile
|
print "Reading " + metafile
|
||||||
apps.append(parse_metadata(metafile, verbose=verbose))
|
apps.append(parse_metadata(metafile, verbose=verbose))
|
||||||
return apps
|
return apps
|
||||||
|
|
||||||
|
class BuildException(Exception):
|
||||||
|
def __init__(self, value):
|
||||||
|
self.value = value
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return repr(self.value)
|
||||||
|
|
||||||
|
class VCSException(Exception):
|
||||||
|
def __init__(self, value):
|
||||||
|
self.value = value
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return repr(self.value)
|
||||||
|
|
||||||
|
class MetaDataException(Exception):
|
||||||
|
def __init__(self, value):
|
||||||
|
self.value = value
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return repr(self.value)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue