Closes #9929: improve dialog messages

authorJulien Jehannet <julien.jehannet@logilab.fr>
changesetadd96d4e78af
branchdefault
phasepublic
hiddenno
parent revision#e87f916ab822 Closes #9938: no repository name check (or unvalid)
child revision#807c0aa3f15a fix wrong assumption about set difference
files modified by this revision
__pkginfo__.py
apt_ftparchive.py
command.py
ldi.py
logging_handlers.py
# HG changeset patch
# User Julien Jehannet <julien.jehannet@logilab.fr>
# Date 1251111784 -7200
# Mon Aug 24 13:03:04 2009 +0200
# Node ID add96d4e78af1b4452dd36050c141cd2881ce95d
# Parent e87f916ab822a10bc1149c6f173f17c25e97e923
Closes #9929: improve dialog messages

diff --git a/__pkginfo__.py b/__pkginfo__.py
@@ -26,28 +26,28 @@
1  http://www.logilab.fr/ -- mailto:contact@logilab.fr'''
2 
3  short_desc = "tool for managing debian repositories at Logilab"
4 
5  long_desc = """
6 - debinstall provides a tool for managing debian repositories at
7 + debinstall provides the ldi command for managing debian repositories at
8   Logilab. We hope that it will, one day, be usefull to others.
9   .
10   It provides functionnality for : 
11    * checking validaty of incoming directory
12    * cleaning up of repositories
13    * more to come.
14  """
15 
16 -author = "Logilab"
17 -author_email = "devel@logilab.fr"
18 +author = "Logilab S.A."
19 +author_email = "contact@logilab.fr"
20 
21  # TODO - publish
22  web = "http://www.logilab.org/project/%s" % modname
23  ftp = "ftp://ftp.logilab.org/pub/%s" % modname
24 
25 
26 -scripts = ['bin/debinstall']
27 +scripts = ['bin/ldi']
28  debian_name = 'debinstall'
29  debian_maintainer = 'Alexandre Fayolle' 
30  debian_maintainer_email = 'alexandre.fayolle@logilab.fr'
31  pyversions = ["2.4"]
32 
diff --git a/apt_ftparchive.py b/apt_ftparchive.py
@@ -12,11 +12,11 @@
33  #
34  # You should have received a copy of the GNU General Public License along with
35  # this program; if not, write to the Free Software Foundation, Inc.,
36  # 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
37 
38 -"""wrapper functions to run the apt-ftparchive commande"""
39 +"""wrapper functions to run the apt-ftparchive command"""
40 
41  import os
42  import os.path as osp
43  from glob import glob
44  import subprocess
@@ -24,11 +24,11 @@
45 
46  from debinstall.command import CommandError
47  from debinstall.logging_handlers import CONSOLE
48 
49 
50 -logger = logging.getLogger('debinstall.apt-ftparchive')
51 +logger = logging.getLogger('ldi.apt-ftparchive')
52  logger.propagate= False
53  logger.addHandler(CONSOLE)
54 
55  def clean(debian_dir):
56      candidates = ['Packages*', 'Source*', 'Content*', 'Release*']
diff --git a/command.py b/command.py
@@ -35,11 +35,11 @@
57      arguments = "arg1"
58      def __init__(self, debug=False):
59          self.options = None
60          self.args = None
61          self.repo_name = None
62 -        self.logger = logging.getLogger('debinstall.%s' % self.name)
63 +        self.logger = logging.getLogger('ldi.%s' % self.name)
64          self.logger.addHandler(CONSOLE)
65          self.logger.propagate = False
66 
67      def register(self, option_parser):
68          option_parser.add_command(self.name,
diff --git a/ldi.py b/ldi.py
@@ -156,19 +156,19 @@
69                                 % repository)
70 
71          if distrib:
72              destdir = osp.join(destdir, distrib)
73              if not osp.isdir(destdir):
74 -                raise CommandError("distribution '%s' not found. Use ldi list to "\
75 -                                   "check" % distrib)
76 +                raise CommandError("%s: distribution '%s' not found. Use ldi list to "\
77 +                                   "check" % (repository, distrib))
78 
79              # Print a warning in case of using symbolic distribution names
80              destdir = osp.realpath(destdir)
81              dereferenced = osp.basename(destdir)
82              if distrib and  dereferenced != distrib:
83 -                self.logger.warn("deferences symlinked distribution '%s' to '%s' "
84 -                                 % (distrib, dereferenced))
85 +                self.logger.warn("%s: deferences symlinked distribution '%s' to '%s' "
86 +                                 % (repository, distrib, dereferenced))
87 
88          return osp.realpath(destdir)
89 
90      def _check_changes_file(self, changes_file):
91          """basic tests to determine debian changes file"""
@@ -405,48 +405,56 @@
92 
93      def process(self):
94          if not self.args:
95              destdir = self.get_config_value('destination')
96              repositories = self.get_repo_list()
97 -            self.logger.info("%s available repositories in %s"
98 +            self.logger.info("%s available repositories in '%s'"
99                               % (len(repositories), destdir))
100 -            print [repository for repository in repositories]
101 -        elif len(self.args)==1 and not self.options.distribution:
102 -            repository = self.args[0]
103 -            path = self._check_repository(repository, self.options.section)
104 +            repositories = sorted([repository for repository in repositories])
105 +            print(os.linesep.join(repositories))
106 +            return
107 +
108 +        repository = self.args[0]
109 +        path = self._check_repository(repository, self.options.section)
110 +        if len(self.args)==1 and not self.options.distribution:
111              lines = []
112              for root, dirs, files in os.walk(path):
113                  if dirs:
114                      for d in dirs:
115 -                        line = str(root.split('/')[4:7] + [d,])
116 +                        line = "%s/%s" % (repository, d)
117                          if osp.islink(osp.join(root, d)):
118 -                            line += ' (symlinked to %s)' % os.readlink(osp.join(root, d))
119 +                            line += ' is symlinked to %s' % os.readlink(osp.join(root, d))
120                          else:
121                              nb = len(glob.glob(osp.join(root, d, "*.changes")))
122                              if nb:
123                                  line += " contains %d changes files" % nb
124                              else:
125                                  line += " is empty"
126                          lines.append(line)
127 -            self.logger.info("%s available %s section(s) in %s"
128 -                             % (len(lines), self.options.section, path))
129 +            self.logger.info("%s: %s available %s section(s)"
130 +                             % (repository, len(lines), self.options.section))
131              for line in lines: print line
132          else:
133 -            repository = self.args[0]
134              self._print_changes_files(repository, self.options.section,
135                                        self.options.distribution)
136 
137 -    def _print_changes_files(self, repository, section, distribution=None):
138 +        if self.options.section == 'incoming':
139 +            self.logger.info("use option 'ldi list -s dists %s' to list published content" % repository)
140 +
141 +    def _print_changes_files(self, repository, section, distribution):
142          """print information about a repository and inside changes files"""
143          filenames = self._find_changes_files(repository, section, distribution)
144 -        filenames = [filename.rsplit('/', 4)[1:] for filename in filenames]
145 
146          if not filenames:
147 -            self.logger.warn("no changes file was found in repository '%s'" % repository)
148 -
149 -        for f in filenames:
150 -            print f
151 +            self.logger.warn("%s/%s: no changes file found" % (repository,
152 +                                                               distribution))
153 +        else:
154 +            self.logger.info("%s/%s: %s available changes files"
155 +                             % (repository, distribution, len(filenames)))
156 +            filenames = [filename.rsplit('/', 4)[1:] for filename in filenames]
157 +            for f in filenames:
158 +                print("%s/%s: %s" % (f[0], f[2], f[-1]))
159 
160      def get_repo_list(self):
161          """return list of repository and do some checks"""
162          destdir = self.get_config_value('destination')
163          confdir = self.get_config_value('configurations')
@@ -509,10 +517,11 @@
164              for filename in filenames:
165                  self.perform_changes_file(filename, "", sht.rm)
166          else:
167              try:
168                  self.logger.warn("you're asking for a large deletion of data...")
169 +                self.logger.warn("use ldi list command to verify actual content")
170                  import time
171                  time.sleep(1)
172                  confirm = raw_input("Do you want to continue (type: Yes, I do) ? ")
173              except KeyboardInterrupt:
174                  sys.exit(1)
diff --git a/logging_handlers.py b/logging_handlers.py
@@ -21,11 +21,11 @@
175 
176 
177  isatty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
178 
179  CONSOLE = logging.StreamHandler()
180 -LOG_FORMAT = '[%(levelname)-8s] %(name)-10s: %(message)s'
181 +LOG_FORMAT = '%(name)s: %(message)s'
182 
183  if not isatty or '--no-color' in sys.argv:
184      formatter = logging.Formatter(LOG_FORMAT)
185  else:
186      formatter = ColorFormatter(LOG_FORMAT)