Github user dankilman commented on a diff in the pull request:
https://github.com/apache/incubator-ariatosca/pull/34#discussion_r92946519
--- Diff: aria/utils/plugin.py ---
@@ -0,0 +1,86 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import tempfile
+import subprocess
+import sys
+from datetime import datetime
+
+import wagon
+
+
+def create(source, destination_dir):
+ return wagon.create(source=source,
archive_destination_dir=destination_dir)
+
+
+class PluginManager(object):
+
+ def __init__(self, model, plugins_dir):
+ self._model = model
+ self._plugins_dir = plugins_dir
+
+ def install(self, source):
+ metadata = wagon.show(source)
+ cls = self._model.plugin.model_cls
+ plugin = cls(
+ archive_name=metadata['archive_name'],
+ supported_platform=metadata['supported_platform'],
+ supported_py_versions=metadata['supported_python_versions'],
+ # Remove suffix colon after upgrading wagon to > 0.5.0
+
distribution=metadata['build_server_os_properties']['distribution:'],
+
distribution_release=metadata['build_server_os_properties']['distribution_version'],
+
distribution_version=metadata['build_server_os_properties']['distribution_release'],
+ package_name=metadata['package_name'],
+ package_version=metadata['package_version'],
+ package_source=metadata['package_source'],
+ wheels=metadata['wheels'],
+ uploaded_at=datetime.now()
+ )
+ if len(self._model.plugin.list(filters={'package_name':
plugin.package_name,
+ 'package_version':
plugin.package_version})):
+ raise RuntimeError('Plugin {0}, version {1} already
exists'.format(
+ plugin.package_name, plugin.package_version))
+ self._install_wagon(source=source,
prefix=self.get_plugin_prefix(plugin))
+ self._model.plugin.put(plugin)
+ return plugin
+
+ def get_plugin_prefix(self, plugin):
+ return os.path.join(
+ self._plugins_dir,
+ '{0}-{1}'.format(plugin.package_name, plugin.package_version))
+
+ @staticmethod
+ def _install_wagon(source, prefix):
+ bin_dir = 'Scripts' if os.name == 'nt' else 'bin'
+ pip_path = os.path.join(sys.prefix, bin_dir,
+ 'pip{0}'.format('.exe' if os.name == 'nt'
else ''))
+ pip_freeze = subprocess.Popen([pip_path, 'freeze'],
stdout=subprocess.PIPE)
+ pip_freeze_output, _ = pip_freeze.communicate()
+ assert not pip_freeze.poll()
+ file_descriptor, constraint_path =
tempfile.mkstemp(prefix='constraint-', suffix='.txt')
+ os.close(file_descriptor)
+ try:
+ with open(constraint_path, 'wb') as constraint:
+ constraint.write(pip_freeze_output)
+ # TODO: test constraint
--- End diff --
remove
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---