Created
August 12, 2016 20:55
-
-
Save mauritsvanrees/2d125cc9d58a7fdf92ce2dc5f352e5da to your computer and use it in GitHub Desktop.
Add Plone 5.1 classifier when Plone 5.0 classifier is there.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Add Plone 5.1 classifier when Plone 5.0 classifier is there. | |
Usage: | |
cd <coredev 5.1 branch> | |
cd src | |
python2.7 add51.py plone.app.favoritepackage | |
python2.7 add51.py * | |
""" | |
from textwrap import dedent | |
import os | |
import sys | |
PLONE50 = "Framework :: Plone :: 5.0" | |
PLONE51 = "Framework :: Plone :: 5.1" | |
NAME = 'setup.py' | |
CURRENT_DIR = os.getcwd() | |
for package in sys.argv[1:]: | |
package_dir = os.path.join(CURRENT_DIR, package) | |
if not os.path.isdir(package_dir): | |
continue | |
os.chdir(package_dir) | |
if not os.path.isfile(NAME): | |
continue | |
# print package name with some markup | |
print('\n\n' + '*' * 70 + '\n\n\n*** %s\n' % | |
os.path.basename(os.getcwd())) | |
# Check for Plone classifiers, add 5.1 when needed. | |
lines = [] | |
with open(NAME) as setup: | |
contents = setup.read() | |
if PLONE51 in contents: | |
print('5.1 ALREADY here.') | |
continue | |
if PLONE50 not in contents: | |
print('5.0 NOT here.') | |
continue | |
for line in contents.splitlines(): | |
lines.append(line) | |
if PLONE50 in line: | |
lines.append(line.replace(PLONE50, PLONE51)) | |
print('ADDED Plone 5.1 classifier') | |
if not lines: | |
# Some error in our logic? | |
print('ERROR no lines !?!') | |
sys.exit(1) | |
with open(NAME, 'w') as setup: | |
setup.write('\n'.join(lines)) | |
# Add line ending at end of file. | |
setup.write('\n') | |
print('git diff is:\n') | |
os.system('git diff') | |
print('\nPress enter or y for yes, anything else for no.') | |
answer = raw_input('Commit and push? [Y/n] ').lower() | |
if answer not in ('', 'y'): | |
print('\nNow what?') | |
print('u: Undo ALL changes in current dir, continue with next package.') | |
print('k: Keep change, continue with next package.') | |
print('q: Quit.') | |
# Loop until we have a correct answer | |
answer = '' | |
while not answer: | |
answer = raw_input('Your answer: ').lower() | |
if answer == 'u': | |
os.system('git checkout -- .') | |
print('\nUndid changes in %s' % package) | |
continue | |
elif answer == 'k': | |
print('\nKept changes in %s' % package) | |
continue | |
elif answer == 'q': | |
sys.exit(1) | |
answer = '' | |
# We should not get here. Easiest is to continue. | |
continue | |
# Commit and push. The '[ci skip'] in the message is for skipping | |
# continuous integration tests on Jenkins or Travis. | |
os.system(dedent("""git commit -am 'Added Plone 5.1 classifier to setup.py. | |
[ci skip]' && git push""")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment