mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Fetch list and update
This commit is contained in:
parent
f00d6081ff
commit
060a4216f4
2 changed files with 40 additions and 29 deletions
|
@ -208,13 +208,17 @@ app:
|
||||||
category_help: Manage apps
|
category_help: Manage apps
|
||||||
actions:
|
actions:
|
||||||
|
|
||||||
### app_updatelist()
|
### app_fetchlist()
|
||||||
updatelist:
|
fetchlist:
|
||||||
action_help: Fetch application list from app server
|
action_help: Fetch application list from app server
|
||||||
arguments:
|
arguments:
|
||||||
-u:
|
-u:
|
||||||
full: --url
|
full: --url
|
||||||
help: URL of remote JSON list (default http://fapp.yunohost.org/app/list/raw)
|
help: URL of remote JSON list (default http://fapp.yunohost.org/app/list/raw)
|
||||||
|
-n:
|
||||||
|
full: --name
|
||||||
|
help: Name of the list (default fapp)
|
||||||
|
pattern: '^[a-z0-9_]+$'
|
||||||
|
|
||||||
### app_list()
|
### app_list()
|
||||||
list:
|
list:
|
||||||
|
|
|
@ -7,37 +7,34 @@ 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
|
from yunohost_domain import domain_list, domain_add
|
||||||
|
|
||||||
def app_updatelist(url=None):
|
def app_fetchlist(url=None, name=None):
|
||||||
"""
|
"""
|
||||||
Fetch application list
|
Fetch application list
|
||||||
|
|
||||||
Keyword arguments:
|
Keyword arguments:
|
||||||
url -- Custom list URL
|
url -- Custom list URL
|
||||||
|
name -- Name of the app list
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
True | YunoHostError
|
True | YunoHostError
|
||||||
|
|
||||||
"""
|
"""
|
||||||
app_path = '/var/cache/yunohost/apps/'
|
repo_path = '/var/cache/yunohost/repo/'
|
||||||
|
|
||||||
# Create app path if not exists
|
# Create app path if not exists
|
||||||
try: os.listdir(app_path)
|
try: os.listdir(repo_path)
|
||||||
except OSError: os.makedirs(app_path)
|
except OSError: os.makedirs(repo_path)
|
||||||
|
|
||||||
if not url: url = 'http://fapp.yunohost.org/app/list/raw'
|
if not url:
|
||||||
|
url = 'http://fapp.yunohost.org/app/list/raw'
|
||||||
|
name = "fapp"
|
||||||
|
else:
|
||||||
|
if not name: raise YunoHostError(22, _("You must indicate a name for your custom list"))
|
||||||
|
|
||||||
# TODO: Add multiple list support
|
if os.system('wget "'+ url +'" -O "'+ repo_path + name +'.json"') != 0:
|
||||||
|
raise YunoHostError(1, _("List server connection failed"))
|
||||||
|
|
||||||
# Get list
|
win_msg(_("List successfully fetched"))
|
||||||
try: fetch = urlopen(url)
|
|
||||||
except IOError: fetch = False
|
|
||||||
finally:
|
|
||||||
if fetch and (fetch.code == 200): urlretrieve(url, app_path + 'list.json')
|
|
||||||
else: raise YunoHostError(1, _("List server connection failed"))
|
|
||||||
|
|
||||||
# TODO: Use system wget in order to have a status bar
|
|
||||||
|
|
||||||
win_msg(_("List updated successfully"))
|
|
||||||
|
|
||||||
|
|
||||||
def app_list(offset=None, limit=None):
|
def app_list(offset=None, limit=None):
|
||||||
|
@ -60,11 +57,20 @@ def app_list(offset=None, limit=None):
|
||||||
else: offset = 0
|
else: offset = 0
|
||||||
if limit: limit = int(limit)
|
if limit: limit = int(limit)
|
||||||
else: limit = 1000
|
else: limit = 1000
|
||||||
with open('/var/cache/yunohost/apps/list.json') as json_list:
|
|
||||||
app_dict = json.loads(str(json_list.read()))
|
|
||||||
|
|
||||||
|
repo_path = '/var/cache/yunohost/repo/'
|
||||||
|
applists = os.listdir(repo_path)
|
||||||
|
app_dict = {}
|
||||||
list_dict = {}
|
list_dict = {}
|
||||||
|
|
||||||
|
if not applists: app_fetchlist()
|
||||||
|
|
||||||
|
for applist in applists:
|
||||||
|
if '.json' in applist:
|
||||||
|
with open(repo_path + applist) as json_list:
|
||||||
|
app_dict.update(json.loads(str(json_list.read())))
|
||||||
|
|
||||||
|
|
||||||
if len(app_dict) > (0 + offset) and limit > 0:
|
if len(app_dict) > (0 + offset) and limit > 0:
|
||||||
i = 0 + offset
|
i = 0 + offset
|
||||||
sorted_app_dict = {}
|
sorted_app_dict = {}
|
||||||
|
@ -144,8 +150,6 @@ def app_install(app, domain=None, path=None, label=None, public=False, protected
|
||||||
|
|
||||||
# TODO: Check if exists another instance
|
# TODO: Check if exists another instance
|
||||||
|
|
||||||
# TODO: Create domain
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
domain_list(filter="virtualdomain="+ domain)
|
domain_list(filter="virtualdomain="+ domain)
|
||||||
except YunoHostError:
|
except YunoHostError:
|
||||||
|
@ -154,6 +158,9 @@ def app_install(app, domain=None, path=None, label=None, public=False, protected
|
||||||
|
|
||||||
# TODO: Install dependencies
|
# TODO: Install dependencies
|
||||||
|
|
||||||
|
for dependency in manifest['dependencies']['debian']:
|
||||||
|
print dependency
|
||||||
|
|
||||||
# TODO: Exec install script
|
# TODO: Exec install script
|
||||||
|
|
||||||
# TODO: Check if MYSQL DB is needed and create it, then init DB if needed
|
# TODO: Check if MYSQL DB is needed and create it, then init DB if needed
|
||||||
|
@ -166,7 +173,7 @@ def app_install(app, domain=None, path=None, label=None, public=False, protected
|
||||||
|
|
||||||
# TODO: Configure apache/lemon with NPZE's scripts
|
# TODO: Configure apache/lemon with NPZE's scripts
|
||||||
|
|
||||||
# TODO: Move scripts folder
|
# TODO: Remove scripts folder
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue