Kill the 'lgp prepare' command (closes #66588)

authorJulien Cristau <julien.cristau@logilab.fr>
changesetb1f71d3534de
branchdefault
phasepublic
hiddenno
parent revision#cd02e85ad475 Kill lgp piuparts (closes #66587)
child revision#c3a5657af351 cleanup dust of stuff killed some time ago
files modified by this revision
lgp/__init__.py
lgp/preparedist.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1305796024 -7200
# Thu May 19 11:07:04 2011 +0200
# Node ID b1f71d3534dea0495161f3cfdc1f342a88db2460
# Parent cd02e85ad475088f04cd8f5eb81c1c897e8f34fa
Kill the 'lgp prepare' command (closes #66588)

diff --git a/lgp/__init__.py b/lgp/__init__.py
@@ -27,13 +27,11 @@
1  BUILD_LOG_EXT   = '.lgp-build'
2 
3  def run(args):
4      parser = OptionParser()
5      parser.usage = 'lgp COMMAND [options] <pkgdir> ...'
6 -    COMMANDS = [('prepare', 'logilab.devtools.lgp.preparedist',
7 -                 'process to prepare distrib'),
8 -                ('build', 'logilab.devtools.lgp.build',
9 +    COMMANDS = [('build', 'logilab.devtools.lgp.build',
10                   'build debian and source packages'),
11                  ('tag', 'logilab.devtools.lgp.tag',
12                   'tag package repository'),
13                  ('check', 'logilab.devtools.lgp.check',
14                   'check that package is ready to be built'),
diff --git a/lgp/preparedist.py b/lgp/preparedist.py
@@ -1,222 +0,0 @@
15 -# -*- coding: utf-8 -*-
16 -
17 -import os, os.path as osp
18 -import sys
19 -from stat import ST_MTIME
20 -from cStringIO import StringIO
21 -from logilab.common.shellutils import cp
22 -
23 -import logilab.devtools
24 -from logilab.devtools.lib import TextReporter
25 -from logilab.devtools.lib.pkginfo import PackageInfo
26 -from logilab.devtools.lib.changelog import ChangeLog
27 -
28 -
29 -TEMPLATE_DIR = osp.join(logilab.devtools.__path__[0], 'templates')
30 -
31 -ADDITIONAL_DESCR="""LOGILAB provides services in the fields of XML techniques and advanced
32 -computing (implementation of intelligent agents, knowledge management,
33 -natural language processing, statistical analysis, data mining, etc.),
34 -and also trainings on Python, XML, UML, Object Oriented design, design
35 -patterns use and other cutting edge topics. To know more about
36 -Logilab, visit http://www.logilab.com/.
37 -
38 -Logilab is also a strong supporter of the Free Software movement, and an
39 -active member of the Python and Debian communities. Logilab's open 
40 -source projects can be found on http://www.logilab.org/."""
41 -
42 -SEPARATOR = '+' * 72
43 -
44 -def ask(msg, options): 
45 -    default = [opt for opt in options if opt.isupper()]
46 -    assert len(default) == 1, "should have one (and only one) default value"
47 -    default = default[0]
48 -    answer = None
49 -    while str(answer) not in options.lower():
50 -        try:
51 -            answer = raw_input('%s [%s] ' % (msg, '/'.join(options)))
52 -        except (EOFError, KeyboardInterrupt):
53 -            print
54 -            sys.exit(0)
55 -        answer = answer.strip().lower() or default.lower()
56 -    return answer
57 -
58 -def confirm(msg):
59 -    return ask(msg, 'Yn') == 'y'
60 -
61 -def cond_exec(cmd, confirm=False, retry=False, force=False):
62 -    """demande confirmation, retourne 0 si oui, 1 si non"""
63 -    # ask confirmation before execution
64 -    if confirm:
65 -        answer = ask("Execute %s ?" % cmd, 'Ynq')
66 -        if answer == 'q':
67 -            sys.exit(0)
68 -        if answer == 'n':
69 -            return False
70 -    while True:
71 -        # if execution failed ask wether to continue or retry
72 -        if os.system(cmd):
73 -            if not force:
74 -                if retry:
75 -                    answer = ask('Continue ?', 'yNr')
76 -                else:
77 -                    answer = ask('Continue ?', 'yN')
78 -            else:
79 -                answer = 'y'
80 -            if answer == 'y':
81 -                return True
82 -            elif retry and answer == 'r':
83 -                continue 
84 -            else:
85 -                sys.exit(0)
86 -        else:
87 -            return False
88 -
89 -def install_copying(license):
90 -    """ensure COPYING is up to date"""
91 -    license_file = osp.join(TEMPLATE_DIR, 'licenses', 'full_%s.txt' % license)
92 -    if osp.isfile(license_file) and confirm('COPYING file checking ?'):
93 -        if osp.isfile('COPYING'):
94 -            # update COPYING file if needed
95 -            if os.stat(license_file)[ST_MTIME] > os.stat('COPYING')[ST_MTIME]:
96 -                cp(license_file, 'COPYING')
97 -            else:
98 -                print "COPYING file is up to date"
99 -        else:
100 -            cp(license_file, 'COPYING')
101 -
102 -
103 -def runtests(projdir=os.getcwd()):
104 -    """runs unit tests"""
105 -    testdirs = ('test', 'tests')
106 -    for testdir in testdirs:
107 -        if osp.isdir(testdir):
108 -            os.chdir(testdir)
109 -            cond_exec('pytest', confirm=True, retry=True)
110 -            os.chdir(projdir)
111 -            break
112 -
113 -def close_changelog(projdir=os.getcwd()):
114 -    """closes the projects's ChangeLog"""
115 -    if osp.isfile('ChangeLog') and confirm('close ChangeLog ?'):
116 -        # chmod u+w ChangeLog
117 -        os.system('chmod 664 ChangeLog')
118 -        # os.system('changelog close')
119 -        chlg = ChangeLog('ChangeLog')
120 -        try:
121 -            chlg.close(projdir)
122 -            print "I:changelog closed for revision:", chlg.get_latest_revision()
123 -            chlg.save()
124 -        except Exception, exc:
125 -            print "An error occured while closing Changelog:", exc
126 -            if not confirm('Continue ?'):
127 -                sys.exit(1)
128 -
129 -
130 -def build_documentation(projdir=os.getcwd()):
131 -    """builds the project's documentation"""
132 -    if osp.isdir('doc') and (osp.isfile('doc/makefile') or osp.isfile('doc/Makefile')) and \
133 -           confirm('build documentation ?'):
134 -        os.chdir('doc')
135 -        cond_exec('make', retry=True)
136 -        os.chdir(projdir)
137 -
138 -
139 -def make_announce(pkginfo, filename):
140 -    if osp.isfile('announce.txt') and confirm('generate announce in %s ?' % filename):
141 -        stream = StringIO()
142 -        chglog = ChangeLog('ChangeLog')
143 -        chglog.extract(stream=stream)
144 -        whatsnew = stream.getvalue()
145 -        values = dict(CHANGELOG=whatsnew, VERSION=pkginfo.version,
146 -                      WEB=pkginfo.web, FTP=pkginfo.ftp,
147 -                      MAILINGLIST=pkginfo.mailinglist,
148 -                      LONG_DESC=pkginfo.long_desc, DISTNAME=pkginfo.name,
149 -                      ADDITIONAL_DESCR=ADDITIONAL_DESCR)
150 -        template = file('announce.txt').read()
151 -        announce = file(filename, 'w')
152 -        announce.write(template % values)
153 -        announce.close()
154 -
155 -
156 -DEFAULT_ACTIONS = ('pylint', 'copying', 'checkpackage',
157 -                   'runtests', 'changelog', 'doc', 'announce',
158 -                   'uptodate', 'clean')
159 -
160 -def add_options(parser):
161 -    parser.usage = "lgp prepare [options] [<project_dir>]"
162 -    parser.description += ". If <project_dir> is omitted, the current directory" \
163 -                          "will be used. Possible actions are: %s" % ', '.join(DEFAULT_ACTIONS)
164 -    parser.add_option('-o', '--only', action="append", dest="only",
165 -                      help="perform only that action (this option can be passed several times)",
166 -                      metavar='<ACTIONS>', default=[])
167 -    parser.add_option('--dist', dest='distdir', default=osp.expanduser('~/dists'),
168 -                      help='where to put results')
169 -    parser.max_args = 1
170 -
171 -
172 -def run(pkgdir, options, args):
173 -    os.chdir(pkgdir)
174 -    if osp.isfile('__init__.py'):
175 -        pkgtype = 'python'
176 -    else:
177 -        pkgtype = 'formation'
178 -    try:
179 -        out = sys.stderr
180 -        reporter = TextReporter(out, color=out.isatty())
181 -        pkginfo = PackageInfo(reporter, pkgdir)
182 -    except ImportError, exc:
183 -        sys.stderr.write("%r does not appear to be a valid package " % pkgdir)
184 -        sys.stderr.write("(no __pkginfo__ found)\n")
185 -        return
186 -    actions = options.only or DEFAULT_ACTIONS
187 -    if 'changelog' in actions:
188 -        # close project's ChangeLog
189 -        print SEPARATOR
190 -        close_changelog()
191 -    if pkgtype == 'python':
192 -        if 'pylint' in actions:
193 -            # run pylint
194 -            print SEPARATOR
195 -            cond_exec('pylint --ignore doc %s' % pkgdir, confirm=True, retry=True)
196 -        # update COPYING (license) file
197 -        if pkginfo.license and 'copying' in actions:
198 -            print SEPARATOR
199 -            install_copying(pkginfo.license)
200 -        # checkpackage
201 -        if 'checkpackage' in actions:
202 -            print SEPARATOR
203 -            cond_exec('lgp check', confirm=True, retry=True)
204 -    else:
205 -        # formation check only release number
206 -        if 'checkpackage' in actions:
207 -            print SEPARATOR
208 -            cond_exec('lgp check -o release_number', confirm=True, retry=True)
209 -    if 'runtests' in actions:
210 -        # run unit tests
211 -        print SEPARATOR
212 -        runtests()
213 -    if 'doc' in actions:
214 -        # builds the documentation
215 -        print SEPARATOR
216 -        build_documentation()
217 -    if 'announce' in actions:
218 -        # prepare ANNOUNCE file
219 -        if pkgtype == 'python':
220 -            print SEPARATOR
221 -            try:
222 -                if not osp.isdir(options.distdir):
223 -                    os.mkdir(options.distdir)
224 -            except IOError, exc:
225 -                sys.stderr.write('could not create directory %r (%s)\n' % (options.distdir, exc))
226 -                sys.exit(1)
227 -            filename = '%s/%s.announce' % (options.distdir, pkginfo.name)
228 -            make_announce(pkginfo, filename)
229 -    if 'clean' in actions:
230 -        # clean
231 -        print SEPARATOR
232 -        if confirm("nettoyage du répertoire de travail ?"):
233 -            patterns = ['*~', '*.pyc', '*.pyo', '*.o', '\#*', '.\#*']
234 -            search = ' -o '.join(['-name "%s" '%item for item in patterns])
235 -            os.system('find . "(" %s ")" -a -exec rm -f \{\} \; 2>/dev/null' % search)
236 -