[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r18800 - in gnunet-update: gnunet_update share/gnunet-updat
From: |
gnunet |
Subject: |
[GNUnet-SVN] r18800 - in gnunet-update: gnunet_update share/gnunet-update test test/confs test/confs/gnunet-update-home/etc test/confs/gnunet-update-home/share/gnunet-update |
Date: |
Sat, 24 Dec 2011 20:54:16 +0100 |
Author: harsha
Date: 2011-12-24 20:54:16 +0100 (Sat, 24 Dec 2011)
New Revision: 18800
Added:
gnunet-update/gnunet_update/group.py
gnunet-update/test/test_group.py
Removed:
gnunet-update/test/confs/user-home/
Modified:
gnunet-update/gnunet_update/config.py
gnunet-update/gnunet_update/file.py
gnunet-update/share/gnunet-update/defaults.conf
gnunet-update/test/confs/gnunet-update-home/etc/gnunet-update.conf
gnunet-update/test/confs/gnunet-update-home/share/gnunet-update/defaults.conf
gnunet-update/test/test_config.py
Log:
-added groups
Modified: gnunet-update/gnunet_update/config.py
===================================================================
--- gnunet-update/gnunet_update/config.py 2011-12-24 16:25:18 UTC (rev
18799)
+++ gnunet-update/gnunet_update/config.py 2011-12-24 19:54:16 UTC (rev
18800)
@@ -1,5 +1,5 @@
# This file is part of GNUnet.
-# (C) 2001--2011 Christian Grothoff (and other contributing authors)
+# (C) 2011 Christian Grothoff (and other contributing authors)
#
# GNUnet is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
@@ -25,10 +25,12 @@
import ConfigParser
import os
+from group import Group
class GnunetUpdateConfig:
"""Class for holding configuration."""
-
+ groups = None
+
def __init__(self, config_file=None):
"""Constructor.
config_file :if not None then the configuration is read for this file,
@@ -50,6 +52,21 @@
else:
self._config_parser.read(config_file)
+ # Read the groups
+ group_names = map(
+ lambda group_section_name: group_section_name.split(':')[1],
+ filter(lambda section: section.startswith("GROUP:"),
+ self._config_parser.sections()))
+ self.groups = list()
+ for group_name in group_names:
+ if not self._config_parser.has_option("GROUP:"+group_name,
+ "MATCH"):
+ continue
+ group_patterns = map(lambda str: str.strip(),
+ self.get("GROUP:"+group_name,
+ "MATCH").split(','))
+ self.groups.append(Group(group_name, group_patterns))
+
def _set_defaults(self):
"""Sets the defaults. It is important to do this at run time."""
# The dictionary holding defaults. Every key which is ever used should
Modified: gnunet-update/gnunet_update/file.py
===================================================================
--- gnunet-update/gnunet_update/file.py 2011-12-24 16:25:18 UTC (rev 18799)
+++ gnunet-update/gnunet_update/file.py 2011-12-24 19:54:16 UTC (rev 18800)
@@ -1,5 +1,5 @@
# This file is part of GNUnet.
-# (C) 2001--2011 Christian Grothoff (and other contributing authors)
+# (C) 2011 Christian Grothoff (and other contributing authors)
#
# GNUnet is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
Added: gnunet-update/gnunet_update/group.py
===================================================================
--- gnunet-update/gnunet_update/group.py (rev 0)
+++ gnunet-update/gnunet_update/group.py 2011-12-24 19:54:16 UTC (rev
18800)
@@ -0,0 +1,52 @@
+# This file is part of GNUnet.
+# (C) 2011 Christian Grothoff (and other contributing authors)
+#
+# GNUnet is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published
+# by the Free Software Foundation; either version 2, or (at your
+# option) any later version.
+#
+# GNUnet is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNUnet; see the file COPYING. If not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+#
+# File: gnunet_update/group.py
+# Author: Sree Harsha Totakura
+#
+# Group class
+
+import glob
+import os
+
+class Group():
+ """Class for holding data for Bundle"""
+ name = None
+ patterns = None
+
+ def __init__(self, name, patterns=None):
+ """Constructor"""
+ self.name = name
+ self.patterns = patterns
+
+ def match(self, basedir=None):
+ """Finds the files matching patterns in basedir.
+
+ basedir: directory which is used as a base for relative patterns
+ return: Files matching the patterns
+ """
+ file_objects = list()
+ if basedir is not None:
+ cwd = os.getcwd()
+ os.chdir(basedir)
+
+ for pattern in self.patterns:
+ file_objects = file_objects + glob.glob(pattern)
+ if basedir is not None:
+ os.chdir(cwd)
+ return file_objects
Modified: gnunet-update/share/gnunet-update/defaults.conf
===================================================================
--- gnunet-update/share/gnunet-update/defaults.conf 2011-12-24 16:25:18 UTC
(rev 18799)
+++ gnunet-update/share/gnunet-update/defaults.conf 2011-12-24 19:54:16 UTC
(rev 18800)
@@ -1,7 +1,7 @@
# DO NOT EDIT THIS FILE!
#
# This file is part of GNUnet.
-# (C) 2001--2011 Christian Grothoff (and other contributing authors)
+# (C) 2011 Christian Grothoff (and other contributing authors)
#
# GNUnet is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
@@ -27,4 +27,7 @@
[META]
-[SECURITY]
\ No newline at end of file
+[SECURITY]
+
+[GROUP:IGNORE]
+patterns:
\ No newline at end of file
Modified: gnunet-update/test/confs/gnunet-update-home/etc/gnunet-update.conf
===================================================================
--- gnunet-update/test/confs/gnunet-update-home/etc/gnunet-update.conf
2011-12-24 16:25:18 UTC (rev 18799)
+++ gnunet-update/test/confs/gnunet-update-home/etc/gnunet-update.conf
2011-12-24 19:54:16 UTC (rev 18800)
@@ -1,5 +1,5 @@
# This file is part of GNUnet.
-# (C) 2001--2011 Christian Grothoff (and other contributing authors)
+# (C) 2011 Christian Grothoff (and other contributing authors)
#
# GNUnet is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
@@ -16,25 +16,23 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
-# File: etc/gnunet-update.conf
+# File: test/confs/gnunet-update-home/etc/gnunet-update.conf
# Author: Sree Harsha Totakura
# Default configuration file
# This section is for signing
-
-[CONFIG]
-# Use this setting to additionally load configuration from user specific files
-# %(HOME)s will be expanded to the value set to the $HOME env variable
-USER_CONFIG_FILE = %(HOME)s/.gnunet-update/gnunet-update.conf
-
[SECURITY]
# Specify which GPG key to use for signing by its Fingerprint
-# PGP_SIGN_KEY = 8E68 1D8A 25AB B102 AFB5 4B40 3B6F 8AF1 43C2 1F3B
+PGP_SIGN_KEY = 8E68 1D8A 25AB B102 AFB5 4B40 3B6F 8AF1 43C2 1F3B
# If you don't want to be prompted for your private key password during
# signing, you may specify your private key password here
# PGP_SIGN_KEY_PASSWORD = private_key_secret
[TEST]
-FOO = BAR
+FOO = FOO
+
+[GROUP:testgroup]
+MATCH = test/old/test-package/*.am,
+ test/*/test-package/*.am
Modified:
gnunet-update/test/confs/gnunet-update-home/share/gnunet-update/defaults.conf
===================================================================
---
gnunet-update/test/confs/gnunet-update-home/share/gnunet-update/defaults.conf
2011-12-24 16:25:18 UTC (rev 18799)
+++
gnunet-update/test/confs/gnunet-update-home/share/gnunet-update/defaults.conf
2011-12-24 19:54:16 UTC (rev 18800)
@@ -1,7 +1,7 @@
# DO NOT EDIT THIS FILE!
#
# This file is part of GNUnet.
-# (C) 2001--2011 Christian Grothoff (and other contributing authors)
+# (C) 2011 Christian Grothoff (and other contributing authors)
#
# GNUnet is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
@@ -18,7 +18,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
-# File: share/gnunet-update/defaults.conf
+# File: test/confs/gnunet-update-home/share/defaults.conf
# Author: Sree Harsha Totakura
#
# The default configuration file.
@@ -27,4 +27,9 @@
[CONFIG]
-[SECURITY]
\ No newline at end of file
+[SECURITY]
+
+[TEST]
+FOO = BAR
+
+[GROUP:IGNORE]
Modified: gnunet-update/test/test_config.py
===================================================================
--- gnunet-update/test/test_config.py 2011-12-24 16:25:18 UTC (rev 18799)
+++ gnunet-update/test/test_config.py 2011-12-24 19:54:16 UTC (rev 18800)
@@ -1,5 +1,5 @@
# This file is part of GNUnet.
-# (C) 2001--2011 Christian Grothoff (and other contributing authors)
+# (C) 2011 Christian Grothoff (and other contributing authors)
#
# GNUnet is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
@@ -26,9 +26,10 @@
import os
import ConfigParser
+import __init__
from gnunet_update.config import GnunetUpdateConfig
+from gnunet_update.group import Group
-
pwd = os.path.dirname(__file__)
class TestConfig(unittest.TestCase):
@@ -44,10 +45,13 @@
def test_config_init(self):
"""Test if the Config constructor is working."""
config = GnunetUpdateConfig()
- # Test if interpolation is working
- self.assertEqual(config.get('CONFIG', 'USER_CONFIG_FILE'),
- os.path.join(pwd,
'confs/user-home/.gnunet-update/gnunet-update.conf'))
+
+ def test_config_init_filename(self):
+ """Test if the Config constructor is working."""
+ config = GnunetUpdateConfig(os.path.join(os.environ['HOME'],
+ "gnunet-update.conf"))
+
def test_config_overwrite(self):
"""Test if a recent configuration overwrites existing options."""
config = GnunetUpdateConfig()
@@ -57,7 +61,7 @@
"""Test if values added by recent configuration are available."""
config = GnunetUpdateConfig()
self.assertEqual(config.get('SECURITY', 'PGP_SIGN_KEY'),
- '38D6 5A4C 06DB 8BF5 28D6 FFA9 4BE3 A0A0 D9CA 26A1')
+ '8E68 1D8A 25AB B102 AFB5 4B40 3B6F 8AF1 43C2 1F3B')
def test_config_exception(self):
"""Test if exception is raised for non existing sections and
options."""
@@ -68,6 +72,18 @@
# Test for non existing option
self.assertRaises(ConfigParser.NoOptionError,
config.get, 'TEST', 'XYZ')
+
+ def test_config_groups(self):
+ """Test if configuration reads groups"""
+ config = GnunetUpdateConfig()
+ # Test for finding total number of registered groups
+ self.assertEqual(len(config.groups), 1)
+ # Test if we are reading the group name correctly
+ self.assertEqual(config.groups[0].name, "testgroup")
+ # Test if we are reading the group match rules correctly
+ self.assertEqual(config.groups[0].patterns,
+ ["test/old/test-package/*.am",
+ "test/*/test-package/*.am"])
Added: gnunet-update/test/test_group.py
===================================================================
--- gnunet-update/test/test_group.py (rev 0)
+++ gnunet-update/test/test_group.py 2011-12-24 19:54:16 UTC (rev 18800)
@@ -0,0 +1,45 @@
+# This file is part of GNUnet.
+# (C) 2011 Christian Grothoff (and other contributing authors)
+#
+# GNUnet is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published
+# by the Free Software Foundation; either version 2, or (at your
+# option) any later version.
+#
+# GNUnet is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNUnet; see the file COPYING. If not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+#
+# File: test/test_group.py
+# Author: Sree Harsha Totakura
+
+"""Test cases for group matching and management."""
+
+import unittest
+import os
+
+import __init__
+from gnunet_update.config import GnunetUpdateConfig
+from gnunet_update.group import Group
+
+pwd = os.path.dirname(__file__)
+
+class TestGroup(unittest.TestCase):
+
+ def test_pattern_match(self):
+ """Tests group's pattern matching."""
+ group = Group("testgroup",
+ ["*/test-package/*.am"])
+ files = group.match("." if pwd=='' else pwd)
+ self.assertEqual(len(files), 2)
+ self.assertEqual(files, ["old/test-package/Makefile.am",
+ "new/test-package/Makefile.am"])
+
+if __name__=='__main__':
+ unittest.main()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r18800 - in gnunet-update: gnunet_update share/gnunet-update test test/confs test/confs/gnunet-update-home/etc test/confs/gnunet-update-home/share/gnunet-update,
gnunet <=