gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r18833 - in gnunet-update: doc gnunet_update share/gnunet-u


From: gnunet
Subject: [GNUnet-SVN] r18833 - in gnunet-update: doc gnunet_update share/gnunet-update test test/confs/gnunet-update-home/etc test/confs/gnunet-update-home/share/gnunet-update test/old/test-package/src
Date: Mon, 26 Dec 2011 20:45:38 +0100

Author: harsha
Date: 2011-12-26 20:45:37 +0100 (Mon, 26 Dec 2011)
New Revision: 18833

Added:
   gnunet-update/test/old/test-package/src/group1-binary.c
Modified:
   gnunet-update/doc/metadata.txt
   gnunet-update/gnunet_update/config.py
   gnunet-update/gnunet_update/file.py
   gnunet-update/gnunet_update/group.py
   gnunet-update/gnunet_update/metadata.py
   gnunet-update/gnunet_update/package.py
   gnunet-update/gnunet_update/util.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/old/test-package/src/Makefile.am
   gnunet-update/test/old/test-package/src/binary-libfunadd.c
   gnunet-update/test/test_config.py
   gnunet-update/test/test_group.py
   gnunet-update/test/test_metadata.py
Log:
-added groups support for packager

Modified: gnunet-update/doc/metadata.txt
===================================================================
--- gnunet-update/doc/metadata.txt      2011-12-26 19:44:22 UTC (rev 18832)
+++ gnunet-update/doc/metadata.txt      2011-12-26 19:45:37 UTC (rev 18833)
@@ -1,11 +1,12 @@
 #+TITLE: Metadata File Format Description
 #+AUTHOR: Sree Harsha Totakura
 #+EMAIL: address@hidden
+    
 
 * Metadata file:
 
-  The metadata file consists of sections separated by a line containing
-  `%%'. Currently there are 3 sections:
+  The metadata file consists of sections separated by a line containing the
+  section delimiter `%%'. Currently there are 3 sections:
 
   1. The metadata header which consists of information about the host (the
      machine on which the package was built)
@@ -14,6 +15,7 @@
   3. A list of signatures of the binary objects and dependencies to verify the
      authenticity. A list mapping dependency name and to the dependency file
      and its signature
+  4. Package groups
 
   IMPORTANT: For every object listed in metadata body, there should be a
   signature associated with that file in signature list
@@ -61,7 +63,7 @@
 ** List of signatures of binary object and dependencies
    
    This section has 2 lists:
-
+   
 *** List of signatures of binary objects
 
     This is a list of sha512 digest of each file in the package expressed in
@@ -109,6 +111,32 @@
    * There exists a library already installed on the host system which has the
      same major number but a greater minor number
 
+** Package Groups
+    
+    Package groups are used to group certain files in the package. The
+    rationale behind this is to provide the user with a customized installation
+    by allowing the user to select which groups are to be installed. 
+
+    A package group is a listing of the all the files which are grouped
+    together. When a package group is installed all the files in it and the
+    dependencies(if they exist) for the files in package are installed.
+
+    Each package group is represented as a subsection in metadata starting with
+    a line indicating the package group's name. This line should start with a
+    `$'. The group's name is followed by a listing of file which belong to this
+    group. The end of a group is marked by another group's name or a section
+    delimiter or EOF.
+
+    The following example listing shows how a group named `testgroup'
+    containing 2 files `file1.txt' and `test/file2.dat' is represented in the
+    metadata:
+    
+    #+BEGIN_EXAMPLE
+    $testgroup
+    file1.txt
+    test/file2.dat
+    #+END_EXAMPLE
+    
 * Appendix
 
 # <<Library Naming Conventions>>

Modified: gnunet-update/gnunet_update/config.py
===================================================================
--- gnunet-update/gnunet_update/config.py       2011-12-26 19:44:22 UTC (rev 
18832)
+++ gnunet-update/gnunet_update/config.py       2011-12-26 19:45:37 UTC (rev 
18833)
@@ -57,7 +57,7 @@
             lambda group_section_name: group_section_name.split(':')[1],
             filter(lambda section: section.startswith("GROUP:"),
                    self._config_parser.sections()))
