check the chroot image availability (Closes: #7858)

authorJulien Jehannet <julien.jehannet@logilab.fr>
changeset2082fa3736f5
branchdefault
phasepublic
hiddenno
parent revision#f4230606aadd use default exception printing
child revision#ca1b8c1a893e Fix the lgp version banner display
files modified by this revision
lgp/build.py
lgp/setup.py
lgp/utils.py
test/unittest_distributions.py
# HG changeset patch
# User Julien Jehannet <julien.jehannet@logilab.fr>
# Date 1237415110 -3600
# Wed Mar 18 23:25:10 2009 +0100
# Node ID 2082fa3736f5acd67ada79d2aa2b9fbb3202e0b7
# Parent f4230606aadd7f3d3be40b36ae640d20b10cfb20
check the chroot image availability (Closes: #7858)

diff --git a/lgp/build.py b/lgp/build.py
@@ -56,11 +56,12 @@
1 
2  def run(args):
3      """main function of lgp build command"""
4      try :
5          builder = Builder(args)
6 -        distributions = get_distributions(builder.config.distrib)
7 +        distributions = get_distributions(builder.config.distrib,
8 +                                          builder.config.basetgz)
9          logging.info("running for distribution(s): %s" % ', '.join(distributions))
10          architectures = get_architectures(builder.config.archi)
11 
12          if not builder.config.no_treatment:
13              run_pre_treatments(builder)
diff --git a/lgp/setup.py b/lgp/setup.py
@@ -39,11 +39,12 @@
14 
15  def run(args):
16      """ Main function of lgp setup command """
17      try :
18          setup = Setup(args)
19 -        distributions = get_distributions(setup.config.distrib)
20 +        distributions = get_distributions(setup.config.distrib,
21 +                                          setup.config.basetgz)
22          logging.info("running for distribution(s): %s" % ', '.join(distributions))
23 
24          if setup.config.command == "create":
25              if not check_keyrings(setup):
26                  logging.warn("you haven't installed archive keyring for ubuntu distributions")
diff --git a/lgp/utils.py b/lgp/utils.py
@@ -45,12 +45,14 @@
27                         'gutsy':'gutsy',
28                         'hardy':'hardy',
29                         'intrepid':'intrepid',
30                         'jaunty':'jaunty',
31                         'dapper':'dapper',
32 +                       'experimental': 'unstable',
33                        }
34 
35 +
36  class SGMLCatalog:
37      """ handle SGML catalog information
38      i.e. map dtds to their public id
39      """
40      def __init__(self, path, stream):
@@ -145,31 +147,26 @@
41              else:
42                  sys.exit(0)
43          else:
44              return False
45 
46 -def get_distributions(distrib=None):
47 +def get_distributions(distrib=None, basetgz=None):
48      """ensure that the target distributions exist or return all the valid distributions
49      """
50 -    if distrib is None:
51 +    if distrib is None or distrib == 'known':
52          distrib = KNOWN_DISTRIBUTIONS.keys()
53          return tuple(set(distrib))
54      elif distrib == 'target':
55          distrib = KNOWN_DISTRIBUTIONS.values()
56          return tuple(set(distrib))
57 -    elif distrib == 'known':
58 -        distrib = KNOWN_DISTRIBUTIONS
59 -        return tuple(set(distrib))
60      elif 'all' in distrib:
61 -        directories = glob.glob(join(os.getcwd(), "debian.*"))
62 -        distrib = [basename(d).split('.')[1] for d in directories]
63 -        # 'unstable' distribution should be always present
64 -        distrib.append('unstable')
65 +        distrib = [os.path.basename(f).split('-', 1)[0]
66 +                   for f in glob.glob(os.path.join(basetgz,'*.tgz'))]
67 +        return set(KNOWN_DISTRIBUTIONS) & set(distrib)
68 
69      mapped = ()
70 -    if type(distrib) is str:
71 -        distrib = distrib.split(',')
72 +    # check and filter if known
73      for t in distrib:
74          if t not in KNOWN_DISTRIBUTIONS:
75              raise DistributionException(t)
76          mapped += (KNOWN_DISTRIBUTIONS[t],)
77      distrib = mapped
diff --git a/test/unittest_distributions.py b/test/unittest_distributions.py
@@ -9,10 +9,13 @@
78  class DistributionTC(TestCase):
79 
80      def test_default_distribution(self):
81          # important for help generation
82          self.assertEquals(get_distributions("known"), tuple(set(KNOWN_DISTRIBUTIONS.keys())))
83 +        self.assertEquals(get_distributions(), tuple(set(KNOWN_DISTRIBUTIONS.keys())))
84 +        self.assertEquals(get_distributions("known"), tuple(set(KNOWN_DISTRIBUTIONS)))
85 +        self.assertEquals(get_distributions(), tuple(set(KNOWN_DISTRIBUTIONS)))
86 
87      def test_one_valid_distribution(self):
88          distrib = 'testing'
89          self.assertEquals(get_distributions(distrib),    (distrib,))
90          self.assertEquals(get_distributions((distrib,)), (distrib,))
@@ -34,7 +37,10 @@
91 
92      def test_mixed_unvalid_distributions(self):
93          distrib = get_distributions() + ('winnie the pooh',)
94          self.assertRaises(DistributionException, get_distributions, distrib)
95 
96 +    def test_all_distribution_keyword(self):
97 +        pass
98 +
99  if __name__  == '__main__':
100      unittest.main()