You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2013/08/01 14:41:12 UTC

[1/8] git commit: Fix a typo.

Updated Branches:
  refs/heads/trunk f1ad40243 -> a6bebca67


Fix a typo.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/fd9bc174
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/fd9bc174
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/fd9bc174

Branch: refs/heads/trunk
Commit: fd9bc174f3343865f1d0b2b70066b174d3c7c820
Parents: 92f10fb
Author: Tomaz Muraus <to...@tomaz.me>
Authored: Wed Jul 31 19:54:20 2013 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Thu Aug 1 14:30:03 2013 +0200

----------------------------------------------------------------------
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/fd9bc174/setup.py
----------------------------------------------------------------------
diff --git a/setup.py b/setup.py
index fc82122..1ed4ebd 100644
--- a/setup.py
+++ b/setup.py
@@ -119,7 +119,7 @@ class TestCommand(Command):
 
         if mtime_dist > mtime_current:
             print("It looks like test/secrets.py file is out of date.")
-            print("Please copy the new secret.py-dist file over otherwise" +
+            print("Please copy the new secrets.py-dist file over otherwise" +
                   " tests might fail")
 
         if pre_python26:


[2/8] git commit: Revert "Add argparse dependency for Python < 2.6 and >= 3.1 and <= 3.2."

Posted by to...@apache.org.
Revert "Add argparse dependency for Python < 2.6 and >= 3.1 and <= 3.2."

This reverts commit a62b97a098441603832deb239307a8cd7cf53029.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/92f10fb7
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/92f10fb7
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/92f10fb7

Branch: refs/heads/trunk
Commit: 92f10fb7b538449f40449bb5080ee72c46eab525
Parents: 39e791c
Author: Tomaz Muraus <to...@tomaz.me>
Authored: Wed Jul 31 19:51:04 2013 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Thu Aug 1 14:30:03 2013 +0200

----------------------------------------------------------------------
 libcloud/utils/py3.py |  4 ----
 setup.py              | 11 ++---------
 2 files changed, 2 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/92f10fb7/libcloud/utils/py3.py
----------------------------------------------------------------------
diff --git a/libcloud/utils/py3.py b/libcloud/utils/py3.py
index 1c44c27..206324e 100644
--- a/libcloud/utils/py3.py
+++ b/libcloud/utils/py3.py
@@ -28,7 +28,6 @@ PY2 = False
 PY25 = False
 PY27 = False
 PY3 = False
-PY31 = False
 PY32 = False
 
 if sys.version_info >= (2, 0) and sys.version_info < (3, 0):
@@ -43,9 +42,6 @@ if sys.version_info >= (2, 7) and sys.version_info <= (2, 8):
 if sys.version_info >= (3, 0):
     PY3 = True
 
-if sys.version_info >= (3, 1) and sys.version_info < (3, 2):
-    PY31 = True
-
 if sys.version_info >= (3, 2) and sys.version_info < (3, 3):
     PY32 = True
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/92f10fb7/setup.py
----------------------------------------------------------------------
diff --git a/setup.py b/setup.py
index 2bbeba7..fc82122 100644
--- a/setup.py
+++ b/setup.py
@@ -31,7 +31,7 @@ except ImportError:
 
 import libcloud.utils.misc
 from libcloud.utils.dist import get_packages, get_data_files
-from libcloud.utils.py3 import unittest2_required, PY31, PY32
+from libcloud.utils.py3 import unittest2_required
 
 libcloud.utils.misc.SHOW_DEPRECATION_WARNING = False
 
@@ -229,13 +229,6 @@ class CoverageCommand(Command):
         cov.save()
         cov.html_report()
 
-if pre_python26:
-    dependencies = ['ssl', 'simplejson', 'argparse']
-elif PY31 or PY32:
-    dependencies = ['argparse']
-else:
-    dependencies = []
-
 
 setup(
     name='apache-libcloud',
@@ -245,7 +238,7 @@ setup(
                 ' and documentation, please see http://libcloud.apache.org',
     author='Apache Software Foundation',
     author_email='dev@libcloud.apache.org',
-    requires=dependencies,
+    requires=([], ['ssl', 'simplejson'],)[pre_python26],
     packages=get_packages('libcloud'),
     package_dir={
         'libcloud': 'libcloud',


[5/8] git commit: Remove CLI stuff since it will be part of a separate PR.

Posted by to...@apache.org.
Remove CLI stuff since it will be part of a separate PR.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/39e791c9
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/39e791c9
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/39e791c9

Branch: refs/heads/trunk
Commit: 39e791c90e8e658d03fe90826dee612cf798874c
Parents: 2e92956
Author: Tomaz Muraus <to...@tomaz.me>
Authored: Wed Jul 31 19:48:37 2013 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Thu Aug 1 14:30:03 2013 +0200

----------------------------------------------------------------------
 bin/libcloud             | 30 ----------------
 libcloud/cli/__init__.py |  0
 libcloud/cli/pricing.py  | 84 -------------------------------------------
 3 files changed, 114 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/39e791c9/bin/libcloud
----------------------------------------------------------------------
diff --git a/bin/libcloud b/bin/libcloud
deleted file mode 100755
index 270922e..0000000
--- a/bin/libcloud
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/usr/bin/env python
-# 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.
-
-from __future__ import with_statement
-
-import argparse
-
-from libcloud.cli.pricing import add_subparser, update_pricing
-
-parser = argparse.ArgumentParser(prog='libcloud', usage='%(prog)s')
-subparsers = parser.add_subparsers(dest='subparser_name')
-add_subparser(subparsers=subparsers)
-
-args = parser.parse_args()
-
-if args.subparser_name == 'update-pricing':
-    update_pricing(file_url=args.file_url, file_path=args.file_path)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/39e791c9/libcloud/cli/__init__.py
----------------------------------------------------------------------
diff --git a/libcloud/cli/__init__.py b/libcloud/cli/__init__.py
deleted file mode 100644
index e69de29..0000000

http://git-wip-us.apache.org/repos/asf/libcloud/blob/39e791c9/libcloud/cli/pricing.py
----------------------------------------------------------------------
diff --git a/libcloud/cli/pricing.py b/libcloud/cli/pricing.py
deleted file mode 100644
index 584d292..0000000
--- a/libcloud/cli/pricing.py
+++ /dev/null
@@ -1,84 +0,0 @@
-# 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 sys
-
-try:
-    import simplejson as json
-except ImportError:
-    import json
-
-
-from libcloud.pricing import CUSTOM_PRICING_FILE_PATH
-from libcloud.utils.connection import get_response_object
-
-__all__ = [
-    'add_subparser',
-    'update_pricing'
-]
-
-# Default URL to the pricing file
-DEFAULT_FILE_URL = 'https://git-wip-us.apache.org/repos/asf?p=libcloud.git;a=blob_plain;f=libcloud/data/pricing.json'
-
-
-def add_subparser(subparsers):
-    parser = subparsers.add_parser('update-pricing',
-                                   help='Update Libcloud pricing file')
-    parser.add_argument('--file-path', dest='file_path', action='store',
-                        default=CUSTOM_PRICING_FILE_PATH,
-                        help='Path where the file will be saved')
-    parser.add_argument('--file-url', dest='file_url', action='store',
-                        default=DEFAULT_FILE_URL,
-                        help='URL to the pricing file')
-    return parser
-
-
-def update_pricing(file_url, file_path):
-    dir_name = os.path.dirname(file_path)
-
-    if not os.path.exists(dir_name):
-        # Verify a valid path is provided
-        sys.stderr.write('Can\'t write to %s, directory %s, doesn\'t exist\n' %
-                         (file_path, dir_name))
-        sys.exit(2)
-
-    if os.path.exists(file_path) and os.path.isdir(file_path):
-        sys.stderr.write('Can\'t write to %s file path because it\'s a'
-                         ' directory\n' %
-                         (file_path))
-        sys.exit(2)
-
-    response = get_response_object(file_url)
-    body = response.body
-
-    # Verify pricing file is valid
-    try:
-        data = json.loads(body)
-    except json.decoder.JSONDecodeError:
-        sys.stderr.write('Provided URL doesn\'t contain valid pricing'
-                         ' data\n')
-        sys.exit(3)
-
-    if not data.get('updated', None):
-        sys.stderr.write('Provided URL doesn\'t contain valid pricing'
-                         ' data\n')
-        sys.exit(3)
-
-    # No need to stream it since file is small
-    with open(file_path, 'w') as file_handle:
-        file_handle.write(response.body)
-
-    print('Pricing file saved to %s' % (file_path))


[3/8] git commit: Add cli utility for updating pricing file.

Posted by to...@apache.org.
Add cli utility for updating pricing file.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/5660b33d
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/5660b33d
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/5660b33d

Branch: refs/heads/trunk
Commit: 5660b33dec344f7a1cd5abc23a0da57a9eeb65c9
Parents: 769c5e0
Author: Tomaz Muraus <to...@tomaz.me>
Authored: Mon Jul 29 21:28:50 2013 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Thu Aug 1 14:30:03 2013 +0200

----------------------------------------------------------------------
 bin/libcloud                 | 30 ++++++++++++++
 libcloud/cli/__init__.py     |  0
 libcloud/cli/pricing.py      | 84 +++++++++++++++++++++++++++++++++++++++
 libcloud/utils/connection.py | 31 +++++++++++++++
 4 files changed, 145 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/5660b33d/bin/libcloud
----------------------------------------------------------------------
diff --git a/bin/libcloud b/bin/libcloud
new file mode 100755
index 0000000..270922e
--- /dev/null
+++ b/bin/libcloud
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+# 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.
+
+from __future__ import with_statement
+
+import argparse
+
+from libcloud.cli.pricing import add_subparser, update_pricing
+
+parser = argparse.ArgumentParser(prog='libcloud', usage='%(prog)s')
+subparsers = parser.add_subparsers(dest='subparser_name')
+add_subparser(subparsers=subparsers)
+
+args = parser.parse_args()
+
+if args.subparser_name == 'update-pricing':
+    update_pricing(file_url=args.file_url, file_path=args.file_path)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/5660b33d/libcloud/cli/__init__.py
----------------------------------------------------------------------
diff --git a/libcloud/cli/__init__.py b/libcloud/cli/__init__.py
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/libcloud/blob/5660b33d/libcloud/cli/pricing.py
----------------------------------------------------------------------
diff --git a/libcloud/cli/pricing.py b/libcloud/cli/pricing.py
new file mode 100644
index 0000000..584d292
--- /dev/null
+++ b/libcloud/cli/pricing.py
@@ -0,0 +1,84 @@
+# 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 sys
+
+try:
+    import simplejson as json
+except ImportError:
+    import json
+
+
+from libcloud.pricing import CUSTOM_PRICING_FILE_PATH
+from libcloud.utils.connection import get_response_object
+
+__all__ = [
+    'add_subparser',
+    'update_pricing'
+]
+
+# Default URL to the pricing file
+DEFAULT_FILE_URL = 'https://git-wip-us.apache.org/repos/asf?p=libcloud.git;a=blob_plain;f=libcloud/data/pricing.json'
+
+
+def add_subparser(subparsers):
+    parser = subparsers.add_parser('update-pricing',
+                                   help='Update Libcloud pricing file')
+    parser.add_argument('--file-path', dest='file_path', action='store',
+                        default=CUSTOM_PRICING_FILE_PATH,
+                        help='Path where the file will be saved')
+    parser.add_argument('--file-url', dest='file_url', action='store',
+                        default=DEFAULT_FILE_URL,
+                        help='URL to the pricing file')
+    return parser
+
+
+def update_pricing(file_url, file_path):
+    dir_name = os.path.dirname(file_path)
+
+    if not os.path.exists(dir_name):
+        # Verify a valid path is provided
+        sys.stderr.write('Can\'t write to %s, directory %s, doesn\'t exist\n' %
+                         (file_path, dir_name))
+        sys.exit(2)
+
+    if os.path.exists(file_path) and os.path.isdir(file_path):
+        sys.stderr.write('Can\'t write to %s file path because it\'s a'
+                         ' directory\n' %
+                         (file_path))
+        sys.exit(2)
+
+    response = get_response_object(file_url)
+    body = response.body
+
+    # Verify pricing file is valid
+    try:
+        data = json.loads(body)
+    except json.decoder.JSONDecodeError:
+        sys.stderr.write('Provided URL doesn\'t contain valid pricing'
+                         ' data\n')
+        sys.exit(3)
+
+    if not data.get('updated', None):
+        sys.stderr.write('Provided URL doesn\'t contain valid pricing'
+                         ' data\n')
+        sys.exit(3)
+
+    # No need to stream it since file is small
+    with open(file_path, 'w') as file_handle:
+        file_handle.write(response.body)
+
+    print('Pricing file saved to %s' % (file_path))

http://git-wip-us.apache.org/repos/asf/libcloud/blob/5660b33d/libcloud/utils/connection.py
----------------------------------------------------------------------
diff --git a/libcloud/utils/connection.py b/libcloud/utils/connection.py
new file mode 100644
index 0000000..bd2b50d
--- /dev/null
+++ b/libcloud/utils/connection.py
@@ -0,0 +1,31 @@
+# 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.
+
+from libcloud.utils.py3 import urlparse, parse_qs
+from libcloud.common.base import Connection
+
+__all__ = [
+    'get_response_object'
+]
+
+
+def get_response_object(url):
+    parsed_url = urlparse.urlparse(url)
+    parsed_qs = parse_qs(parsed_url.query)
+    secure = parsed_url.scheme == 'https'
+
+    con = Connection(secure=secure, host=parsed_url.netloc)
+    response = con.request(method='GET', action=parsed_url.path, params=parsed_qs)
+    return response


[6/8] git commit: Allow user to use a custom pricing file by placing a file to ~/.libcloud/pricing.json.

Posted by to...@apache.org.
Allow user to use a custom pricing file by placing a file to ~/.libcloud/pricing.json.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/769c5e01
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/769c5e01
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/769c5e01

Branch: refs/heads/trunk
Commit: 769c5e019147b3851e0ff70278a7f6f36dd4138c
Parents: f1ad402
Author: Tomaz Muraus <to...@tomaz.me>
Authored: Fri Jun 14 21:50:50 2013 -0700
Committer: Tomaz Muraus <to...@apache.org>
Committed: Thu Aug 1 14:30:03 2013 +0200

----------------------------------------------------------------------
 libcloud/pricing.py | 43 ++++++++++++++++++++++++++++---------------
 1 file changed, 28 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/769c5e01/libcloud/pricing.py
----------------------------------------------------------------------
diff --git a/libcloud/pricing.py b/libcloud/pricing.py
index 3ed32d2..db3b674 100644
--- a/libcloud/pricing.py
+++ b/libcloud/pricing.py
@@ -25,27 +25,26 @@ except ImportError:
 import os.path
 from os.path import join as pjoin
 
-PRICING_FILE_PATH = 'data/pricing.json'
+CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
+DEFAULT_PRICING_FILE_PATH = pjoin(CURRENT_DIRECTORY, 'data/pricing.json')
+CUSTOM_PRICING_FILE_PATH = os.path.expanduser('~/.libcloud/pricing.json')
 
-PRICING_DATA = {}
+# Pricing data cache
+PRICING_DATA = {
+    'compute': {},
+    'storage': {}
+}
 
 VALID_PRICING_DRIVER_TYPES = ['compute', 'storage']
 
 
-def clear_pricing_data():
-    PRICING_DATA.clear()
-    PRICING_DATA.update({
-        'compute': {},
-        'storage': {},
-    })
-clear_pricing_data()
-
-
 def get_pricing_file_path(file_path=None):
-    pricing_directory = os.path.dirname(os.path.abspath(__file__))
-    pricing_file_path = pjoin(pricing_directory, PRICING_FILE_PATH)
+    if os.path.exists(CUSTOM_PRICING_FILE_PATH) and \
+       os.path.isfile(CUSTOM_PRICING_FILE_PATH):
+        # Custom pricing file is available, use it
+        return CUSTOM_PRICING_FILE_PATH
 
-    return pricing_file_path
+    return DEFAULT_PRICING_FILE_PATH
 
 
 def get_pricing(driver_type, driver_name, pricing_file_path=None):
@@ -58,6 +57,10 @@ def get_pricing(driver_type, driver_name, pricing_file_path=None):
     @type driver_name: C{str}
     @param driver_name: Driver name
 
+    @type pricing_file_path: C{str}
+    @param pricing_file_path: Custom path to a price file. If not provided
+                              it uses a default path.
+
     @rtype: C{dict}
     @return: Dictionary with pricing where a key name is size ID and
              the value is a price.
@@ -126,12 +129,22 @@ def get_size_price(driver_type, driver_name, size_id):
 
 def invalidate_pricing_cache():
     """
-    Invalidate the cache for all the drivers.
+    Invalidate pricing cache for all the drivers.
     """
     PRICING_DATA['compute'] = {}
     PRICING_DATA['storage'] = {}
 
 
+def clear_pricing_data():
+    """
+    Invalidate pricing cache for all the drivers.
+
+    Note: This method does the same thing as invalidate_pricing_cache and is
+    here for backward compatibility reasons.
+    """
+    invalidate_pricing_cache()
+
+
 def invalidate_module_pricing_cache(driver_type, driver_name):
     """
     Invalidate the cache for the specified driver.


[8/8] git commit: Update changes.

Posted by to...@apache.org.
Update changes.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/a6bebca6
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/a6bebca6
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/a6bebca6

Branch: refs/heads/trunk
Commit: a6bebca672279bf71f31983235552e7bd53870de
Parents: fd9bc17
Author: Tomaz Muraus <to...@apache.org>
Authored: Thu Aug 1 14:31:22 2013 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Thu Aug 1 14:31:22 2013 +0200

----------------------------------------------------------------------
 CHANGES | 11 +++++++++++
 1 file changed, 11 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/a6bebca6/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index c7367d3..e46b896 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,17 @@
 
 Changes with Apache Libcloud in development
 
+ *) General
+
+    - By default read pricing data from ~/.libcloud/pricing.json if this file
+      exists. If it doesn't it uses old behavior and falls back to pricing file
+      bundled with a libcloud release.
+      [Tomaz Muraus]
+
+    - Add libcloud.pricing.download_pricing_file function for downloading and
+      updating the pricing file.
+      [Tomaz Muraus]
+
  *) Compute
 
     - Modify ElasticHosts drive to store drive UUID in 'extra' field.


[7/8] git commit: Add download_pricing_file function to libcloud.pricing module.

Posted by to...@apache.org.
Add download_pricing_file function to libcloud.pricing module.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/2e929567
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/2e929567
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/2e929567

Branch: refs/heads/trunk
Commit: 2e929567d2696615b5f50937d9d46e2276e9e2df
Parents: cde33ec
Author: Tomaz Muraus <to...@tomaz.me>
Authored: Wed Jul 31 19:48:01 2013 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Thu Aug 1 14:30:03 2013 +0200

----------------------------------------------------------------------
 libcloud/pricing.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 59 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/2e929567/libcloud/pricing.py
----------------------------------------------------------------------
diff --git a/libcloud/pricing.py b/libcloud/pricing.py
index db3b674..6e5befe 100644
--- a/libcloud/pricing.py
+++ b/libcloud/pricing.py
@@ -13,17 +13,31 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 from __future__ import with_statement
+
 """
 A class which handles loading the pricing files.
 """
 
+import os.path
+from os.path import join as pjoin
+
 try:
     import simplejson as json
 except ImportError:
     import json
 
-import os.path
-from os.path import join as pjoin
+from libcloud.utils.connection import get_response_object
+
+__all__ = [
+    'get_pricing',
+    'get_size_price',
+    'set_pricing',
+    'clear_pricing_data',
+    'download_pricing_file'
+]
+
+# Default URL to the pricing file
+DEFAULT_FILE_URL = 'https://git-wip-us.apache.org/repos/asf?p=libcloud.git;a=blob_plain;f=libcloud/data/pricing.json'
 
 CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
 DEFAULT_PRICING_FILE_PATH = pjoin(CURRENT_DIRECTORY, 'data/pricing.json')
@@ -157,3 +171,46 @@ def invalidate_module_pricing_cache(driver_type, driver_name):
     """
     if driver_name in PRICING_DATA[driver_type]:
         del PRICING_DATA[driver_type][driver_name]
+
+
+def download_pricing_file(file_url=DEFAULT_FILE_URL,
+                          file_path=CUSTOM_PRICING_FILE_PATH):
+    """
+    Download pricing file from the file_url and save it to file_path.
+
+    @type file_url: C{str}
+    @param file_url: URL pointing to the pricing file.
+
+    @type file_path: C{str}
+    @param file_path: Path where a download pricing file will be saved.
+    """
+    dir_name = os.path.dirname(file_path)
+
+    if not os.path.exists(dir_name):
+        # Verify a valid path is provided
+        msg = ('Can\'t write to %s, directory %s, doesn\'t exist' %
+              (file_path, dir_name))
+        raise ValueError(msg)
+
+    if os.path.exists(file_path) and os.path.isdir(file_path):
+        msg = ('Can\'t write to %s file path because it\'s a'
+               ' directory' % (file_path))
+        raise ValueError(msg)
+
+    response = get_response_object(file_url)
+    body = response.body
+
+    # Verify pricing file is valid
+    try:
+        data = json.loads(body)
+    except json.decoder.JSONDecodeError:
+        msg = 'Provided URL doesn\'t contain valid pricing data'
+        raise Exception(msg)
+
+    if not data.get('updated', None):
+        msg = 'Provided URL doesn\'t contain valid pricing data'
+        raise Exception(msg)
+
+    # No need to stream it since file is small
+    with open(file_path, 'w') as file_handle:
+        file_handle.write(body)


[4/8] git commit: Add argparse dependency for Python < 2.6 and >= 3.1 and <= 3.2.

Posted by to...@apache.org.
Add argparse dependency for Python < 2.6 and >= 3.1 and <= 3.2.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/cde33ec3
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/cde33ec3
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/cde33ec3

Branch: refs/heads/trunk
Commit: cde33ec3e5bd20387ff0ffa703c70afba9fdf334
Parents: 5660b33
Author: Tomaz Muraus <to...@tomaz.me>
Authored: Mon Jul 29 21:36:15 2013 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Thu Aug 1 14:30:03 2013 +0200

----------------------------------------------------------------------
 libcloud/utils/py3.py |  4 ++++
 setup.py              | 11 +++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/cde33ec3/libcloud/utils/py3.py
----------------------------------------------------------------------
diff --git a/libcloud/utils/py3.py b/libcloud/utils/py3.py
index 206324e..1c44c27 100644
--- a/libcloud/utils/py3.py
+++ b/libcloud/utils/py3.py
@@ -28,6 +28,7 @@ PY2 = False
 PY25 = False
 PY27 = False
 PY3 = False
+PY31 = False
 PY32 = False
 
 if sys.version_info >= (2, 0) and sys.version_info < (3, 0):
@@ -42,6 +43,9 @@ if sys.version_info >= (2, 7) and sys.version_info <= (2, 8):
 if sys.version_info >= (3, 0):
     PY3 = True
 
+if sys.version_info >= (3, 1) and sys.version_info < (3, 2):
+    PY31 = True
+
 if sys.version_info >= (3, 2) and sys.version_info < (3, 3):
     PY32 = True
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/cde33ec3/setup.py
----------------------------------------------------------------------
diff --git a/setup.py b/setup.py
index fc82122..2bbeba7 100644
--- a/setup.py
+++ b/setup.py
@@ -31,7 +31,7 @@ except ImportError:
 
 import libcloud.utils.misc
 from libcloud.utils.dist import get_packages, get_data_files
-from libcloud.utils.py3 import unittest2_required
+from libcloud.utils.py3 import unittest2_required, PY31, PY32
 
 libcloud.utils.misc.SHOW_DEPRECATION_WARNING = False
 
@@ -229,6 +229,13 @@ class CoverageCommand(Command):
         cov.save()
         cov.html_report()
 
+if pre_python26:
+    dependencies = ['ssl', 'simplejson', 'argparse']
+elif PY31 or PY32:
+    dependencies = ['argparse']
+else:
+    dependencies = []
+
 
 setup(
     name='apache-libcloud',
@@ -238,7 +245,7 @@ setup(
                 ' and documentation, please see http://libcloud.apache.org',
     author='Apache Software Foundation',
     author_email='dev@libcloud.apache.org',
-    requires=([], ['ssl', 'simplejson'],)[pre_python26],
+    requires=dependencies,
     packages=get_packages('libcloud'),
     package_dir={
         'libcloud': 'libcloud',