-        self.groups = list()
+        self.groups = dict()
         for group_name in group_names:
             if not self._config_parser.has_option("GROUP:"+group_name,
                                                   "MATCH"):
@@ -65,7 +65,7 @@
             group_patterns = map(lambda str: str.strip(),
                                  self.get("GROUP:"+group_name, 
                                           "MATCH").split(','))
-            self.groups.append(Group(group_name, group_patterns))
+            self.groups[group_name] = Group(group_name, group_patterns)
 
     def _set_defaults(self):
         """Sets the defaults. It is important to do this at run time."""

Modified: gnunet-update/gnunet_update/file.py
===================================================================
--- gnunet-update/gnunet_update/file.py 2011-12-26 19:44:22 UTC (rev 18832)
+++ gnunet-update/gnunet_update/file.py 2011-12-26 19:45:37 UTC (rev 18833)
@@ -23,8 +23,6 @@
 
 import re
 
-import util
-
 class FileObject(object):
     """Class for holding data for a file entity"""
     name = None
@@ -71,14 +69,14 @@
          """
          self.deps.append(dep)
     
-    def __eq__(self, other):
-        """The equality relation."""
-        if not (self.name == other.name):
-            return False
-        for dep in other.deps:
-            if dep not in self.deps:
-                return False
-        return True
+    # def __eq__(self, other):
+    #     """The equality relation."""
+    #     if not (self.name == other.name):
+    #         return False
+    #     for dep in other.deps:
+    #         if dep not in self.deps:
+    #             return False
+    #     return True
 
 class DependencyFileObject(FileObject):
     """Class representing a dependency (library object)."""

Modified: gnunet-update/gnunet_update/group.py
===================================================================
--- gnunet-update/gnunet_update/group.py        2011-12-26 19:44:22 UTC (rev 
18832)
+++ gnunet-update/gnunet_update/group.py        2011-12-26 19:45:37 UTC (rev 
18833)
@@ -28,25 +28,27 @@
     """Class for holding data for Bundle"""
     name = None
     patterns = None
+    file_objects = 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
+        return: The file names matching the patterns
         """
-        file_objects = list()
+        matching_files = list()
         if basedir is not None:
             cwd = os.getcwd()
             os.chdir(basedir)
 
         for pattern in self.patterns:
-            file_objects = file_objects + glob.glob(pattern)
+            matching_files.extend(glob.glob(pattern))
         if basedir is not None:
             os.chdir(cwd)
-        return file_objects
+        return matching_files
+        

Modified: gnunet-update/gnunet_update/metadata.py
===================================================================
--- gnunet-update/gnunet_update/metadata.py     2011-12-26 19:44:22 UTC (rev 
18832)
+++ gnunet-update/gnunet_update/metadata.py     2011-12-26 19:45:37 UTC (rev 
18833)
@@ -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
@@ -22,7 +22,9 @@
 #To handle metadata files.
 
 import tempfile
+
 from file import FileObject, ExecutableFileObject, DependencyFileObject
+from group import Group
 
 class Metadata(object):
     """Class for holding metadata information."""
@@ -33,6 +35,7 @@
     binary_objects = None
     other_objects = None
     dependencies = None
+    groups = None
 
     def __init__(self, machine=None, system=None, pkey=None,
                  release=None):
@@ -88,6 +91,15 @@
         writeln_("%%") #section seperator
         for dep in self.dependencies:
             writeln_(dep.name + ";" + dep.realname + ";" + dep.hash)
+        
+        # write the groups
+        writeln_("%%") #section seperator
+        for group in self.groups:
+            if group.file_objects is None:
+                continue
+            writeln_('$' + group.name)
+            for f_object in group.file_objects:
+                writeln_(f_object.name)
 
         #close file
         if None == path:
