App system enhancement

This commit is contained in:
Kloadut 2013-02-12 13:52:11 +01:00
parent d902369b18
commit 67cf68343b
4 changed files with 27 additions and 10 deletions

View file

@ -29,6 +29,8 @@
# #
########################################################################## ##########################################################################
# TODO: Add patern for all this
############################# #############################
# General args # # General args #
############################# #############################

View file

@ -190,11 +190,11 @@ def main():
result = args.func(**args_dict) result = args.func(**args_dict)
else: else:
result = args.func(**args_dict) result = args.func(**args_dict)
except TypeError, error: #except TypeError, error:
if not __debug__ : #if not __debug__ :
traceback.print_exc() #traceback.print_exc()
print(_("Not (yet) implemented function")) #print(_("Not (yet) implemented function"))
return 1 #return 1
except YunoHostError, error: except YunoHostError, error:
display_error(error) display_error(error)
return error.code return error.code

View file

@ -5,6 +5,7 @@ import sys
import json import json
from urllib import urlopen, urlretrieve from urllib import urlopen, urlretrieve
from yunohost import YunoHostError, YunoHostLDAP, win_msg from yunohost import YunoHostError, YunoHostLDAP, win_msg
from yunohost_domain import domain_list, domain_add
def app_updatelist(url=None): def app_updatelist(url=None):
""" """
@ -25,6 +26,8 @@ def app_updatelist(url=None):
if not url: url = 'http://fapp.yunohost.org/app/list/raw' if not url: url = 'http://fapp.yunohost.org/app/list/raw'
# TODO: Add multiple list support
# Get list # Get list
try: fetch = urlopen(url) try: fetch = urlopen(url)
except IOError: fetch = False except IOError: fetch = False
@ -32,6 +35,8 @@ def app_updatelist(url=None):
if fetch and (fetch.code == 200): urlretrieve(url, app_path + 'list.json') if fetch and (fetch.code == 200): urlretrieve(url, app_path + 'list.json')
else: raise YunoHostError(1, _("List server connection failed")) else: raise YunoHostError(1, _("List server connection failed"))
# TODO: Use system wget in order to have a status bar
win_msg(_("List updated successfully")) win_msg(_("List updated successfully"))
@ -95,6 +100,8 @@ def app_install(app, domain=None, path=None, label=None, public=False, protected
# TODO: Check if the app is already installed # TODO: Check if the app is already installed
# Fetch | Extract sources
install_tmp = '/tmp/yunohost/install' install_tmp = '/tmp/yunohost/install'
try: os.listdir(install_tmp) try: os.listdir(install_tmp)
except OSError: os.makedirs(install_tmp) except OSError: os.makedirs(install_tmp)
@ -114,6 +121,9 @@ def app_install(app, domain=None, path=None, label=None, public=False, protected
if extract_result != 0: if extract_result != 0:
raise YunoHostError(22, _("Invalid install file")) raise YunoHostError(22, _("Invalid install file"))
with open(app_tmp_folder + '/manifest.webapp') as json_manifest:
manifest = json.loads(str(json_manifest.read()))
else: else:
install_from_file = False install_from_file = False
app_tmp_folder = install_tmp +'/'+ app app_tmp_folder = install_tmp +'/'+ app
@ -122,6 +132,7 @@ def app_install(app, domain=None, path=None, label=None, public=False, protected
if app in app_dict: if app in app_dict:
app_info = app_dict[app] app_info = app_dict[app]
manifest = app_info['manifest']
else: else:
raise YunoHostError(22, _("App doesn't exists")) raise YunoHostError(22, _("App doesn't exists"))
@ -131,12 +142,16 @@ def app_install(app, domain=None, path=None, label=None, public=False, protected
if not git_result == git_result_2 == 0: if not git_result == git_result_2 == 0:
raise YunoHostError(22, _("Sources fetching failed")) raise YunoHostError(22, _("Sources fetching failed"))
# TODO: Check if exists another instance # TODO: Check if exists another instance
# TODO: Create domain # TODO: Create domain
try:
domain_list(filter="virtualdomain="+ domain)
except YunoHostError:
domain_add(domain=[domain])
# TODO: Install dependencies # TODO: Install dependencies
# TODO: Exec install script # TODO: Exec install script

View file

@ -32,8 +32,8 @@ def domain_list(filter=None, limit=None, offset=None):
if result and len(result) > (0 + offset) and limit > 0: if result and len(result) > (0 + offset) and limit > 0:
i = 0 + offset i = 0 + offset
for domain in result[i:]: for domain in result[i:]:
if i < limit: if i <= limit:
result_dict[str(i)] = domain['virtualdomain'] result_dict[str(i)] = domain['virtualdomain'][0]
i += 1 i += 1
else: else:
raise YunoHostError(167, _("No domain found")) raise YunoHostError(167, _("No domain found"))