[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[minion-cvs] Refactor incoming queues for better separation of permi...



Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv8806/lib/mixminion

Modified Files:
	ClientMain.py Common.py 
Log Message:
Refactor incoming queues for better separation of permissions; add publication

Index: ClientMain.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/ClientMain.py,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- ClientMain.py	21 May 2003 18:03:33 -0000	1.74
+++ ClientMain.py	23 May 2003 22:49:29 -0000	1.75
@@ -11,16 +11,18 @@
 
 import anydbm
 import binascii
+import errno
 import cPickle
 import getopt
 import getpass
 import os
 import re
+import signal
 import stat
 import string
 import sys
 import time
-import urllib
+import urllib2
 from types import ListType
 
 import mixminion.BuildMessage
@@ -70,13 +72,6 @@
     _CLIENT_LOCKFILE = Lockfile(filename)
 
 #----------------------------------------------------------------------
-
-class MyURLOpener(urllib.FancyURLopener):
-    def http_error_default(self, url, fp, errcode, errmsg, headers):
-        message = fp.read()
-        fp.close()
-        raise UIError("Error connecting to %s: %s %s\n(Server said:\n%s)" % (url, errcode, errmsg, message))
-
 class ClientDirectory:
     """A ClientDirectory manages a list of server descriptors, either
        imported from the command line or from a directory."""
@@ -149,15 +144,30 @@
     def downloadDirectory(self):
         """Download a new directory from the network, validate it, and
            rescan its servers."""
+        # FFFF Make configurable
+        DIRECTORY_TIMEOUT = 15
         # Start downloading the directory.
         url = MIXMINION_DIRECTORY_URL
         LOG.info("Downloading directory from %s", url)
+        def sigalrmHandler(sig, _):
+            pass
+        signal.signal(signal.SIGALRM, sigalrmHandler)
         try:
-            infile = MyURLOpener().open(url)
-        except IOError, e:
-            raise UIError(
-                ("Couldn't connect to directory server: %s.\n"
-                 "Try '-D no' to run without downloading a directory.")%e)
+            try:
+                infile = urllib2.urlopen(url)
+            except IOError, e:
+                raise UIError(
+                    ("Couldn't connect to directory server: %s.\n"
+                     "Try '-D no' to run without downloading a directory.")%e)
+            except socket.error, e:
+                if e.errno == errno.EINTR:
+                    raise UIError("Connection to directory server timed out")
+                else:
+                    raise UIError("Error connecting: %s",e)
+                raise UIError
+        finally:
+            signal.alarm(0)
+        
         # Open a temporary output file.
         if url.endswith(".gz"):
             fname = os.path.join(self.dir, "dir_new.gz")

Index: Common.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Common.py,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -d -r1.76 -r1.77
--- Common.py	21 May 2003 18:03:33 -0000	1.76
+++ Common.py	23 May 2003 22:49:30 -0000	1.77
@@ -402,12 +402,12 @@
     finally:
         f.close()
 
-def writePickled(fn, obj):
+def writePickled(fn, obj, mode=0600):
     """Given a filename and an object to be pickled, pickles the object into
        a temporary file, then replaces the file with the temporary file.
     """
     tmpname = fn + ".tmp"
-    f, tmpname = openUnique(tmpname, 'wb')
+    f, tmpname = openUnique(tmpname, 'wb', mode)
     try:
         try:
             cPickle.dump(obj, f, 1)
@@ -1167,7 +1167,7 @@
         if f is not None:
             f.close()
 
-def openUnique(fname, mode='w'):
+def openUnique(fname, mode='w', perms=0600):
     """Helper function. Returns a file open for writing into the file named
        'fname'.  If fname already exists, opens 'fname.1' or 'fname.2' or
        'fname.3' or so on."""
@@ -1175,7 +1175,7 @@
     idx = 0
     while 1:
         try:
-            fd = os.open(fname, os.O_WRONLY|os.O_CREAT|os.O_EXCL, 0600)
+            fd = os.open(fname, os.O_WRONLY|os.O_CREAT|os.O_EXCL, perms)
             return os.fdopen(fd, mode), fname
         except OSError:
             pass