Exemple #1
0
def test_filesystem(tmp_path, database):
    """Test loading and using a queue with the filesystem database.
    """
    from rse.main import Encyclopedia

    config_dir = os.path.join(str(tmp_path), "software")
    os.mkdir(config_dir)
    config_file = os.path.join(config_dir, "rse.ini")

    # System exit if doesn't exist
    with pytest.raises(SystemExit):
        enc = Encyclopedia(config_file=config_file)

    enc = Encyclopedia(config_file=config_file,
                       generate=True,
                       database=database)
    assert enc.config.configfile == config_file

    assert os.path.exists(config_dir)
    assert enc.config_dir == config_dir
    assert enc.config.configfile == os.path.join(enc.config_dir, "rse.ini")
    assert enc.database == database
    assert enc.db.database == database
    if database == "filesystem":
        assert enc.db.data_base == os.path.join(config_dir, "database")

    # Test list, empty without anything
    assert not enc.list()

    # Add a repo
    repo = enc.add("github.com/singularityhub/sregistry")
    assert len(enc.list()) == 1

    # enc.get should return last repo, given no id
    lastrepo = enc.get()
    assert lastrepo.uid == repo.uid

    # Summary
    enc.summary()
    enc.summary("github.com/singularityhub/sregistry")
    enc.analyze("github.com/singularityhub/sregistry")
    enc.analyze_bulk()

    # Clean up a specific repo (no prompt)
    enc.clear(repo.uid, noprompt=True)
    assert len(enc.list()) == 0
    enc.clear(noprompt=True)
    assert not enc.list()

    # Get the taxonomy or criteria
    enc.list_taxonomy()
    enc.list_criteria()
Exemple #2
0
def main(args, extra):

    client = Encyclopedia(config_file=args.config_file, database=args.database)

    # Case 1: empty list indicates listing all
    if os.path.exists(args.path) and not args.force:
        bot.error(f"{args.path} already exists, use --force to overwrite it.")

    # Export a list of repos
    if args.export_type == "repos-txt":

        # We just want the unique id, the first result
        repos = [x[0] for x in client.list()]
        write_file(args.path, "\n".join(repos))
        bot.info(f"Wrote {len(repos)} to {args.path}")

    # Static web export from flask to a directory
    elif args.export_type == "static-web":
        from rse.app.server import start
        from rse.app.export import export_web_static

        # Start the webserver on a separate process
        p = Process(
            target=
            start,  # port, debug, client, host, log-level, disable_annotate
            args=(args.port, args.debug, client, args.host, args.log_level,
                  True),
        )
        p.start()

        # Do the export!
        export_web_static(
            export_dir=args.path,
            base_url="http://%s:%s" % (args.host, args.port),
            force=args.force,
            client=client,
        )

        # Ensure that it stops!
        p.kill()