@@ -155,6 +167,7 @@
         # read until next `%%'
         # read the hashes
         # The lines in this section are hashes of both binary and other objects
+        other_objects = dict()
         while True:
             read_line = f.readline()
             if len(read_line) == 0:
@@ -169,12 +182,16 @@
                 _binary_objects[file_name].hash = hash
             else:
                 other_object = FileObject(file_name, hash)
-                self.other_objects.append(other_object)
-            
+                other_objects[file_name] = other_object
+        self.other_objects = other_objects.values()
+        
         # read the dependency name, file name(real name) and its hash
         while True:
             read_line = f.readline()
             if len(read_line) == 0:
+                print "Unrecognized metadata file"
+                error_exit()
+            if "%%" == read_line[:2]:
                 break
             tokens = read_line.split(';')
             dep_name = tokens[0]
@@ -187,6 +204,39 @@
             dep.name = dep_name
             dep.realname = dep_realname
             dep.hash = dep_hash
-        f.close()
+        
         # Set the binary_objects to the items from _binary_objects dictionary
         self.binary_objects = _binary_objects.values()
+
+        # read the group data
+        group = None
+        self.groups = list()
+        while True:
+            read_line = f.readline()
+            if len(read_line) == 0:
+                if group is not None:
+                    self.groups.append(group)
+                break
+            if read_line.startswith('$'):
+                if group is not None:
+                    self.groups.append(group)
+                group = Group(read_line[1:].strip())
+                group.file_objects = list() # Create the list for file_objects
+                continue
+            if group is not None:
+                file_name = read_line.strip()
+                matched_f_object = None
+                if file_name in _binary_objects:
+                    # Get the existing binary object
+                    matched_f_object = _binary_objects[file_name]
+                else:
+                    matched_f_object = other_objects[file_name]
+                if matched_f_object is None:
+                    print "Unrecognized metadata file"
+                    error_exit()
+                group.file_objects.append(matched_f_object)
+            else:
+                print "Unrecognized metadata file"
+                error_exit()
+
+        f.close()

Modified: gnunet-update/gnunet_update/package.py
===================================================================
--- gnunet-update/gnunet_update/package.py      2011-12-26 19:44:22 UTC (rev 
18832)
+++ gnunet-update/gnunet_update/package.py      2011-12-26 19:45:37 UTC (rev 
18833)
@@ -49,6 +49,7 @@
 other_objects = list()
 #dependency cache
 dependencies = dict()
+config = None
 
 def usage():
     """Print helpful usage information."""    
@@ -117,17 +118,44 @@
     
 def get_deps(install_dir):
     """Extract dependencies from ldd output."""
+
+    reverse_group_map = dict()
+    for group_name in config.groups:
+        config.groups[group_name].matching_files = config.groups[
+            group_name].match(install_dir)
+        for matching_file in config.groups[group_name].matching_files:
+            if matching_file not in reverse_group_map:
+                reverse_group_map[matching_file] = set(
+                    [config.groups[group_name]])
+            else:
+                reverse_group_map[matching_file].add(config.groups[group_name])
+                        
+    def add_to_matching_group(file_object):
+        if file_object.name in reverse_group_map:
+            for group in reverse_group_map[file_object.name]:
+                if group.file_objects is None:
+                    group.file_objects = list()
+                group.file_objects.append(file_object)
+
+    # We have to skip files in ignore group if it exists
+    ignore_files = (config.groups['IGNORE'].matching_files if
+                    'IGNORE' in config.groups else list())
+
     for root, dirs, files in os.walk(install_dir):
         root_rel = os.path.relpath(root, install_dir)
         for file in files:
+            file_path_rel = os.path.join(root_rel, file)
+            # Ignore the file if in ignore group
+            if file_path_rel in ignore_files: 
+                continue
             file_path = os.path.join(root, file)
             #ignore symbolic links if they point to something inside 
install_dir
             if (os.path.islink(file_path) and
                 len(os.path.commonprefix([file_path, root])) >= 
                 len(install_dir)):
