diff options
author | Brian Harring <ferringb@gmail.com> | 2006-10-05 04:39:15 -0700 |
---|---|---|
committer | Brian Harring <ferringb@gmail.com> | 2006-10-05 04:39:15 -0700 |
commit | 2805c1bf0b1ff0a1792325368708f86355fecd33 (patch) | |
tree | 291cee854f5f99957ba30eaa64979b17b75dee41 /sandbox | |
parent | hg tests. (diff) | |
download | pkgcore-2805c1bf0b1ff0a1792325368708f86355fecd33.tar.gz pkgcore-2805c1bf0b1ff0a1792325368708f86355fecd33.tar.bz2 pkgcore-2805c1bf0b1ff0a1792325368708f86355fecd33.zip |
check the old sync code; still don't have snapshot reimplemented, but that code isn't usable (plus I'll be using tarsync and friends)
Diffstat (limited to 'sandbox')
-rw-r--r-- | sandbox/dead_code/sync/__init__.py | 6 | ||||
-rw-r--r-- | sandbox/dead_code/sync/cvs.py | 93 | ||||
-rw-r--r-- | sandbox/dead_code/sync/parseuri.py | 28 | ||||
-rw-r--r-- | sandbox/dead_code/sync/snapshot.py | 145 | ||||
-rw-r--r-- | sandbox/dead_code/sync/syncexceptions.py | 10 |
5 files changed, 0 insertions, 282 deletions
diff --git a/sandbox/dead_code/sync/__init__.py b/sandbox/dead_code/sync/__init__.py deleted file mode 100644 index 5c0eeeaf..00000000 --- a/sandbox/dead_code/sync/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -# sync/__init__.py; sync module namespace initialization -# Copyright 2004 Brian Harring <ferringb@gmail.com> -# Distributed under the terms of the GNU General Public License v2 - -from parseuri import parseSyncUri - diff --git a/sandbox/dead_code/sync/cvs.py b/sandbox/dead_code/sync/cvs.py deleted file mode 100644 index f804b041..00000000 --- a/sandbox/dead_code/sync/cvs.py +++ /dev/null @@ -1,93 +0,0 @@ -# cvs.py; provides cvs sync capabilities, encapsulates the necessary cvs binary calls -# Copyright 2004 Brian Harring <ferringb@gmail.com> -# Distributed under the terms of the GNU General Public License v2 - -import os, stat -from pkgcore.spawn import spawn, spawn_bash, CommandNotFound -#import sync -from pkgcore.const import CVS_BIN - -import sync.syncexceptions -class CVSIOError(sync.syncexceptions.SyncException): - def __init__(self, errmsg, command): - self.errmsg = errmsg - self.command = command - def __str__(self): - return "cvs error: command %s, %s" % (self.command, self.errmsg) - -class CvsHost: - def __init__(self, host_uri, cvs_binary=CVS_BIN): - if not os.access(cvs_binary, os.X_OK): - raise CommandNotFound(cvs_binary) - self.__binary = cvs_binary - #parse the bugger. - #new format. - #cvs://[CVS_RSH binary:]user@host:cvs_root:module - #example - #cvs://ssh:ferringb@dev.gentoo.org:/var/cvsroot:gentoo-x86 - #old format - #cvs://user@host:cvsroot - #implicit gentoo-x86 module, and ext w/ ssh. - #here we go. :/ - - if host_uri.count(":") >= 2: - self.__init_new_host_uri(host_uri) - else: - self.__init_deprecated_uri(host_uri) - - def __init_new_host_uri(self, host): - #cvs://ssh:ferringb@dev.gentoo.org:/var/cvsroot:gentoo-x86 - s = host.split(":") - if len(s) == 4: - self.__ext = s.pop(0) - s[0] = ":ext:" + s[0] - else: - self.__ext = None - self.__cvsroot = s[0] + ":" + s[1] - self.__cvsmodule = s[2] - - def __init_deprecated_uri(self, host): - self.__ext = "ssh" - self.__cvsmodule = "gentoo-x86" - self.__cvsroot = host - - def sync(self, local_path, verbosity=1, compress=False): - while local_path[-1] == "/": - local_path = local_path[:-1] - if compress: - c_arg = '-z9' - else: - c_arg = '' - - env = {} - if self.__ext: - env = {"CVS_RSH":self.__ext} - - l = len(self.__cvsmodule) - if not os.path.exists(local_path): - newdir = os.path.basename(local_path) - basedir = local_path[:-len(newdir)] - if os.path.exists(basedir+"/"+self.__cvsmodule): - raise Exception("unable to checkout to %s, module directory %s exists already" % \ - (basedir, self.__cvsmodule)) - elif os.path.exists(basedir+"/CVS"): - raise Exception("unable to checkout to %s, a CVS directory exists w/in already" % basedir) - command = "cd '%s' ; %s %s -d %s co -P %s" % \ - (basedir, self.__binary, c_arg, self.__cvsroot, self.__cvsmodule) - - ret = spawn_bash(command, env=env, opt_name="cvs co") - if ret: - raise CVSIOError("failed checkout", command) - if newdir != self.__cvsmodule: - ret = spawn(('mv', '%s/%s' % (basedir, self.__cvsmodule), local_path)) - if ret: - raise Exception("failed moving %s/%s to %s" % (basedir, self.__cvsmodule, local_path)) - elif stat.S_ISDIR(os.stat(local_path).st_mode): - - command = "cd '%s'; %s %s -d %s up" % (local_path, self.__binary, c_arg, self.__cvsroot) - ret = spawn_bash(command, env=env, opt_name="cvs up") - if ret: - raise CVSIOError("failed updated", command) - else: - raise Exception("%s exists, and is not a directory. rectify please" % local_path) - return True diff --git a/sandbox/dead_code/sync/parseuri.py b/sandbox/dead_code/sync/parseuri.py deleted file mode 100644 index 9cad6504..00000000 --- a/sandbox/dead_code/sync/parseuri.py +++ /dev/null @@ -1,28 +0,0 @@ -# parseuri.py; parses a SYNC uri, returning protocol/host_uri -# Copyright 2004-2006 Brian Harring <ferringb@gmail.com> -# Distributed under the terms of the GNU General Public License v2 - -"""WARNING, NEEDS WORK""" - -#sanitize this to use listdir -#~harring - -from pkgcore.const import RSYNC_HOST - -def parseSyncUri(uri): - """parse a SYNC uri, returning a tuple of protocol,host_uri""" - u = uri.lower() - if u.startswith("rsync") or not u: - if len(u) <= 5: - return ('rsync', RSYNC_HOST) - return ('rsync', u[8:]) - elif u.startswith("cvs://"): - u = u[6:] - return ('cvs', u) - elif u.startswith("snapshot"): - if len(u) == 8: - # the caller gets to randomly crapshoot a mirror for it. - return ('snapshot', None) - return ('snapshot', u[9:]) - else: - return (None, None) diff --git a/sandbox/dead_code/sync/snapshot.py b/sandbox/dead_code/sync/snapshot.py deleted file mode 100644 index f1f72706..00000000 --- a/sandbox/dead_code/sync/snapshot.py +++ /dev/null @@ -1,145 +0,0 @@ -# snapshot.py; provides the capability of fetching a portage tree snapshot, and syncing a tree with it. -# Copyright 2004-2006 Brian Harring <ferringb@gmail.com> -# Distributed under the terms of the GNU General Public License v2 - -"""WARNING, WILL NOT WORK (too much has changed)""" - -import os -import time -from pkgcore import chksums -from pkgcore.spawn import spawn -import shutil -import sync.rsync - -"""snapshot-http://gentoo.chem.wisc.edu/gentoo""" -class SnapshotHost: - def __init__(self, host_uri, snapshots_dir, tmp_dir, fetcher=None, use_md5=True): - if fetcher is None: - import transports.bundled_lib - fetcher = transports.bundled_lib.BundledConnection() - self.__fetcher = fetcher - self.__host_uri = host_uri - self.__tmpdir = tmp_dir - self.__snapshots_dir = snapshots_dir - self.__use_md5 = use_md5 - - def sync(self, local_path, verbosity=1): - attempts = 0 - downloaded = False - while attempts < 40 and not downloaded: - file = "portage-%s.tar.bz2" % time.strftime("%Y%m%d", - time.localtime(time.time() - (attempts*24*60*60))) - loc = self.__snapshots_dir + "/" + file - rem = self.__host_uri + "/" + file - downloaded = self.__fetch_snapshot(file, loc, rem, verbosity) - attempts += 1 - - if not downloaded: - # no snapshot, no syncy-poo. - return False - - return self.__apply_snapshot(loc, local_path, verbosity) - - def __apply_snapshot(self, snapshot, local_tree, verbosity): - """apply the actual snapshot. for different methods of this, inherit this class - and overload this function - current it untars to a temp location, and rsync's it over to local_path.""" - - #this should be checked - spawn(("tar", "-jxf", snapshot, "-C", self.__tmpdir)) - syncer = sync.rsync.RsyncHost("%s/portage/" % self.__tmpdir, local_host=True) - try: - ret = syncer.sync({}, local_tree, excludes=("/distfiles", "/local", "/packages"), verbosity=verbosity) - except sync.rsync.RSyncSyntaxError, e: - print "caught rsync syntax exception:", e - return False - except IOError, ie: - print "issue: ", ie - return False - if verbosity: - print "cleaning tempoary snapshot directory- %s/portage" % self.__tmpdir - shutil.rmtree(self.__tmpdir+"/portage") - - #nuke all other return codes. - if ret != True: - return False - return ret - - def __fetch_snapshot(self, file, loc, rem, verbosity): - grab_md5 = True - hash = None - md5 = None - md5_existed = False - ret = False - if self.__use_md5 and os.path.exists(loc+".md5sum"): - hash = self.__read_md5sum(loc+".md5sum") - if hash is None: - os.remove(loc+".md5sum") - else: - md5_existed = True - grab_md5 = False - - if self.__use_md5 and grab_md5: - ret = self.__fetcher.fetch(rem+".md5sum", file_name=loc+".md5sum", verbose=(verbosity==1)) - if not ret: - hash = self.__read_md5sum(loc+".md5sum") - - if ret: - if verbosity: - print "!!! failed to fetch md5 for %s" % file - return False - - # at this point we have the md5, and know the image *should* exist. - ret = False - if os.path.exists(loc): - if self.__use_md5: - md5 = portage_checksum.perform_md5(loc) - if hash == md5 or not self.__use_md5: - if verbosity: - print ">>> reusing %s" % loc - return True - else: - if verbosity: - print ">>> resuming %s" % rem - ret = self.__fetcher.resume(rem, file_name=loc, verbose=(verbosity==1)) - else: - if verbosity: - print ">>> fetching %s" % rem - ret = self.__fetcher.fetch(rem, file_name=loc, verbose=(verbosity==1)) - - if ret: - if verbosity: - print "!!! failed %s" % file - return False - - if self.__use_md5 and md5 is None: - md5 = portage_checksum.perform_md5(loc) - - if self.__use_md5 and md5_existed and md5 is not hash: - print ">>> re-grabbing the hash" - # grab the md5 anew to be safe. - os.remove(loc+".md5sum") - if not self.__fetcher.fetch(rem+".md5sum", file_name=loc+".md5sum", verbose=True): - hash = self.__read_md5sum(loc+".md5sum") - - if md5 != hash and self.__use_md5: - if verbosity: - print "!!! snapshots correct md5: %s" % hash - print "!!! snapshots actual md5 : %s" % md5 - print "!!! cycling to next candidate." - print - return False - # if this point has been reached, things are sane. - return True - - - def __read_md5sum(self, file): - try: - myf = open(file, "r") - hash = myf.readline().split()[0] - if len(hash) != 32: - return None - return hash - except (OSError, IOError, IndexError), e: - print e - return None diff --git a/sandbox/dead_code/sync/syncexceptions.py b/sandbox/dead_code/sync/syncexceptions.py deleted file mode 100644 index 1d4645ca..00000000 --- a/sandbox/dead_code/sync/syncexceptions.py +++ /dev/null @@ -1,10 +0,0 @@ -# syncexceptions.py: base sync exception class. not used currently (should be though) -# Copyright 2004 Brian Harring <ferringb@gmail.com> -# Distributed under the terms of the GNU General Public License v2 - -class SyncException(Exception): - """base sync exception""" - def __init__(self, value): - self.value = value - def __str__(self): - return value |