Created
June 9, 2020 12:01
-
-
Save gigidn/f8b12b58fa52f9230bbe60a218842061 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Part of OBA40. See LICENSE file for full copyright and licensing details. | |
import signal | |
import sys | |
import odoo | |
from odoo.tools import config | |
from . import Command | |
_logger = logging.getLogger(__name__) | |
def raise_keyboard_interrupt(*a): | |
raise KeyboardInterrupt() | |
def _do_stuff(dbname): | |
"""Start a server in a subprocess.""" | |
_logger.info("Starting new server.") | |
with odoo.api.Environment.manage(): | |
registry = odoo.registry(dbname) | |
# your code here | |
def command_service(dbname): | |
if not dbname: | |
_logger.warning( | |
"Could not start API Service without database ... please run whit -d option." | |
) | |
_logger.debug("!!API server error!! - no db found") | |
sys.exit(-1) | |
_do_stuff(dbname) | |
class GenericCommand(Command): | |
"""Start OBA40 Command - No frontend will be loaded""" | |
@staticmethod | |
def init(args): | |
config.parse_config(args) | |
odoo.cli.server.report_configuration() | |
odoo.service.server.start(preload=[], stop=True) | |
signal.signal(signal.SIGINT, raise_keyboard_interrupt) | |
def run(self, args): | |
handler = logging.StreamHandler(sys.stdout) | |
formatter = logging.Formatter("[PID %(process)d] %(message)s") | |
handler.setFormatter(formatter) | |
_logger.addHandler(handler) | |
_logger.setLevel(logging.INFO) | |
self.init(args) | |
command_service(config["db_name"]) | |
return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment