moulinette/bin/yunohost
Jerome Lebleu 9104024fa1 Refactore interfaces and reorganize files a bit
* Remove 'core' folder and reorganize root package structure
* Introduce interface's base class and implement 'api' and 'cli'
* Add a Package class and a moulinette initialization method
* Start to replace YunoHostError by MoulinetteError
* Fix actionsmap/yunohost.yml to follow extra parameters rules
2014-03-04 12:49:42 +01:00

49 lines
1.3 KiB
Python
Executable file

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os.path
import gettext
# Run from source
basedir = os.path.abspath(os.path.dirname(__file__) +'/../')
if os.path.isdir(basedir +'/src'):
sys.path.append(basedir +'/src')
from moulinette import init, cli, MoulinetteError
from moulinette.helpers import YunoHostError, colorize
gettext.install('yunohost')
## Main action
if __name__ == '__main__':
# Run from source (prefix and libdir set to None)
init('yunohost', prefix=None, libdir=None,
cachedir=os.path.join(basedir, 'cache'))
# Additional arguments
use_cache = True
if '--no-cache' in sys.argv:
use_cache = False
sys.argv.remove('--no-cache')
try:
args = list(sys.argv)
args.pop(0)
# Check that YunoHost is installed
if not os.path.isfile('/etc/yunohost/installed') \
and (len(args) < 2 or args[1] != 'tools' or args[2] != 'postinstall'):
raise YunoHostError(17, _("YunoHost is not correctly installed, please execute 'yunohost tools postinstall'"))
# Execute the action
cli(args, use_cache)
except MoulinetteError as e:
print(e.colorize())
sys.exit(e.code)
except YunoHostError as e:
print(colorize(_("Error: "), 'red') + e.message)
sys.exit(e.code)
sys.exit(0)