r406 - in branches/rewrite: . debian src
Otavio Salvador
partial-mirror-devel@lists.alioth.debian.org
Mon, 13 Dec 2004 18:03:58 -0700
Author: otavio
Date: Mon Dec 13 18:03:56 2004
New Revision: 406
Added:
branches/rewrite/src/debpartial-mirror.py (contents, props changed)
Modified:
branches/rewrite/ (props changed)
branches/rewrite/debian/rules
Log:
r565@nurf: otavio | 2004-12-14T01:04:02.458829Z
Rename to .py
Modified: branches/rewrite/debian/rules
==============================================================================
--- branches/rewrite/debian/rules (original)
+++ branches/rewrite/debian/rules Mon Dec 13 18:03:56 2004
@@ -33,7 +33,7 @@
touch build-stamp
# Fill the vars
- sed "s/@VERSION@/$(shell dpkg-parsechangelog | grep '^Version:' | awk '{ print $$2; }')/g;s/@DATE@/$(shell dpkg-parsechangelog | grep '^Date:' | awk -F': ' '{ print $$2; }')/g" < src/debpartial-mirror.in > src/debpartial-mirror
+ sed "s/@VERSION@/$(shell dpkg-parsechangelog | grep '^Version:' | awk '{ print $$2; }')/g;s/@DATE@/$(shell dpkg-parsechangelog | grep '^Date:' | awk -F': ' '{ print $$2; }')/g" < src/debpartial-mirror.py > src/debpartial-mirror
clean:
dh_testdir
Added: branches/rewrite/src/debpartial-mirror.py
==============================================================================
--- (empty file)
+++ branches/rewrite/src/debpartial-mirror.py Mon Dec 13 18:03:56 2004
@@ -0,0 +1,175 @@
+#!/usr/bin/env python
+"""
+Tool to build partial debian mirrors (and more)
+"""
+
+# debpartial-mirror - partial debian mirror package tool
+# (c) 2004 Otavio Salvador <otavio@debian.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+# $Id$
+
+# -------
+# Imports
+# -------
+import getopt
+import signal
+import sys
+
+# Appending our lib directory to sys.path
+sys.path.append("/usr/share/debpartial-mirror")
+
+import Backend
+import Config
+import Download
+
+# ---------
+# Variables
+# ---------
+
+# Defaults
+conffile = "../etc/debpartial-mirror.conf"
+
+# User command descriptions
+cmnds_desc = {
+ 'all': 'Updates and upgrades the selected mirror(s)',
+ 'update': 'Update selected mirror(s) (download Package and Source lists)',
+ 'upgrade': 'Upgrade selected mirror(s) (download binary and source packages)',
+}
+
+# Sorted list of user commands
+cmnds_list = cmnds_desc.keys()
+cmnds_list.sort()
+
+# ---------
+# Functions
+# ---------
+
+def version():
+ """Print package version"""
+ print """debpartial-mirror @VERSION@ - Partial mirroring tool for Debian - @DATE@
+This program is free software and was released under the terms of the GNU General Public License
+"""
+
+def usage(ret=2):
+ """Print program usage message"""
+ global conffile
+ global cmnds_desc
+ global cmnds_list
+
+ cmnds_string = ""
+ for c in cmnds_list:
+ cmnds_string += " %-27s %s\n" % (c, cmnds_desc[c])
+
+ print """Usage: debpartial-mirror [OPTIONS] COMMAND [MIRROR]
+
+Where OPTIONS is one of:
+ -h, --help Display this help end exit
+ -c, --configfile=FILE Select a config file (currently '%s')
+ -v, --version Show program version
+
+COMMAND is one of:
+%s
+And MIRROR selects which mirror we should work with (all by default).
+""" % (conffile, cmnds_string)
+ sys.exit(ret)
+
+def sigint_handler(signum, frame):
+ print "\n\rInterrupting download due a user request ..."
+ d = Download.Download()
+ d.fetcher.running = False
+ d.join()
+ sys.exit(1)
+
+def main():
+ """Main program"""
+ global conffile
+ global cmnds_list
+
+ cmnd = None
+ sect = None
+
+ # Parse options
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], 'hvc:',
+ ["help", "version", "configfile="])
+ except getopt.GetoptError:
+ print "ERROR reading program options\n"
+ usage()
+
+ for o, v in opts:
+ if o in ("-h", "--help"):
+ usage()
+ if o in ("-v", "--version"):
+ version()
+ sys.exit(0)
+ if o in ("-c", "--configfile"):
+ if v == '':
+ usage()
+ conffile = v
+
+ if len(args) > 0:
+ cmnd = args[0]
+ if cmnd not in cmnds_list:
+ print "ERROR: Unknown command '%s'" % cmnd
+ usage()
+ if len(args) > 1:
+ sect = args[1]
+
+ # Load configuration file
+ try:
+ cnf = Config.Config(conffile)
+ except Config.InvalidOption, msg:
+ print("Wrong option [%s] found on [%s] section of '%s'."
+ % (msg.option, msg.section, conffile))
+ sys.exit(1)
+ except Config.InvalidSection, msg:
+ print("Wrong section [%s] found on '%s'."
+ % (msg.section, conffile))
+ sys.exit(1)
+ except Config.RequiredOptionMissing, msg:
+ print("Required option [%s] was missing on [%s] section of '%s'."
+ % (msg.option, msg.section, conffile))
+ sys.exit(1)
+
+ # Verify if the section is valid
+ if sect != None and not cnf.has_section(sect):
+ print("Unknown MIRROR [%s] on '%s'."
+ % (sect, conffile))
+ sys.exit(1)
+
+ # Get available backends
+ backends = []
+ for b in cnf.getBackends():
+ if sect != "" or b.section == sect:
+ backends.append(Backend.Backend(b.section, cnf))
+
+ for b in backends:
+ if cmnd == 'all':
+ b.update()
+ b.upgrade()
+ elif cmnd == 'update':
+ b.update()
+ elif cmnd == 'upgrade':
+ b.upgrade()
+ else:
+ usage()
+
+# ------------
+# Main Program
+# ------------
+if __name__ == '__main__':
+ signal.signal(signal.SIGINT, sigint_handler)
+ main()