r353 - /debtorrent/trunk/split_cache_for_all.py
camrdale-guest at users.alioth.debian.org
camrdale-guest at users.alioth.debian.org
Thu Jan 24 07:05:01 UTC 2008
Author: camrdale-guest
Date: Thu Jan 24 07:05:01 2008
New Revision: 353
URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=353
Log:
Add a new script to transition cache directories from binary-arch to bianry-all directories.
Added:
debtorrent/trunk/split_cache_for_all.py (with props)
Added: debtorrent/trunk/split_cache_for_all.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/split_cache_for_all.py?rev=353&op=file
==============================================================================
--- debtorrent/trunk/split_cache_for_all.py (added)
+++ debtorrent/trunk/split_cache_for_all.py Thu Jan 24 07:05:01 2008
@@ -1,0 +1,56 @@
+#!/usr/bin/env python
+#
+# see LICENSE.txt for license information
+#
+# $Id$
+
+import os
+from re import subn
+from sys import argv
+
+try:
+ from debian_bundle import debfile
+except:
+ raise ImportError, 'You must install the python-debian package to use this script'
+
+def run(dirs):
+ if not dirs:
+ dirs = ['/var/cache/debtorrent']
+
+ for dir in dirs:
+ process(os.path.abspath(dir))
+
+def process(dir):
+ print "processing", dir
+ for subdir in os.listdir(dir):
+ (subdir_all, n) = subn(r'binary-[a-zA-Z0-9-]+([^a-zA-Z0-9-]?)', r'binary-all\1', subdir)
+ if n > 0 and subdir != subdir_all:
+ print " trying to move from", subdir
+ print " to", subdir_all
+ move(os.path.join(dir, subdir), os.path.join(dir, subdir_all))
+
+def move(subdir, subdir_all):
+ for root, dirs, files in os.walk(subdir):
+ for file in files:
+ if file.endswith('.deb'):
+ filename = os.path.join(root, file)
+ deb = debfile.DebFile(filename)
+ if deb.debcontrol().get('Architecture', '') == 'all':
+ newfile = subdir_all + filename[len(subdir):]
+ if os.path.exists(newfile):
+ print " not moving (destination exists)", os.path.basename(filename)
+ else:
+ print " moving", os.path.basename(filename)
+ os.renames(filename, newfile)
+
+if __name__ == '__main__':
+ if argv[1:2] == ['--help']:
+ print "Usage:", argv[0], "[directory directory ...]"
+ print
+ print " Will move all architecture:all files from the binary-arch"
+ print " directories in each directory, into the appropriate"
+ print " binary-all directory. If no directories are specified on"
+ print " the command-line, then it will use /var/cache/debtorrent"
+ exit(0)
+ else:
+ run(argv[1:])
Propchange: debtorrent/trunk/split_cache_for_all.py
------------------------------------------------------------------------------
svn:executable = *
Propchange: debtorrent/trunk/split_cache_for_all.py
------------------------------------------------------------------------------
svn:keywords = Id
More information about the Debtorrent-commits
mailing list