Beispiel #1
0
    def test_confirm(self):
        from clldutils.clilib import confirm

        with patch('clldutils.clilib.input', Mock(return_value='')):
            self.assertTrue(confirm('a?'))
            self.assertFalse(confirm('a?', default=False))

        with patch('clldutils.clilib.input', Mock(side_effect=['x', 'y'])):
            with capture_all(confirm, 'a?') as res:
                self.assertTrue(res[0])
                self.assertIn('Please respond', res[1])
Beispiel #2
0
def test_confirm(capsys, mocker):
    from clldutils.clilib import confirm

    mocker.patch('clldutils.clilib.input', mocker.Mock(return_value=''))
    assert confirm('a?')
    assert not confirm('a?', default=False)

    mocker.patch('clldutils.clilib.input', mocker.Mock(side_effect=['x', 'y']))
    assert confirm('a?')
    out, err = capsys.readouterr()
    assert 'Please respond' in out
Beispiel #3
0
def run(args):
    with Config.from_file() as cfg:
        for cat in BUILTIN_CATALOGS:
            val = getattr(args, cat.cli_name())
            if not val:
                if cat.default_location().exists():  # pragma: no cover
                    val = cat(cat.default_location()).dir
                    args.log.info(
                        'CLone of {0} exists at {1} - skipping'.format(
                            cat.__github__, cat.default_location()))
                elif args.quiet or confirm('clone {0}?'.format(cat.__github__),
                                           default=False):  # pragma: no cover
                    url = 'https://github.com/{0}.git'.format(cat.__github__)
                    args.log.info('Cloning {0} into {1} ...'.format(
                        url, cat.default_location()))
                    val = cat.clone(url).dir
                    args.log.info('... done')
            else:
                try:
                    cat(val)
                except ValueError as e:  # pragma: no cover
                    args.log.warning(str(e))
            if val:
                cfg.add_clone(cat.cli_name(), val)

    args.log.info('Config written to {0}'.format(cfg.fname()))
Beispiel #4
0
def run(args):  # pragma: no cover
    appdir = args.repos.repos / 'app'
    if not list(appdir.joinpath('cluster').iterdir()):
        raise argparse.ArgumentError(
            None,
            'There are no clusters in {0}!\nYou may have to run "clics cluster" first'
            .format(appdir))
    proc = subprocess.Popen(
        ['python', '-u', '-m', 'http.server',
         str(args.port)],
        cwd=str(appdir),
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
    )
    time.sleep(2)
    url = 'http://localhost:{0}'.format(args.port)
    webbrowser.open(url)
    print(
        'You should now see {0} opened in yur browser. If you are done using the app, press '
        'enter'.format(url))
    try:
        if confirm('quit?'):
            proc.terminate()
    finally:
        proc.terminate()
Beispiel #5
0
 def cldf(self, **kw):
     self.glottolog_version = git_describe(kw['glottolog_repos'])
     self.concepticon_version = git_describe(kw['concepticon_repos'])
     try:
         bag = bagit.Bag(self.raw.parent.as_posix())
         if not bag.is_valid():
             if confirm(
                     'The downloaded data has changed. Update checksums?'):
                 bag.save(manifests=True)
                 assert bag.is_valid()
             else:
                 raise bagit.BagError('invalid raw data')
         concepticon = Concepticon(kw['concepticon_repos'])
         if self.conceptlist:
             self.conceptlist = concepticon.conceptlists[self.conceptlist]
         self._run_command('cldf', concepticon, **kw)
     except bagit.BagError:
         self.log.error('invalid raw data for dataset %s' % self.id)
Beispiel #6
0
def orthography(args):  # pragma: no cover
    ds = get_dataset(args)
    out = ds.dir.joinpath('orthography.tsv')
    if out.exists():
        if not confirm(
                'There already is an orthography profile for this dataset. Overwrite?',
                default=False):
            return

    graphemes = Counter()
    for line in ds.iter_raw_lexemes():
        graphemes.update(grapheme_pattern.findall(line))

    with UnicodeWriter(out, delimiter='\t') as writer:
        writer.writerow(['graphemes', 'frequency', 'IPA'])
        for grapheme, frequency in graphemes.most_common():
            writer.writerow([grapheme, '{0}'.format(frequency), grapheme])

    log_dump(out, log=args.log)