]> git.openstreetmap.org Git - chef.git/commitdiff
Add a python cookbook
authorTom Hughes <tom@compton.nu>
Fri, 17 Mar 2017 19:00:37 +0000 (19:00 +0000)
committerTom Hughes <tom@compton.nu>
Fri, 17 Mar 2017 19:00:37 +0000 (19:00 +0000)
.kitchen.yml
cookbooks/python/.foodcritic [new file with mode: 0644]
cookbooks/python/README.md [new file with mode: 0644]
cookbooks/python/metadata.rb [new file with mode: 0644]
cookbooks/python/recipes/default.rb [new file with mode: 0644]
cookbooks/python/resources/package.rb [new file with mode: 0644]

index c49fa230fe8e369adf8ceac95fbd4cfe07584e5d..1b49363e6b13698d9dc3108e01e4596527ccb2b2 100644 (file)
@@ -62,6 +62,9 @@ suites:
       - recipe[accounts::default]
       - recipe[chef::default]
       - role[otrs]
+  - name: python
+    run_list:
+      - recipe[python::default]
   - name: tools
     run_list:
       - recipe[tools::default]
diff --git a/cookbooks/python/.foodcritic b/cookbooks/python/.foodcritic
new file mode 100644 (file)
index 0000000..a085263
--- /dev/null
@@ -0,0 +1,3 @@
+~FC001
+~FC064
+~FC065
diff --git a/cookbooks/python/README.md b/cookbooks/python/README.md
new file mode 100644 (file)
index 0000000..120d710
--- /dev/null
@@ -0,0 +1,4 @@
+# Python Cookbook
+
+This cookbook installs the Python runtime, and defines a `python_package`
+provider to install packages using pip.
diff --git a/cookbooks/python/metadata.rb b/cookbooks/python/metadata.rb
new file mode 100644 (file)
index 0000000..789050a
--- /dev/null
@@ -0,0 +1,7 @@
+name              "python"
+maintainer        "OpenStreetMap Administrators"
+maintainer_email  "admins@openstreetmap.org"
+license           "Apache 2.0"
+description       "Installs and configures Python"
+long_description  IO.read(File.join(File.dirname(__FILE__), "README.md"))
+version           "1.0.0"
diff --git a/cookbooks/python/recipes/default.rb b/cookbooks/python/recipes/default.rb
new file mode 100644 (file)
index 0000000..14b1e5a
--- /dev/null
@@ -0,0 +1,21 @@
+#
+# Cookbook Name:: python
+# Recipe:: default
+#
+# Copyright 2017, OpenStreetMap Foundation
+#
+# Licensed 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.
+#
+
+package "python"
+package "python-pip"
diff --git a/cookbooks/python/resources/package.rb b/cookbooks/python/resources/package.rb
new file mode 100644 (file)
index 0000000..3a76695
--- /dev/null
@@ -0,0 +1,44 @@
+#
+# Cookbook Name:: python
+# Resource:: package
+#
+# Copyright 2017, OpenStreetMap Foundation
+#
+# Licensed 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.
+#
+
+default_action :install
+
+attribute :package_name, :kind_of => String, :name_attribute => true
+attribute :version, :kind_of => String
+
+action :install do
+  if version.nil?
+    execute "pip-install-#{name}" do
+      command "pip install #{new_resource.package_name}"
+      not_if "pip show #{new_resource.package_name}"
+    end
+  else
+    execute "pip-install-#{name}" do
+      command "pip install #{new_resource.package_name}==#{new_resource.version}"
+      not_if "pip show #{new_resource.package_name} | fgrep -q #{new_resource.version}"
+    end
+  end
+end
+
+action :remove do
+  execute "pip-uninstall-#{name}" do
+    command "pip uninstall #{new_resource.package_name}"
+    only_if "pip show #{new_resource.package_name}"
+  end
+end