[Python-checkins] distutils2: Fixed #1049: mkcfg was crashing on licence selection
tarek.ziade
python-checkins at python.org
Sat Nov 13 18:25:16 CET 2010
tarek.ziade pushed a99e29d63071 to distutils2:
http://hg.python.org/distutils2/rev/a99e29d63071
changeset: 818:a99e29d63071
tag: tip
user: Tarek Ziade <tarek at ziade.org>
date: Sat Nov 13 18:25:12 2010 +0100
summary: Fixed #1049: mkcfg was crashing on licence selection
files: CHANGES.txt, distutils2/mkcfg.py
diff --git a/CHANGES.txt b/CHANGES.txt
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -6,6 +6,8 @@
---------
- The setup runner supports more options:
+- XXX fill changes done in commands + compilers
+- Issue 10409: Fixed the Licence selector in mkcfg
1.0a3 - 2010-10-08
------------------
diff --git a/distutils2/mkcfg.py b/distutils2/mkcfg.py
--- a/distutils2/mkcfg.py
+++ b/distutils2/mkcfg.py
@@ -148,6 +148,16 @@
CLASSIFIERS = _build_classifiers_dict(_CLASSIFIERS_LIST)
+def _build_licences(classifiers):
+ res = []
+ for index, item in enumerate(classifiers):
+ if not item.startswith('License :: '):
+ continue
+ res.append((index, item.split(' :: ')[-1].lower()))
+ return res
+
+LICENCES = _build_licences(_CLASSIFIERS_LIST)
+
class MainProgram(object):
def __init__(self):
@@ -378,45 +388,44 @@
if not license:
return
- licenseWords = license.lower().split(' ')
+ license_words = license.lower().split(' ')
+ found_list = []
- foundList = []
- # TODO use enumerate
- for index in range(len(_CLASSIFIERS_LIST)):
- troveItem = _CLASSIFIERS_LIST[index]
- if not troveItem.startswith('License :: '):
- continue
- troveItem = troveItem[11:].lower()
+ for index, licence in LICENCES:
+ for word in license_words:
+ if word in licence:
+ found_list.append(index)
+ break
- allMatch = True
- for word in licenseWords:
- if not word in troveItem:
- allMatch = False
- break
- if allMatch:
- foundList.append(index)
+ if len(found_list) == 0:
+ print('ERROR: Could not find a matching license for "%s"' % \
+ license)
+ continue
question = 'Matching licenses:\n\n'
- # TODO use enumerate?
- for i in xrange(1, len(foundList) + 1):
- question += ' %s) %s\n' % (i, _CLASSIFIERS_LIST[foundList[i - 1]])
+
+ for index, list_index in enumerate(found_list):
+ question += ' %s) %s\n' % (index + 1,
+ _CLASSIFIERS_LIST[list_index])
+
question += ('\nType the number of the license you wish to use or '
'? to try again:')
- troveLicense = ask(question, required=False)
+ choice = ask(question, required=False)
- if troveLicense == '?':
+ if choice == '?':
continue
- if troveLicense == '':
+ if choice == '':
return
- # FIXME the int conversion can fail
- foundIndex = foundList[int(troveLicense) - 1]
- classifiers[_CLASSIFIERS_LIST[foundIndex]] = 1
+
try:
- return
- except IndexError:
+ index = found_list[int(choice) - 1]
+ except ValueError:
print ("ERROR: Invalid selection, type a number from the list "
"above.")
+ classifiers[_CLASSIFIERS_LIST[index]] = 1
+ return
+
def set_devel_status(self, classifiers):
while True:
choice = ask(dedent('''\
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list