script for pack-n-clean bzr [shared] repos
Eduardo O. Padoan
eduardo.padoan at gmail.com
Fri Dec 26 23:01:02 GMT 2008
On Fri, Dec 26, 2008 at 8:54 AM, Alexander Belchenko <bialix at ukr.net> wrote:
> This script can walk you directory tree, looking for [shared] repositories,
> packs them and optionally clean obsolete_packs.
>
> Very simple, but perhaps will be useful for someone.
This could be refactored as a plugin.
> #!/usr/bin/python
> # Copyright (C) Alexander Belchenko, 2008
> # License: GPL v2
>
> """Walk directories and pack all [shared] repositories.
>
> Usage:
> bzr-pack-all.py [OPTIONS] [DIR]
>
> Options:
> --clean - clean obsolete_packs directories after packing.
> --dont-pack - don't pack repo (if you want only clean obsoletes).
>
> Argument:
> DIR - root directory to walk and pack.
> """
>
> import sys
>
> def main(argv=None):
> import getopt
> import os
>
> if argv is None:
> argv = sys.argv[1:]
>
> need_pack = True
> need_clean = False
> root_dir = u'.'
>
> try:
> opts, args = getopt.gnu_getopt(argv, "h", ["help", "clean",
> "dont-pack"])
> for o, a in opts:
> if o in ("-h", "--help"):
> print __doc__
> return 0
> elif o == "--dont-pack":
> need_pack = False
> elif o == "--clean":
> need_clean = True
>
> if len(args) > 1:
> raise getopt.GetoptError("Too much arguments.")
>
> except getopt.GetoptError, e:
> print str(e)
> print __doc__
> return 1
>
> if len(args) == 1:
> root_dir = args[0]
>
> cwd = os.getcwdu()
> for root, dirs, files in os.walk(root_dir):
> if '.bzr' in dirs:
> bzrdir = os.path.join(root, '.bzr')
> if os.path.isdir(os.path.join(bzrdir, 'repository', 'packs')):
> # packs repo found
> if need_pack:
> print 'Packing repo at', root
> os.chdir(root)
> try:
> os.system('bzr pack')
> finally:
> os.chdir(cwd)
> if need_clean:
> obs_dir = os.path.join(bzrdir, 'repository',
> 'obsolete_packs')
> print 'Cleaning obsolete_packs in', obs_dir
> obsoletes = os.listdir(obs_dir)
> for f in obsoletes:
> try:
> name = os.path.join(obs_dir, f)
> os.remove(name)
> except (OSError, IOError), e:
> print ' Unable to delete %s: %s' % (name,
> str(e))
> dirs.remove('.bzr')
> return 0
>
> if __name__ == '__main__':
> sys.exit(main())
>
>
--
Eduardo de Oliveira Padoan
http://djangopeople.net/edcrypt/
"Distrust those in whom the desire to punish is strong." -- Goethe,
Nietzsche, Dostoevsky
More information about the bazaar
mailing list