-                other_objects.append(FileObject(
-                        os.path.join(root_rel, file),
-                        "-LINK"))
+                other_object = FileObject(file_path_rel, "-LINK")
+                other_objects.append(other_object)
+                add_to_matching_group(other_object)
                 continue
             
             proc = subprocess.Popen(["ldd", file_path],
@@ -139,9 +167,10 @@
             # points to something outside of the install directory then it may
             # cause issues during installation
             if 0 != proc.returncode:
-                other_object = FileObject(os.path.join(root_rel, file),
+                other_object = FileObject(file_path_rel,
                                           util.hexdigest(file_path))
                 other_objects.append(other_object)
+                add_to_matching_group(other_object)
                 continue
 
             #create a new ExecutableFileObject instance and collect its 
dependencies
@@ -168,7 +197,9 @@
                 bin_object.add_dependency(dep)
             #Add the binary object to the global list of binary objects
             binary_objects.append(bin_object)
-
+            # Add the binary object to a matching group
+            add_to_matching_group(bin_object)
+            
 def test_dependency_collection():
     """Function to check whether we are collecting dependencies correctly."""
     for bin_object in binary_objects:
@@ -179,12 +210,13 @@
             
 def run(action):
     """control procedure."""
+    global config
+
     config = GnunetUpdateConfig(external_config_file);
     release_counter_file_path = config.get('META', 'RELEASE_COUNTER_FILE')
     if release_counter_file_path == '':
         print ('Release counter file is required but not defined in 
configuration')
         exit(1);
-    print "Release: "+release_counter_file_path
     
     release = None;
     try:
@@ -193,7 +225,7 @@
             release = int(release_counter_file_content)
     except IOError as (errno, strerr):
         if errno == 2:
-            print ("IO Error while trying to open couter file" +
+            print ("IO Error while trying to open counter file" +
                    release_counter_file_path)
         elif errno == 13:
              print release_counter_file_path + "is not readable"
@@ -218,7 +250,7 @@
         get_deps(install_prefix)
     else :
         get_deps(install_prefix)
-    test_dependency_collection()
+    # test_dependency_collection()
 
     metadata = Metadata(machine=platform.machine(),
                         system=platform.system(),
@@ -227,7 +259,8 @@
     metadata.binary_objects = binary_objects
     metadata.other_objects = other_objects
     metadata.dependencies = dependencies
-
+    metadata.groups = config.groups.values()
+    
     #package the installed files
     tar_file = tarfile.open(package_file + ".tgz", 'w:gz')
     #tar_file.add(install_prefix, "install-prefix")

Modified: gnunet-update/gnunet_update/util.py
===================================================================
--- gnunet-update/gnunet_update/util.py 2011-12-26 19:44:22 UTC (rev 18832)
+++ gnunet-update/gnunet_update/util.py 2011-12-26 19:45:37 UTC (rev 18833)
@@ -24,7 +24,6 @@
 from hashlib import sha512
 import gpgme
 import os
-import sys
 import tempfile
 import tarfile
 import shutil
@@ -288,7 +287,7 @@
             member = package_tarfile.getmember("install-prefix/" + 
member_obj.name)
         except KeyError:
             print "Broken/Bad package - Cannot find " + member_obj.name
-            sys.exit(-1)
+            exit(-1)
         
         member.name = member.name.replace("install-prefix/","",1)
         package_tarfile.extract(member, install_dir)
@@ -300,10 +299,10 @@
                        " not matched with the expected hash " + 
member_obj.hash)
                 print "Given package contains code not signed by trusted 
packager"
                 print "Installation failed due to security reasons."
-                sys.exit(-1) 
+                exit(-1) 
         # If the file is a symbolic link, then its hash should be -LINK
         elif member_obj.hash != "-LINK":
             print "Malicious code detected. Stopping installation"
             print member_obj.name + "<-->" + member_obj.hash
-            sys.exit(-1)
+            exit(-1)
         if installed_files is not None: installed_files.append(member_obj)

Modified: gnunet-update/share/gnunet-update/defaults.conf
===================================================================
--- gnunet-update/share/gnunet-update/defaults.conf     2011-12-26 19:44:22 UTC 
(rev 18832)
+++ gnunet-update/share/gnunet-update/defaults.conf     2011-12-26 19:45:37 UTC 
(rev 18833)
@@ -30,4 +30,4 @@
 [SECURITY]
 
 [GROUP:IGNORE]
-patterns:
\ No newline at end of file
+MATCH = 

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-26 19:44:22 UTC (rev 18832)
+++ gnunet-update/test/confs/gnunet-update-home/etc/gnunet-update.conf  
2011-12-26 19:45:37 UTC (rev 18833)
@@ -24,15 +24,21 @@
 # This section is for signing
 [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 = 38D6 5A4C 06DB 8BF5 28D6 FFA9 4BE3 A0A0 D9CA 26A1
 
 # 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
+PGP_SIGN_KEY_PASSWORD = test
 
 [TEST]
 FOO = FOO
 
+[META]
+RELEASE_COUNTER_FILE = /home/harsha/.gnunet-update/release-counter
+
 [GROUP:testgroup]
 MATCH = test/old/test-package/*.am,
        test/*/test-package/*.am
+
+[GROUP:group1]
+MATCH = bin/group1-binary

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-26 19:44:22 UTC (rev 18832)
+++ 
gnunet-update/test/confs/gnunet-update-home/share/gnunet-update/defaults.conf   
    2011-12-26 19:45:37 UTC (rev 18833)
@@ -25,7 +25,7 @@
 #
 # Do NOT edit this file. For customization edit etc/gnunet-update.conf file
 
-[CONFIG]
+[META]
 
 [SECURITY]
 

Modified: gnunet-update/test/old/test-package/src/Makefile.am
===================================================================
--- gnunet-update/test/old/test-package/src/Makefile.am 2011-12-26 19:44:22 UTC 
(rev 18832)
+++ gnunet-update/test/old/test-package/src/Makefile.am 2011-12-26 19:45:37 UTC 
(rev 18833)
@@ -54,7 +54,8 @@
                binary-libfunadd \
                binary-libfundel \
                binary-libfunmod \
-               binary-libnochange
+               binary-libnochange \
+               group1-binary
 
 test_binary_SOURCES = test-binary.c
 
@@ -73,3 +74,5 @@
 
 binary_libnochange_SOURCES = binary-libnochange.c libnochange.h
 binary_libnochange_LDADD = libnochange.la
+
+group1_binary_SOURCES = group1-binary.c
\ No newline at end of file

Modified: gnunet-update/test/old/test-package/src/binary-libfunadd.c
===================================================================
--- gnunet-update/test/old/test-package/src/binary-libfunadd.c  2011-12-26 
19:44:22 UTC (rev 18832)
+++ gnunet-update/test/old/test-package/src/binary-libfunadd.c  2011-12-26 
19:45:37 UTC (rev 18833)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009, 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/test/old/test-package/src/group1-binary.c
===================================================================
--- gnunet-update/test/old/test-package/src/group1-binary.c                     
        (rev 0)
+++ gnunet-update/test/old/test-package/src/group1-binary.c     2011-12-26 
19:45:37 UTC (rev 18833)
@@ -0,0 +1,34 @@
+/*
+     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 3, 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/old/test-package/src/group1-binary.c
+ * @brief binary which is to be grouped under group1
+ * @author Sree Harsha Totakura <address@hidden> 
+ */
+
+/**
+ * The main execution function
+ */
+int main()
+{
+  return 0;
+}

Modified: gnunet-update/test/test_config.py
===================================================================
--- gnunet-update/test/test_config.py   2011-12-26 19:44:22 UTC (rev 18832)
+++ gnunet-update/test/test_config.py   2011-12-26 19:45:37 UTC (rev 18833)
@@ -61,7 +61,7 @@
         """Test if values added by recent configuration are available."""
         config = GnunetUpdateConfig()
         self.assertEqual(config.get('SECURITY', 'PGP_SIGN_KEY'), 
-                         '8E68 1D8A 25AB B102 AFB5  4B40 3B6F 8AF1 43C2 1F3B')
+                         '38D6 5A4C 06DB 8BF5 28D6 FFA9 4BE3 A0A0 D9CA 26A1')
 
     def test_config_exception(self):
         """Test if exception is raised for non existing sections and 
options."""
@@ -77,11 +77,11 @@
         """Test if configuration reads groups"""
         config = GnunetUpdateConfig()
         # Test for finding total number of registered groups
-        self.assertEqual(len(config.groups), 1)
+        self.assertEqual(len(config.groups), 2)
         # Test if we are reading the group name correctly
-        self.assertEqual(config.groups[0].name, "testgroup")
+        self.assertEqual(config.groups["testgroup"].name, "testgroup")
         # Test if we are reading the group match rules correctly
-        self.assertEqual(config.groups[0].patterns,
+        self.assertEqual(config.groups["testgroup"].patterns,
                          ["test/old/test-package/*.am", 
                           "test/*/test-package/*.am"])
         

Modified: gnunet-update/test/test_group.py
===================================================================
--- gnunet-update/test/test_group.py    2011-12-26 19:44:22 UTC (rev 18832)
+++ gnunet-update/test/test_group.py    2011-12-26 19:45:37 UTC (rev 18833)
@@ -36,10 +36,10 @@
         """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"])
+        matched_files = group.match("." if pwd=='' else pwd)
+        self.assertEqual(len(matched_files), 2)
+        self.assertEqual(matched_files, ["old/test-package/Makefile.am",
+                                         "new/test-package/Makefile.am"])
 
 if __name__=='__main__':
     unittest.main()

Modified: gnunet-update/test/test_metadata.py
===================================================================
--- gnunet-update/test/test_metadata.py 2011-12-26 19:44:22 UTC (rev 18832)
+++ gnunet-update/test/test_metadata.py 2011-12-26 19:45:37 UTC (rev 18833)
@@ -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
@@ -30,51 +30,91 @@
 
 import __init__
 from gnunet_update.metadata import Metadata
-from gnunet_update.dependency import BinaryObject, Dependency
+import gnunet_update.file as file
+from gnunet_update.group import Group
 
 class TestMetadata(unittest.TestCase):
     """Metadata test case class."""
     deps_1 = list()
     deps_2 = list()
     binary_objects = list()
+    other_objects = list()
+    groups = list()
 
-    deps_1.append(Dependency("dep1_1"))
-    deps_1.append(Dependency("dep1_2"))
-    deps_1[0].set_path("/tmp/dependencies/dep1_1.so.1.0.0")
-    deps_1[0].hash = "hash-dep_1_0"
-    deps_1[1].set_path("/tmp/dependencies/dep1_2.so.1.1.0")
-    deps_1[1].hash = "hash-dep_1_1"
-    
-    deps_2.append(Dependency("dep2_1"))
-    deps_2[-1].set_path("/tmp/dependencies/dep2_1.so.1.0.0")
-    deps_2[-1].hash = "hash-dep_2_1"
-    deps_2.append(Dependency("dep2_2"))
-    deps_2[-1].set_path("/tmp/dependencies/dep2_2.so.1.1.0")
-    deps_2[-1].hash = "hash-dep_2_2"
-    
-    binary_objects.append(BinaryObject("test-binary1"))
+    deps_1.append(file.DependencyFileObject("dep1_1",
+                                            
"/tmp/dependencies/dep1_1.so.1.0.0",
+                                            "hash-dep_1_0"))
+    deps_1[-1].realname = "dep1_1.so.1.0.0"
+    deps_1.append(file.DependencyFileObject("dep1_2",
+                                            
"/tmp/dependencies/dep1_2.so.1.1.0",
+                                            "hash-dep_1_1"))
+    deps_1[-1].realname = "dep1_2.so.1.1.0"
+
+    deps_2.append(file.DependencyFileObject("dep2_1",
+                                            
"/tmp/dependencies/dep2_1.so.1.0.0",
+                                            "hash-dep_2_1"))
+    deps_2[-1].realname = "dep2_1.so.1.0.0"
+    deps_2.append(file.DependencyFileObject("dep2_2",
+                                            
"/tmp/dependencies/dep2_2.so.1.1.0",
+                                            "hash-dep_2_2"))
+    deps_2[-1].realname = "dep2_2.so.1.1.0"
+
+    binary_objects.append(file.ExecutableFileObject("test-binary1"))
     for dep in deps_1:
         binary_objects[-1].add_dependency(dep)
     binary_objects[-1].hash = "hash-binary_object_1"
     
-    binary_objects.append(BinaryObject("test-binary2"))
+    binary_objects.append(file.ExecutableFileObject("test-binary2"))
     for dep in deps_2:
         binary_objects[-1].add_dependency(dep)
     binary_objects[-1].hash = "hash-binary_object_2"
 
+    other_objects.append(file.FileObject("other1_1",
+                                         "hash-other1_1"))
+    other_objects.append(file.FileObject("other1_2",
+                                         "hash-other1_2"))
 
+    groups.append(Group("group1"))
+    groups[-1].file_objects = [binary_objects[0], other_objects[0]]
+    
+    groups.append(Group("group2"))
+    groups[-1].file_objects = [binary_objects[1], other_objects[1]]
+
+
     def test_metadata_read_write(self):
         """Test case to test metadata file writing."""
 
         machine = platform.machine()
         system = platform.system()
         pkey = 'ABCDEFGHIJK012345678' # A testing key
-        release = 'R-A001'
+        release = '1'
         metadata = Metadata(machine=machine, system=system,
-                            pkey=pkey, release=release)
+                                     pkey=pkey, release=release)
+        # Writing empty lists
+        metadata.binary_objects = list()
+        metadata.dependencies = list()
+        metadata.other_objects = list()
+        metadata.groups = list()
+        metadata_file = metadata.write_to_file()
+        del metadata
+        metadata = Metadata()
+        metadata.read_from_file(metadata_file)
+        self.assertEquals(machine, metadata.machine)
+        self.assertEquals(system, metadata.system)
+        self.assertEquals(pkey, metadata.pkey)
+        self.assertEquals(release, metadata.release)
+        self.assertEquals(len(metadata.other_objects), 0)
+        self.assertEquals(len(metadata.binary_objects), 0)
+        self.assertEquals(len(metadata.dependencies), 0)
+        del metadata
         
+        # Metadata with populated lists
+        metadata = Metadata(machine=machine, system=system,
+                                     pkey=pkey, release=release)
         metadata.binary_objects = self.binary_objects
         metadata.dependencies = self.deps_1 + self.deps_2
+        metadata.other_objects = self.other_objects
+        metadata.groups = self.groups
 
         # Write the metadata to file
         metadata_file = metadata.write_to_file()
@@ -94,7 +134,23 @@
             self.assertTrue(binary_object in metadata.binary_objects)
         for dep in self.deps_1 + self.deps_2:
             self.assertTrue(dep in metadata.dependencies)
-        
+        self.assertEquals(len(metadata.other_objects), 2)
+        for other_object in self.other_objects:
+            self.assertTrue(other_object in metadata.other_objects)
+
+        for group in self.groups:
+            self.assertTrue(group.name in map(lambda grp: grp.name,
+                                              metadata.groups))
+
+        for group in self.groups:
+            matching_group = None
+            for grp in metadata.groups:
+                if grp.name == group.name:
+                    matching_group = grp
+                    break
+            for f_object in group.file_objects:
+                self.assertTrue(f_object in matching_group.file_objects)
+
         os.remove(metadata_file)
 
 if __name__ == '__main__':




reply via email to

[Prev in Thread] Current Thread [Next in Thread]