deluge/deluge/ui/ui.py
Calum Lind d417c4b0f9 [Core] Refactor the base argparser and translation code.
- Move baseargparser out of deluge/ui since it is also used by the
  Daemon and could cause packaging issues if UI code is not available.
  - Renamed baseargparser to argparserbase to follow existing Deluge
    naming.
  - Renamed get_version to distinguish from deluge.common.get_version.
- Translation code is usable by more than just the UIs so also move it
  to Deluge namespace and re-use i18n directory and make it a package.
  - Renamed setup_translations to singular as it felt more correct.
  - Renamed set_dummy_trans to be more descriptive.

Closes: #3081
2019-05-11 20:40:20 +01:00

73 lines
1.8 KiB
Python

# -*- coding: utf-8 -*-
#
# Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com>
#
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# the additional special exception to link portions of this program with the OpenSSL library.
# See LICENSE for more details.
#
from __future__ import unicode_literals
import logging
import deluge.common
import deluge.configmanager
import deluge.log
from deluge.argparserbase import ArgParserBase
from deluge.i18n import setup_translation
log = logging.getLogger(__name__)
try:
from setproctitle import setproctitle
except ImportError:
def setproctitle(title):
return
class UI(object):
"""
Base class for UI implementations.
"""
cmd_description = """Override with command description"""
def __init__(self, name, **kwargs):
self.__name = name
self.ui_args = kwargs.pop('ui_args', None)
setup_translation()
self.__parser = ArgParserBase(**kwargs)
def parse_args(self, parser, args=None):
options = parser.parse_args(args)
if not hasattr(options, 'remaining'):
options.remaining = []
return options
@property
def name(self):
return self.__name
@property
def parser(self):
return self.__parser
@property
def options(self):
return self.__options
def start(self, parser=None):
args = deluge.common.unicode_argv()[1:]
if parser is None:
parser = self.parser
self.__options = self.parse_args(parser, args)
setproctitle('deluge-%s' % self.__name)
log.info('Deluge ui %s', deluge.common.get_version())
log.debug('options: %s', self.__options)
log.info('Starting %s ui..', self.__name)