moulinette/bin/yunohost-api

53 lines
1.2 KiB
Text
Raw Normal View History

2014-02-05 02:01:03 +01:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os.path
2014-03-26 01:50:14 +01:00
from_source = False
# Run from source
2014-03-26 01:50:14 +01:00
basedir = os.path.abspath('%s/../' % os.path.dirname(__file__))
if os.path.isdir('%s/moulinette' % basedir):
sys.path.insert(0, basedir)
from_source = True
2014-02-05 02:01:03 +01:00
from moulinette import init, api, MoulinetteError
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__':
# Run from source
2014-03-26 01:50:14 +01:00
init(_from_source=from_source)
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')
# TODO: Add log argument
try:
# Run the server
api(['yunohost'], 6787,
{('GET', '/installed'): is_installed}, use_cache)
except MoulinetteError as e:
from moulinette.interfaces.cli import colorize
print(_('%s: %s' % (colorize(_('Error'), 'red'), e.strerror)))
sys.exit(e.errno)
2014-02-05 02:01:03 +01:00
sys.exit(0)