Example #1
0
def execute(argv):
    create_parser = argparse.ArgumentParser(
        prog='cpm create',
        description='Create a new cpm project',
        add_help=False)
    create_parser.add_argument('project_name')
    create_parser.add_argument('-s',
                               '--repository-url',
                               required=False,
                               action='store',
                               default='https://repo.cpmbits.com:8000')
    create_parser.add_argument('-t',
                               '--template',
                               required=False,
                               action='store')
    args = create_parser.parse_args(argv)

    project_loader = ProjectLoader()
    cpm_hub_connector = CpmHubConnectorV1(repository_url=args.repository_url)
    service = CreationService(project_loader,
                              cpm_hub_connector=cpm_hub_connector)
    template_name, template_version = __template_to_use(args.template)

    options = CreationOptions(
        project_name=args.project_name,
        directory=args.project_name,
        init_from_existing_sources=False,
        init_from_template=True if args.template else False,
        template_name=template_name,
        template_version=template_version)
    result = new_project(service, options)

    return result
Example #2
0
def execute(argv):
    install_bit_arg_parser = argparse.ArgumentParser(
        prog='cpm install', description='cpm Package Manager', add_help=False)
    install_bit_arg_parser.add_argument(
        '-s',
        '--repository-url',
        required=False,
        action='store',
        default='https://repo.cpmbits.com:8000')
    install_bit_arg_parser.add_argument('bit_name', nargs='?')
    args = install_bit_arg_parser.parse_args(argv)

    project_loader = ProjectLoader()
    bit_installer = BitInstaller(project_loader)
    user_configuration = CpmUserConfiguration()
    user_configuration.load()
    repository_url = args.repository_url if args.repository_url else user_configuration[
        "cpm_hub_url"]
    cpm_hub_connector = CpmHubConnectorV1(repository_url=f'{repository_url}')
    service = InstallService(project_loader, bit_installer, cpm_hub_connector)
    bit_name, bit_version = __bit_to_install(args.bit_name)

    if not args.bit_name:
        result = install_project_bits(service)
    else:
        result = install_bit(service, bit_name, bit_version)

    return result
Example #3
0
    def test_download_bit_raises_exception_when_bit_is_not_found(
            self, http_client, filesystem):
        connector = CpmHubConnectorV1()
        http_client.get.return_value = HttpResponse(HTTPStatus.NOT_FOUND, '')

        self.assertRaises(BitNotFound, connector.download_bit, 'cest',
                          'latest')

        http_client.get.assert_called_once_with(
            f'{connector.repository_url}/cest')
Example #4
0
    def test_download_template_raises_exception_when_template_is_not_found(
            self, http_client):
        connector = CpmHubConnectorV1()
        http_client.get.return_value = HttpResponse(HTTPStatus.NOT_FOUND, '')

        self.assertRaises(TemplateNotFound, connector.download_template,
                          'arduino', 'latest')

        http_client.get.assert_called_once_with(
            f'{connector.repository_url}/templates/arduino')
Example #5
0
    def test_publish_bit_raises_publication_error_when_status_code_is_not_200(
            self, getpass, input, http_client, filesystem):
        project = Project('cpm-hub')
        connector = CpmHubConnectorV1()
        http_client.post.return_value = HttpResponse(409, '')
        filesystem.read_file.return_value = b'bit payload'
        getpass.return_value = 'password'
        input.return_value = 'username'

        self.assertRaises(PublicationFailure, connector.publish_bit, project,
                          'cpm-hub.zip')
Example #6
0
    def test_publish_bit_raises_invalid_cpm_hub_url_on_status_code_404(
            self, getpass, input, http_client, filesystem):
        project = Project('cpm-hub')
        connector = CpmHubConnectorV1()
        http_client.post.return_value = HttpResponse(404, '')
        filesystem.read_file.return_value = b'bit payload'
        getpass.return_value = 'password'
        input.return_value = 'username'

        self.assertRaises(InvalidCpmHubUrl, connector.publish_bit, project,
                          'cpm-hub.zip')
Example #7
0
    def test_download_bit_gets_bit_with_specific_version(self, http_client):
        connector = CpmHubConnectorV1()
        http_client.get.return_value = HttpResponse(
            HTTPStatus.OK,
            '{"bit_name": "cpm-hub", "version": "1.0", "payload": "Yml0IHBheWxvYWQ="}'
        )

        bit_download = connector.download_bit('cest', '1.0')

        http_client.get.assert_called_once_with(
            f'{connector.repository_url}/bits/cest/1.0')
        assert bit_download == BitDownload("cpm-hub", "1.0",
                                           "Yml0IHBheWxvYWQ=")
Example #8
0
def execute(argv):
    publish_parser = argparse.ArgumentParser(prog='cpm publish', description='cpm Package Manager', add_help=False)
    publish_parser.add_argument('-s', '--repository-url', required=True, action='store', default='https://repo.cpmbits.com:8000')
    publish_parser.add_argument('-t', '--template', required=False, action='store_true', default=False)
    publish_parser.add_argument('-d', '--dry-run', required=False, action='store_true', default=False)
    args = publish_parser.parse_args(argv)

    cpm_hub_connector = CpmHubConnectorV1(repository_url=args.repository_url, dry_run=args.dry_run)
    service = PublishService(cpm_hub_connector)

    result = publish_project(service, publish_as_template=args.template)

    return result
Example #9
0
    def test_download_bit_gets_bit_with_base64_encoded_payload(
            self, http_client, filesystem):
        connector = CpmHubConnectorV1()
        http_client.get.return_value = HttpResponse(
            HTTPStatus.OK,
            '{"bit_name": "cpm-hub", "version": "0.1", "payload": "Yml0IHBheWxvYWQ="}'
        )

        bit_download = connector.download_bit('cest', 'latest')

        http_client.get.assert_called_once_with(
            f'{connector.repository_url}/cest')
        assert bit_download == BitDownload("cpm-hub", "0.1",
                                           "Yml0IHBheWxvYWQ=")
Example #10
0
    def test_download_template_gets_bit_with_base64_encoded_payload(
            self, http_client):
        connector = CpmHubConnectorV1()
        http_client.get.return_value = HttpResponse(
            HTTPStatus.OK,
            '{"template_name": "arduino", "version": "1.0.0", "payload": "Yml0IHBheWxvYWQ="}'
        )

        template_download = connector.download_template('arduino', 'latest')

        http_client.get.assert_called_once_with(
            f'{connector.repository_url}/templates/arduino')
        assert template_download == TemplateDownload("arduino", "1.0.0",
                                                     "Yml0IHBheWxvYWQ=")
Example #11
0
    def test_publish_bit_posts_bit_with_base64_encoded_payload_and_user_credentials(
            self, getpass, input, http_client, filesystem):
        project = Project('cpm-hub')
        connector = CpmHubConnectorV1()
        http_client.post.return_value = HttpResponse(200, '')
        filesystem.read_file.return_value = b'bit payload'
        getpass.return_value = 'password'
        input.return_value = 'username'

        connector.publish_bit(project, 'cpm-hub.zip')

        http_client.post.assert_called_once_with(
            connector.repository_url,
            data=
            '{"bit_name": "cpm-hub", "version": "0.1", "payload": "Yml0IHBheWxvYWQ=", "username": "******", "password": "******"}'
        )