Exemple #1
0
    def handle_register(config):
        cache_dirs = config.get("datadir.paths.cache_dirs")
        name = config.get("assets.register.name")
        asset_hash = config.get("assets.register.sha1_hash")
        location = config.get("assets.register.url")
        # Adding a twice the location is a small hack due the current logic to
        # return "by_name". This needs to be improved soon.
        asset = Asset(
            name=name,
            asset_hash=asset_hash,
            locations=[location, location],
            cache_dirs=cache_dirs,
        )

        try:
            asset.find_asset_file()
            LOG_UI.error("Asset with name %s already registered.", name)
            return exit_codes.AVOCADO_WARNING
        except OSError:
            try:
                asset.fetch()
                LOG_UI.info("Done. Now you can reference it by name %s", name)
                return exit_codes.AVOCADO_ALL_OK
            except OSError as e:
                LOG_UI.error(e)
                return exit_codes.AVOCADO_FAIL
Exemple #2
0
    def handle_register(self, config):
        cache_dirs = data_dir.get_cache_dirs()
        name = config.get('assets.register.name')
        asset_hash = config.get('assets.register.sha1_hash')
        location = config.get('assets.register.url')
        # Adding a twice the location is a small hack due the current logic to
        # return "by_name". This needs to be improved soon.
        asset = Asset(name=name,
                      asset_hash=asset_hash,
                      locations=[location, location],
                      cache_dirs=cache_dirs)

        try:
            asset.find_asset_file()
            LOG_UI.error("Asset with name %s already registered.", name)
        except OSError:
            try:
                asset.fetch()
                LOG_UI.info("Done. Now you can reference it by name %s", name)
            except OSError as e:
                LOG_UI.error(e)