incubator-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r1488735 - in /incubator/public/trunk/tools: NOTICE.txt requirements.txt setup.py src/asf/utils/ src/asf/utils/__init__.py src/asf/utils/config.py src/asf/utils/file.py tests/test_config.py
Date Sun, 02 Jun 2013 16:21:25 GMT
Author: adc
Date: Sun Jun  2 16:21:24 2013
New Revision: 1488735

URL: http://svn.apache.org/r1488735
Log:
First few utility functions/classes

Also include LinkedIn notice

Added:
    incubator/public/trunk/tools/src/asf/utils/
    incubator/public/trunk/tools/src/asf/utils/__init__.py
    incubator/public/trunk/tools/src/asf/utils/config.py
    incubator/public/trunk/tools/src/asf/utils/file.py
    incubator/public/trunk/tools/tests/test_config.py
Modified:
    incubator/public/trunk/tools/NOTICE.txt
    incubator/public/trunk/tools/requirements.txt
    incubator/public/trunk/tools/setup.py

Modified: incubator/public/trunk/tools/NOTICE.txt
URL: http://svn.apache.org/viewvc/incubator/public/trunk/tools/NOTICE.txt?rev=1488735&r1=1488734&r2=1488735&view=diff
==============================================================================
--- incubator/public/trunk/tools/NOTICE.txt (original)
+++ incubator/public/trunk/tools/NOTICE.txt Sun Jun  2 16:21:24 2013
@@ -1,5 +1,21 @@
 =========================================================================
 ==  NOTICE file corresponding to section 4(d) of the Apache License,   ==
-==  Version 1.0.0, in this case for the LiveTribe Utilities            ==
+==  Version 2.0.0, in this case for the ASF Incubator tools            ==
 ==  distribution.                                                      ==
 =========================================================================
+
+This distribution contains code from the LinkedIn Corporation:
+
+ Copyright (c) 2013 LinkedIn Corp. All rights reserved.
+
+ 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.

Modified: incubator/public/trunk/tools/requirements.txt
URL: http://svn.apache.org/viewvc/incubator/public/trunk/tools/requirements.txt?rev=1488735&r1=1488734&r2=1488735&view=diff
==============================================================================
--- incubator/public/trunk/tools/requirements.txt (original)
+++ incubator/public/trunk/tools/requirements.txt Sun Jun  2 16:21:24 2013
@@ -0,0 +1,4 @@
+argparse
+brownie
+mock
+restkit

