| 1 |
#!/usr/bin/python
|
| 2 |
# A script to recursively update a CVS checkout, skipping directories for
|
| 3 |
# languages you do not know or care about. Useful for translators who only want
|
| 4 |
# a checkout of the directories for English and their own language.
|
| 5 |
#
|
| 6 |
# This special script is needed because:
|
| 7 |
# - "cvs up -d" will check out languages most people usually do not care about
|
| 8 |
# - however plain "cvs up" does not create directories newly created in the
|
| 9 |
# repository
|
| 10 |
#
|
| 11 |
# Copyright 2010 Marcin Owsiany <porridge@debian.org>
|
| 12 |
|
| 13 |
import sys
|
| 14 |
import logging
|
| 15 |
import os
|
| 16 |
import subprocess
|
| 17 |
|
| 18 |
logging.basicConfig(level=logging.INFO)
|
| 19 |
|
| 20 |
logging.info('Getting list of entries in the repository.')
|
| 21 |
# Set LANG=C as we need to parse command output
|
| 22 |
env = dict(os.environ)
|
| 23 |
env['LANG'] = 'C'
|
| 24 |
lines = subprocess.Popen(['cvs', 'ls', '-l'], stdout=subprocess.PIPE, env=env).communicate()[0]
|
| 25 |
repo_dirs = set()
|
| 26 |
for line in lines.split('\n'):
|
| 27 |
if not line:
|
| 28 |
pass
|
| 29 |
elif line.startswith('-'):
|
| 30 |
pass
|
| 31 |
elif line.startswith('d'):
|
| 32 |
repo_dirs.add(line.split(None, 4)[4])
|
| 33 |
else:
|
| 34 |
logging.warn('Unexpected line: %s', line)
|
| 35 |
|
| 36 |
logging.info('Getting list of known languages.')
|
| 37 |
lines = subprocess.Popen(['make', 'list-languages'], stdout=subprocess.PIPE).communicate()[0]
|
| 38 |
langs = set(lines.split())
|
| 39 |
|
| 40 |
logging.info('Getting list of checked-out directories.')
|
| 41 |
local_dirs = set(e for e in os.listdir('.') if os.path.isdir(e))
|
| 42 |
|
| 43 |
logging.debug('Dirs in repo: %s', ' '.join(sorted(repo_dirs)))
|
| 44 |
logging.debug('LANGS : %s', ' '.join(sorted(langs)))
|
| 45 |
logging.debug('Dirs in . : %s', ' '.join(sorted(local_dirs)))
|
| 46 |
|
| 47 |
# We want:
|
| 48 |
# - all currently checked out directories (i.e. ones that exist locally and in
|
| 49 |
# the repository)
|
| 50 |
checked_out = local_dirs.intersection(repo_dirs)
|
| 51 |
# - all directories in repo that are not langs
|
| 52 |
specials = repo_dirs - langs
|
| 53 |
# However we do not want e.g. stale language directories which are being
|
| 54 |
# transitioned to a new name. So we keep a list of known non-language
|
| 55 |
# directories, and we warn (and ignore) if the above encounters anything else.
|
| 56 |
known_specials = set(['Perl', 'po'])
|
| 57 |
mysterious = specials - known_specials
|
| 58 |
|
| 59 |
to_update = known_specials | checked_out
|
| 60 |
if to_update:
|
| 61 |
logging.info('Updating recursively: %s', ' '.join(to_update))
|
| 62 |
subprocess.Popen(['cvs', '-q', 'up', '-dP'] + sorted(list(to_update))).wait()
|
| 63 |
else:
|
| 64 |
logging.warn('No directories to update recursively.')
|
| 65 |
logging.info('Updating current directory.')
|
| 66 |
subprocess.Popen(['cvs', '-q', 'up', '-lP']).wait()
|
| 67 |
|
| 68 |
if mysterious:
|
| 69 |
logging.warn('The following directories exist in repo but are neither '
|
| 70 |
'known special dirs nor in LANGUAGES in top Makefile. '
|
| 71 |
'Please delete them or add to known_specials in %s: %s',
|
| 72 |
sys.argv[0], ' '.join(mysterious))
|