Send cache hit/miss status updates to stdout instead of stderr and add some more...
authorZac Medico <zmedico@gentoo.org>
Wed, 22 Aug 2007 04:21:59 +0000 (04:21 -0000)
committerZac Medico <zmedico@gentoo.org>
Wed, 22 Aug 2007 04:21:59 +0000 (04:21 -0000)
svn path=/main/trunk/; revision=7656

pym/portage/getbinpkg.py

index 8ca6642d2878fa2c84cef21818513f7768c5ce2c..e39b365024481fcd59c2a0b9bc6b0ab74e688d4b 100644 (file)
@@ -458,11 +458,12 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache=
                makepickle = "/var/cache/edb/metadata.idx.most_recent"
 
        conn,protocol,address,params,headers = create_conn(baseurl, conn)
-
+       out = sys.stdout
        try:
                metadatafile = open("/var/cache/edb/remote_metadata.pickle")
                metadata = cPickle.load(metadatafile)
-               sys.stderr.write("Loaded metadata pickle.\n")
+               out.write("Loaded metadata pickle.\n")
+               out.flush()
                metadatafile.close()
        except (cPickle.UnpicklingError, OSError, IOError, EOFError):
                metadata = {}
@@ -502,10 +503,12 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache=
                                        sys.stderr.write("--- "+str(e)+"\n")
                                        if trynum < 3:
                                                sys.stderr.write("Retrying...\n")
+                                       sys.stderr.flush()
                                        mytempfile.close()
                                        continue
                                if match_in_array([mfile],suffix=".gz"):
-                                       sys.stderr.write("gzip'd\n")
+                                       out.write("gzip'd\n")
+                                       out.flush()
                                        try:
                                                import gzip
                                                mytempfile.seek(0)
@@ -516,6 +519,7 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache=
                                        except Exception, e:
                                                mytempfile.close()
                                                sys.stderr.write("!!! Failed to use gzip: "+str(e)+"\n")
+                                               sys.stderr.flush()
                                        mytempfile.close()
                                try:
                                        metadata[baseurl]["data"] = cPickle.loads(data)
@@ -523,13 +527,15 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache=
                                        metadata[baseurl]["indexname"] = mfile
                                        metadata[baseurl]["timestamp"] = int(time.time())
                                        metadata[baseurl]["modified"]  = 0 # It's not, right after download.
-                                       sys.stderr.write("Pickle loaded.\n")
+                                       out.write("Pickle loaded.\n")
+                                       out.flush()
                                        break
                                except SystemExit, e:
                                        raise
                                except Exception, e:
                                        sys.stderr.write("!!! Failed to read data from index: "+str(mfile)+"\n")
                                        sys.stderr.write("!!! "+str(e)+"\n")
+                                       sys.stderr.flush()
                        try:
                                metadatafile = open("/var/cache/edb/remote_metadata.pickle", "w+")
                                cPickle.dump(metadata,metadatafile)
@@ -539,19 +545,21 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache=
                        except Exception, e:
                                sys.stderr.write("!!! Failed to write binary metadata to disk!\n")
                                sys.stderr.write("!!! "+str(e)+"\n")
+                               sys.stderr.flush()
                        break
        # We may have metadata... now we run through the tbz2 list and check.
        ext_miss = 0
        ext_hit = 0
-       sys.stderr.write(yellow("cache miss: '"+str(ext_miss)+"'")+" --- "+green("cache hit: '"+str(ext_hit)+"'"))
+       out.write(yellow("cache miss: '"+str(ext_miss)+"'")+" --- "+green("cache hit: '"+str(ext_hit)+"'"))
+       out.flush()
        binpkg_filenames = set()
        for x in tbz2list:
                x = os.path.basename(x)
                binpkg_filenames.add(x)
                if x not in metadata[baseurl]["data"]:
                        ext_miss += 1
-                       sys.stderr.write("\r"+yellow("cache miss: '"+str(ext_miss)+"'")+" --- "+green("cache hit: '"+str(ext_hit)+"'"))
-                       sys.stderr.flush()
+                       out.write("\r"+yellow("cache miss: '"+str(ext_miss)+"'")+" --- "+green("cache hit: '"+str(ext_hit)+"'"))
+                       out.flush()
                        metadata[baseurl]["modified"] = 1
                        myid = None
                        for retry in xrange(3):
@@ -572,10 +580,11 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache=
                                metadata[baseurl]["data"][x] = make_metadata_dict(myid)
                        elif verbose:
                                sys.stderr.write(red("!!! Failed to retrieve metadata on: ")+str(x)+"\n")
+                               sys.stderr.flush()
                else:
                        ext_hit += 1
-                       sys.stderr.write("\r"+yellow("cache miss: '"+str(ext_miss)+"'")+" --- "+green("cache hit: '"+str(ext_hit)+"'"))
-                       sys.stderr.flush()
+                       out.write("\r"+yellow("cache miss: '"+str(ext_miss)+"'")+" --- "+green("cache hit: '"+str(ext_hit)+"'"))
+                       out.flush()
        # Cleanse stale cache for files that don't exist on the server anymore.
        stale_cache = set(metadata[baseurl]["data"]).difference(binpkg_filenames)
        if stale_cache:
@@ -584,8 +593,9 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache=
                metadata[baseurl]["modified"] = 1
        del stale_cache
        del binpkg_filenames
-       sys.stderr.write("\n")
-       
+       out.write("\n")
+       out.flush()
+
        try:
                if metadata[baseurl].has_key("modified") and metadata[baseurl]["modified"]:
                        metadata[baseurl]["timestamp"] = int(time.time())
@@ -601,6 +611,7 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache=
        except Exception, e:
                sys.stderr.write("!!! Failed to write binary metadata to disk!\n")
                sys.stderr.write("!!! "+str(e)+"\n")
+               sys.stderr.flush()
 
        if not keepconnection:
                conn.close()