2014-02-05 02:01:03 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os.path
|
|
|
|
|
2014-03-04 12:31:04 +01:00
|
|
|
# Run from source
|
|
|
|
basedir = os.path.abspath(os.path.dirname(__file__) +'/../')
|
|
|
|
if os.path.isdir(basedir +'/src'):
|
|
|
|
sys.path.append(basedir +'/src')
|
2014-02-05 02:01:03 +01:00
|
|
|
|
2014-03-25 00:51:39 +01:00
|
|
|
from moulinette import init, api, MoulinetteError
|
2014-03-04 12:31:04 +01:00
|
|
|
|
2014-02-05 02:01:03 +01:00
|
|
|
|
|
|
|
## Callbacks for additional routes
|
|
|
|
|
|
|
|
def is_installed():
|
|
|
|
"""
|
|
|
|
Check whether YunoHost is installed or not
|
|
|
|
|
|
|
|
"""
|
|
|
|
installed = False
|
|
|
|
if os.path.isfile('/etc/yunohost/installed'):
|
|
|
|
installed = True
|
|
|
|
return { 'installed': installed }
|
|
|
|
|
|
|
|
|
|
|
|
## Main action
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2014-03-11 00:57:28 +01:00
|
|
|
# Run from source
|
|
|
|
init(_from_source=True)
|
2014-03-04 12:31:04 +01:00
|
|
|
|
2014-02-05 02:01:03 +01:00
|
|
|
# Additional arguments
|
|
|
|
use_cache = True
|
|
|
|
if '--no-cache' in sys.argv:
|
|
|
|
use_cache = False
|
|
|
|
sys.argv.remove('--no-cache')
|
|
|
|
if '--debug' in sys.argv:
|
|
|
|
sys.argv.remove('--debug')
|
|
|
|
# TODO: Add log argument
|
|
|
|
|
2014-03-25 00:51:39 +01:00
|
|
|
try:
|
|
|
|
# Run the server
|
2014-03-25 18:56:51 +01:00
|
|
|
api(['yunohost'], 6787,
|
2014-03-25 00:51:39 +01:00
|
|
|
{('GET', '/installed'): is_installed}, use_cache)
|
|
|
|
except MoulinetteError as e:
|
2014-03-25 18:13:44 +01:00
|
|
|
from moulinette.interfaces.cli import colorize
|
2014-03-25 00:51:39 +01:00
|
|
|
print(_('%s: %s' % (colorize(_('Error'), 'red'), e.strerror)))
|
2014-03-25 18:13:44 +01:00
|
|
|
sys.exit(e.errno)
|
2014-02-05 02:01:03 +01:00
|
|
|
sys.exit(0)
|