Example #1
0
 def test_home_dir(self):
     _orig_home = ''
     if 'JAMDICT_HOME' in os.environ:
         _orig_home = os.environ['JAMDICT_HOME']
     # set a new home
     os.environ['JAMDICT_HOME'] = str(self._cfg_dir)
     # home_dir exist ...
     if not self._cfg_dir.is_dir():
         self._cfg_dir.mkdir(parents=True)
     self.assertEqual(config.home_dir(), str(self._cfg_dir))
     # home_dir does not exist ...
     if self._cfg_dir.is_dir():
         self.clean_config_file()
     self.assertEqual(config.home_dir(), "~/.jamdict")
     # no environ
     del os.environ['JAMDICT_HOME']
     self.assertEqual(config.home_dir(), "~/.jamdict")
     os.environ['JAMDICT_HOME'] = _orig_home
Example #2
0
def show_info(cli, args):
    ''' Show jamdict configuration (data folder, configuration file location, etc.) '''
    output = TextReport(args.output) if 'output' in args else TextReport()
    output.print("Jamdict " + version_info.__version__)
    output.print(version_info.__description__)
    output.header("Basic configuration")
    output.print("JAMDICT_HOME        : {}".format(config.home_dir()))
    output.print("Config file location: {}".format(config._get_config_manager().locate_config()))
    output.header("Data files")
    output.print("Jamdict DB location: {} - {}".format(args.jdb, file_status(args.jdb)))
    output.print("JMDict XML file    : {} - {}".format(args.jmdxml, file_status(args.jmdxml)))
    output.print("KanjiDic2 XML file : {} - {}".format(args.kd2xml, file_status(args.kd2xml)))
    output.print("JMnedict XML file : {} - {}".format(args.jmnexml, file_status(args.jmnexml)))
Example #3
0
from jamdict import Jamdict
from jamdict import config
from jamdict import version_info

# -------------------------------------------------------------------------------
# Configuration
# -------------------------------------------------------------------------------

JMD_XML = config.get_file('JMDICT_XML')
KD2_XML = config.get_file('KD2_XML')
JMD_DB = config.get_file('JAMDICT_DB')

if os.path.isfile('logging.json'):
    setup_logging('logging.json', 'logs')
else:
    setup_logging(os.path.join(config.home_dir(), 'logging.json'), 'logs')

# -------------------------------------------------------------------------------
# Functions
# -------------------------------------------------------------------------------


def get_jam(cli, args):
    if not args.jdb:
        args.jdb = None
    if args.kd2:
        cli.logger.warning("Jamdict database location: {}".format(args.jdb))
        cli.logger.warning("Kanjidic2 database location: {}".format(args.kd2))
        jmd = Jamdict(db_file=args.jdb,
                      kd2_file=args.kd2,
                      jmd_xml_file=args.jmdxml,