Modified: incubator/public/trunk/tools/setup.py
URL: http://svn.apache.org/viewvc/incubator/public/trunk/tools/setup.py?rev=1488735&r1=1488734&r2=1488735&view=diff
==============================================================================
--- incubator/public/trunk/tools/setup.py (original)
+++ incubator/public/trunk/tools/setup.py Sun Jun  2 16:21:24 2013
@@ -98,10 +98,12 @@ setup(
     license='Apache Software License (http://www.apache.org/licenses/LICENSE-2.0)',
     author='Apache Software Foundation',
     author_email='general@incubator.apache.org',
-    description='ASF Incubator tools.',
+    description='ASF Incubator tools',
     # don't ever depend on refcounting to close files anywhere else
     long_description=open('README.rst', encoding='utf-8').read(),
 
+    scripts=["bin/check-email"],
+
     namespace_packages=['asf'],
     package_dir={'': 'src'},
     packages=find_packages('src'),

Added: incubator/public/trunk/tools/src/asf/utils/__init__.py
URL: http://svn.apache.org/viewvc/incubator/public/trunk/tools/src/asf/utils/__init__.py?rev=1488735&view=auto
==============================================================================
--- incubator/public/trunk/tools/src/asf/utils/__init__.py (added)
+++ incubator/public/trunk/tools/src/asf/utils/__init__.py Sun Jun  2 16:21:24 2013
@@ -0,0 +1,18 @@
+#
+# 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.
+#

Added: incubator/public/trunk/tools/src/asf/utils/config.py
URL: http://svn.apache.org/viewvc/incubator/public/trunk/tools/src/asf/utils/config.py?rev=1488735&view=auto
==============================================================================
--- incubator/public/trunk/tools/src/asf/utils/config.py (added)
+++ incubator/public/trunk/tools/src/asf/utils/config.py Sun Jun  2 16:21:24 2013
@@ -0,0 +1,52 @@
+#
+# 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 ConfigParser
+import os
+
+
+TOOLS_CFG_FILE = os.path.expanduser('~/.asf-tools.ini')
+
+
+class load_config(object):
+    def __init__(self, sections=None, defaults=None):
+        defaults = defaults or {}
+        self.config = ConfigParser.SafeConfigParser(defaults=defaults)
+        self.config.read(TOOLS_CFG_FILE)
+
+        if sections:
+            for section in sections:
+                if not self.config.has_section(section):
+                    self.config.add_section(section)
+
+    def get(self, section, option, raw=False, variables=None):
+        return self.config.get(section, option, raw, variables)
+
+    def set(self, section, option, value):
+        self.config.set(section, option, value)
+
+    def remove_option(self, section, option):
+        self.config.remove_option(section, option)
+
+    def __enter__(self):
+        return self
+
+    def __exit__(self, exception_type, exception_value, traceback):
+        if not exception_value:
+            self.config.write(open(TOOLS_CFG_FILE, 'w'))
+        return False

Added: incubator/public/trunk/tools/src/asf/utils/file.py
URL: http://svn.apache.org/viewvc/incubator/public/trunk/tools/src/asf/utils/file.py?rev=1488735&view=auto
==============================================================================
--- incubator/public/trunk/tools/src/asf/utils/file.py (added)
+++ incubator/public/trunk/tools/src/asf/utils/file.py Sun Jun  2 16:21:24 2013
@@ -0,0 +1,34 @@
+#
+# 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 contextlib
+import shutil
+import tempfile
+
+
+@contextlib.contextmanager
+def temp_directory(*args, **kwargs):
+    """
+    Context manager returns a path created by mkdtemp and cleans it up afterwards.
+    """
+
+    path = tempfile.mkdtemp(*args, **kwargs)
+    try:
+        yield path
+    finally:
+        shutil.rmtree(path)

Added: incubator/public/trunk/tools/tests/test_config.py
URL: http://svn.apache.org/viewvc/incubator/public/trunk/tools/tests/test_config.py?rev=1488735&view=auto
==============================================================================
--- incubator/public/trunk/tools/tests/test_config.py (added)
+++ incubator/public/trunk/tools/tests/test_config.py Sun Jun  2 16:21:24 2013
@@ -0,0 +1,71 @@
+#
+# 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 ConfigParser
+import contextlib
+import os
+
+from mock import patch
+
+from asf.utils.config import load_config
+from asf.utils.file import temp_directory
+
+
+@contextlib.contextmanager
+def mock_tools_config_file():
+    with temp_directory() as tmp_dir:
+        mock_tools_cfg_file = os.path.join(tmp_dir, 'asf-tools.ini')
+
+        with patch('asf.utils.config.TOOLS_CFG_FILE', new=mock_tools_cfg_file):
+            yield mock_tools_cfg_file
+
+
+def test_config_file_creation():
+    with mock_tools_config_file() as mock_tools_cfg_file:
+        assert not os.path.exists(mock_tools_cfg_file)
+
+        with load_config([], {}) as config:
+            pass
+
+        assert os.path.exists(mock_tools_cfg_file)
+
+
+def test_config_section_creation():
+    with mock_tools_config_file() as mock_tools_cfg_file:
+        assert not os.path.exists(mock_tools_cfg_file)
+
+        with load_config(['TEST-SECTION'], {}) as config:
+            pass
+
+        config = ConfigParser.SafeConfigParser()
+        config.read(mock_tools_cfg_file)
+
+        assert len(config.sections()) == 1
+        assert 'TEST-SECTION' in config.sections()
+
+
+def test_config_defaults():
+    with mock_tools_config_file() as mock_tools_cfg_file:
+        assert not os.path.exists(mock_tools_cfg_file)
+
+        with load_config(sections=['TEST-SECTION']) as config:
+            config.set('TEST-SECTION', 'c', 'not_d')
+
+        with load_config(sections=['TEST-SECTION'], defaults={'a': 'b', 'c': 'd'}) as config:
+            assert config.get('TEST-SECTION', 'a') == 'b'
+            assert config.get('TEST-SECTION', 'c') == 'not_d'



---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@incubator.apache.org
For additional commands, e-mail: cvs-help@incubator.apache.org


Mime
View raw message