Esempio n. 1
0
def create_plugin_wagon(plugin_dir_name,
                        target_directory,
                        requirements=False,
                        basedir=None):
    """
    Create a wagon from a plugin.

    :param plugin_dir_name: the plugin directory name, relative to the
    resources package.
    :type plugin_dir_name: str
    :param target_directory: the directory to create the wagon in
    :type target_directory: str
    :param requirements: optional requirements for wagon
    :type requirements: str

    :return: path to created wagon`
    :rtype: str
    """
    if basedir:
        plugin_source_path = os.path.join(basedir, plugin_dir_name)
    else:
        plugin_source_path = resources.get_resource(
            os.path.join('plugins', plugin_dir_name))
    w = wagon.Wagon(plugin_source_path)
    return w.create(with_requirements=requirements,
                    archive_destination_dir=target_directory)
Esempio n. 2
0
 def setUp(self):
     super(TestValidate, self).setUp()
     self.runner = clicktest.CliRunner()
     self.packager = wagon.Wagon(TEST_PACKAGE, verbose=True)
     self.archive_path = self.packager.create(force=True)
     utils.untar(self.archive_path, '.')
     with open(os.path.join(TEST_PACKAGE_NAME, wagon.METADATA_FILE_NAME),
               'r') as f:
         self.m = json.loads(f.read())
Esempio n. 3
0
 def setUp(self):
     super(TestCreate, self).setUp()
     self.runner = clicktest.CliRunner()
     self.wagon = wagon.Wagon(TEST_PACKAGE, verbose=True)
     self.wagon.platform = 'any'
     self.wagon.python_versions = [utils.get_python_version()]
     self.package_version = TEST_PACKAGE_VERSION
     self.package_name = TEST_PACKAGE_NAME
     self.archive_name = self.wagon.set_archive_name(
         self.package_name, self.package_version)
Esempio n. 4
0
def _create_mock_wagon(package_name, package_version):
    module_src = tempfile.mkdtemp(prefix='plugin-{0}-'.format(package_name))
    try:
        with open(os.path.join(module_src, 'setup.py'), 'w') as f:
            f.write('from setuptools import setup\n')
            f.write('setup(name="{0}", version={1})'.format(
                package_name, package_version))
        wagon_client = wagon.Wagon(module_src)
        result = wagon_client.create(
            archive_destination_dir=tempfile.gettempdir(), force=True)
    finally:
        shutil.rmtree(module_src)
    return result
Esempio n. 5
0
 def _wagon_install(self, plugin, args):
     client = get_rest_client()
     wagon_dir = tempfile.mkdtemp(prefix='{0}-'.format(plugin.id))
     wagon_path = os.path.join(wagon_dir, 'wagon.tar.gz')
     try:
         self.logger.debug('Downloading plugin {0} from manager into {1}'
                           .format(plugin.id, wagon_path))
         client.plugins.download(plugin_id=plugin.id,
                                 output_file=wagon_path)
         self.logger.debug('Installing plugin {0} using wagon'
                           .format(plugin.id))
         w = wagon.Wagon(source=wagon_path)
         w.install(ignore_platform=True,
                   install_args=args,
                   virtualenv=VIRTUALENV)
     finally:
         self.logger.debug('Removing directory: {0}'
                           .format(wagon_dir))
         self._rmtree(wagon_dir)
Esempio n. 6
0
 def setUp(self):
     super(TestInstall, self).setUp()
     self.runner = clicktest.CliRunner()
     self.packager = wagon.Wagon(TEST_PACKAGE, verbose=True)
     utils.run('virtualenv test_env')
     self.archive_path = self.packager.create(force=True)
Esempio n. 7
0
 def test_unsupported_url_schema(self):
     packager = wagon.Wagon(source='ftp://x', verbose=True)
     e = self.assertRaises(SystemExit, packager.create)
     self.assertIn(str(codes.errors['unsupported_url_type']), str(e))
        _archive_destination_dir = tempfile.gettempdir()
    if not os.path.exists(_archive_destination_dir):
        os.mkdir(_archive_destination_dir)
    wagon_create_args['archive_destination_dir'] = _archive_destination_dir

    if not isinstance(wagon_source, basestring):
        print "The wagon source %s is not valid" % str(wagon_source)
        sys.exit(os.EX_USAGE)

    if isinstance(wagon_create_args, basestring):
        try:
            wagon_create_args = ast.literal_eval(wagon_create_args)
        except SyntaxError:
            print "The wagon_create_args structure %s is not valid." % str(wagon_create_args)
            sys.exit(os.EX_USAGE)

    w = wagon.Wagon(source=wagon_source)

    try:
        build_wagon_output = w.create(**wagon_create_args)
        print build_wagon_output
    except KeyError as e:
        print "Failed to create wagon because: %s." % str(e)
        sys.exit(os.EX_CANTCREAT)

    if not build_wagon_output:
        raise Exception('Wagon output: {0}'.format(build_wagon_output))

    sys.exit(os.EX_OK)