Author: aum
Date: 2006-06-04 08:42:59 +0000 (Sun, 04 Jun 2006)
New Revision: 9046

Modified:
   trunk/apps/pyFreenet/code.leo
   trunk/apps/pyFreenet/fcp/node.py
   trunk/apps/pyFreenet/fcpput
   trunk/apps/pyFreenet/fcpput.py
   trunk/apps/pyFreenet/freedisk.py
Log:
implemented 'req sent' semaphore for nowait puts


Modified: trunk/apps/pyFreenet/code.leo
===================================================================
--- trunk/apps/pyFreenet/code.leo       2006-06-04 08:33:39 UTC (rev 9045)
+++ trunk/apps/pyFreenet/code.leo       2006-06-04 08:42:59 UTC (rev 9046)
@@ -29,7 +29,7 @@
 </v>
 <v t="aum.20060513073239" a="E"><vh>Package 'fcp'</vh>
 <v t="aum.20060516141235" tnodeList="aum.20060516141235"><vh>@nosent 
__init__.py</vh></v>
-<v t="aum.20060506215707" a="E" 
tnodeList="aum.20060506215707,aum.20060506215707.1,aum.20060506220237,aum.20060506215707.2,aum.20060506215707.3,aum.20060506220237.1,aum.20060506220237.2,aum.20060514223716,aum.20060506231352.1,aum.20060506231352,aum.20060507003931,aum.20060511001853,aum.20060521180804,aum.20060506224238,aum.20060514224855,aum.20060514224919,aum.20060514225725,aum.20060514223936,aum.20060514223822,aum.20060514223845,aum.20060514224020,aum.20060514124642,aum.20060514191601,aum.20060511205201,aum.20060506232639,aum.20060506232639.1,aum.20060511222538,aum.20060512101715,aum.20060511205201.1,aum.20060511205201.2,aum.20060506223545,aum.20060506224238.1,aum.20060506231352.2,aum.20060506220856,aum.20060506222005,aum.20060507124316,aum.20060511103841,aum.20060511103841.1,aum.20060511103952,aum.20060511103952.1,aum.20060514134235,aum.20060512181209,aum.20060514162944,aum.20060514124934,aum.20060512102840,aum.20060514164052,aum.20060509184020.1,aum.20060509184020.2,aum.20060509224119,aum.20060509224221,aum.20060603170554,aum.20060603231840,aum.20060603231840.1,aum.20060603231840.2"><vh>@nosent
 node.py</vh>
+<v t="aum.20060506215707" a="E" 
tnodeList="aum.20060506215707,aum.20060506215707.1,aum.20060506220237,aum.20060506215707.2,aum.20060506215707.3,aum.20060506220237.1,aum.20060506220237.2,aum.20060514223716,aum.20060506231352.1,aum.20060506231352,aum.20060507003931,aum.20060511001853,aum.20060521180804,aum.20060506224238,aum.20060514224855,aum.20060514224919,aum.20060514225725,aum.20060514223936,aum.20060514223822,aum.20060514223845,aum.20060514224020,aum.20060514124642,aum.20060514191601,aum.20060511205201,aum.20060506232639,aum.20060506232639.1,aum.20060511222538,aum.20060512101715,aum.20060511205201.1,aum.20060511205201.2,aum.20060506223545,aum.20060506224238.1,aum.20060506231352.2,aum.20060506220856,aum.20060506222005,aum.20060507124316,aum.20060511103841,aum.20060511103841.1,aum.20060511103952,aum.20060511103952.1,aum.20060604204143,aum.20060514134235,aum.20060512181209,aum.20060514162944,aum.20060514124934,aum.20060512102840,aum.20060514164052,aum.20060509184020.1,aum.20060509184020.2,aum.20060509224119,aum.20060509224221,aum.20060603170554,aum.20060603231840,aum.20060603231840.1,aum.20060603231840.2"><vh>@nosent
 node.py</vh>
 <v t="aum.20060506215707.1"><vh>imports</vh></v>
 <v t="aum.20060506220237"><vh>exceptions</vh></v>
 <v t="aum.20060506215707.2"><vh>globals</vh></v>
@@ -74,6 +74,7 @@
 <v t="aum.20060511103841.1"><vh>__init__</vh></v>
 <v t="aum.20060511103952"><vh>isComplete</vh></v>
 <v t="aum.20060511103952.1"><vh>wait</vh></v>
+<v t="aum.20060604204143"><vh>waitTillReqSent</vh></v>
 <v t="aum.20060514134235"><vh>getResult</vh></v>
 <v t="aum.20060512181209"><vh>callback</vh></v>
 <v t="aum.20060514162944"><vh>cancel</vh></v>
@@ -369,7 +370,7 @@
 <v t="aum.20060529163723.1"><vh>globals</vh></v>
 <v t="aum.20060603114446" a="E"><vh>class FreediskMgr</vh>
 <v t="aum.20060604194409"><vh>__init__</vh></v>
-<v t="aum.20060604194834"><vh>execute</vh></v>
+<v t="aum.20060604194834"><vh>run</vh></v>
 <v t="aum.20060603114247"><vh>cmd_init</vh></v>
 <v t="aum.20060530143459.3"><vh>cmd_start</vh></v>
 <v t="aum.20060530143459.4"><vh>cmd_stop</vh></v>
@@ -420,7 +421,7 @@
 <v t="aum.20060529163723.1"><vh>globals</vh></v>
 <v t="aum.20060603114446" a="E"><vh>class FreediskMgr</vh>
 <v t="aum.20060604194409"><vh>__init__</vh></v>
-<v t="aum.20060604194834"><vh>execute</vh></v>
+<v t="aum.20060604194834"><vh>run</vh></v>
 <v t="aum.20060603114247"><vh>cmd_init</vh></v>
 <v t="aum.20060530143459.3"><vh>cmd_start</vh></v>
 <v t="aum.20060530143459.4"><vh>cmd_stop</vh></v>
@@ -6893,6 +6894,9 @@
     self.lock.acquire()
     self.result = None

+    self.reqSentLock = threading.Lock()
+    self.reqSentLock.acquire()
+
 </t>
 <t tx="aum.20060511103952">def isComplete(self):
     """
@@ -7442,6 +7446,8 @@
     # now can send, since we're the only one who will
     self._txMsg(cmd, **kw)

+    job.reqSentLock.release()
+
 </t>
 <t tx="aum.20060511222538">def _msgIncoming(self):
     """
@@ -9181,7 +9187,10 @@
         sys.stderr.write("%s: Failed to insert key %s\n" % (progname, 
repr(uri)))
         sys.exit(1)

-    if not nowait:
+    if nowait:
+        # got back a job ticket, wait till it has been sent
+        uri.waitTillReqSent()
+    else:
         # successful, return the uri
         sys.stdout.write(uri)
         sys.stdout.flush()
@@ -11863,14 +11872,17 @@
 </t>
 <t tx="aum.20060530143459.3">def cmd_start(self, *args):

+    conf = self.conf
+    kw = self.kw
+
     print "starting freedisk service..."
     fs = freenetfs.FreenetFS(
             conf.mountpoint,
             fcpHost=conf.fcpHost,
             fcpPort=conf.fcpPort,
             verbosity=conf.fcpVerbosity,
-            debug=debug,
-            multithreaded=multithreaded,
+            debug=kw['debug'],
+            multithreaded=kw['multithreaded'],
             )

     # spawn a process to run it
@@ -11913,8 +11925,8 @@
             file(pubKeyPath, "w").write(disk.uri)
             file(privKeyPath, "w").write(disk.privUri)
             file(passwdPath, "w").write(disk.passwd)
-            
-    </t>
+
+</t>
 <t tx="aum.20060530143459.4">def cmd_stop(self, *args):
     """
     Unmount the freenetfs
@@ -12034,12 +12046,19 @@
     f.close()

 </t>
-<t tx="aum.20060530143459.9">print "commit: %s: launching.." % diskname
+<t tx="aum.20060530143459.9">def cmd_commit(self, *args):
+    """
+    commits a freedisk *to* freenet
+    """
+    cmdPath = self.cmdPath
+    diskname = self.diskname

-f = file(cmdPath, "w")
-f.write("commit")
-f.flush()
-f.close()
+    print "commit: %s: launching.." % diskname
+    
+    f = file(cmdPath, "w")
+    f.write("commit")
+    f.flush()
+    f.close()

 </t>
 <t tx="aum.20060530151453">def updateDisk(self, name):
@@ -12743,17 +12762,23 @@
     return self.root._getChild("disk")

 </t>
-<t tx="aum.20060603164555">disks = conf.getDisks()
+<t tx="aum.20060603164555">def cmd_list(self, *args):
+    """
+    Produces a list of mounted freedisks
+    """
+    conf = self.conf

-if disks:
-    print "Currently mounted freedisks:"
-    for d in disks:
-        print "  %s:" % d.name
-        print "    uri=%s" % d.uri
-        print "    passwd=%s" % d.passwd
-else:
-    print "No freedisks mounted"
-
+    disks = conf.getDisks()
+    
+    if disks:
+        print "Currently mounted freedisks:"
+        for d in disks:
+            print "  %s:" % d.name
+            print "    uri=%s" % d.uri
+            print "    passwd=%s" % d.passwd
+    else:
+        print "No freedisks mounted"
+    
 </t>
 <t tx="aum.20060603170554">def uriIsPrivate(uri):
     """
@@ -12888,7 +12913,7 @@
     self.cmd_unmoutn = self.cmd_umount = self.cmd_stop

 </t>
-<t tx="aum.20060604194834">def execute(self):
+<t tx="aum.20060604194834">def run(self):
     """
     Executes the given command
     """
@@ -12905,5 +12930,12 @@
 mgr.run()

 </t>
+<t tx="aum.20060604204143">def waitTillReqSent(self):
+    """
+    Waits till the request has been sent to node
+    """
+    self.reqSentLock.acquire()
+
+</t>
 </tnodes>
 </leo_file>

Modified: trunk/apps/pyFreenet/fcp/node.py
===================================================================
--- trunk/apps/pyFreenet/fcp/node.py    2006-06-04 08:33:39 UTC (rev 9045)
+++ trunk/apps/pyFreenet/fcp/node.py    2006-06-04 08:42:59 UTC (rev 9046)
@@ -1070,7 +1070,9 @@
         # now can send, since we're the only one who will
         self._txMsg(cmd, **kw)

+        job.reqSentLock.release()

+    
     # low level noce comms methods

     def _hello(self):
@@ -1294,6 +1296,9 @@
         self.lock.acquire()
         self.result = None

+        self.reqSentLock = threading.Lock()
+        self.reqSentLock.acquire()
+    
     def isComplete(self):
         """
         Returns True if the job has been completed
@@ -1307,6 +1312,12 @@
         self.lock.acquire()
         self.lock.release()
         return self.getResult()
+    def waitTillReqSent(self):
+        """
+        Waits till the request has been sent to node
+        """
+        self.reqSentLock.acquire()
+    
     def getResult(self):
         """
         Returns result of job, or None if job still not complete

Modified: trunk/apps/pyFreenet/fcpput
===================================================================
--- trunk/apps/pyFreenet/fcpput 2006-06-04 08:33:39 UTC (rev 9045)
+++ trunk/apps/pyFreenet/fcpput 2006-06-04 08:42:59 UTC (rev 9046)
@@ -190,7 +190,10 @@
         sys.stderr.write("%s: Failed to insert key %s\n" % (progname, 
repr(uri)))
         sys.exit(1)

-    if not nowait:
+    if nowait:
+        # got back a job ticket, wait till it has been sent
+        uri.waitTillReqSent()
+    else:
         # successful, return the uri
         sys.stdout.write(uri)
         sys.stdout.flush()

Modified: trunk/apps/pyFreenet/fcpput.py
===================================================================
--- trunk/apps/pyFreenet/fcpput.py      2006-06-04 08:33:39 UTC (rev 9045)
+++ trunk/apps/pyFreenet/fcpput.py      2006-06-04 08:42:59 UTC (rev 9046)
@@ -190,7 +190,10 @@
         sys.stderr.write("%s: Failed to insert key %s\n" % (progname, 
repr(uri)))
         sys.exit(1)

-    if not nowait:
+    if nowait:
+        # got back a job ticket, wait till it has been sent
+        uri.waitTillReqSent()
+    else:
         # successful, return the uri
         sys.stdout.write(uri)
         sys.stdout.flush()

Modified: trunk/apps/pyFreenet/freedisk.py
===================================================================
--- trunk/apps/pyFreenet/freedisk.py    2006-06-04 08:33:39 UTC (rev 9045)
+++ trunk/apps/pyFreenet/freedisk.py    2006-06-04 08:42:59 UTC (rev 9046)
@@ -101,8 +101,8 @@
         self.cmd_unmoutn = self.cmd_umount = self.cmd_stop

     #@-node:__init__
-    #@+node:execute
-    def execute(self):
+    #@+node:run
+    def run(self):
         """
         Executes the given command
         """
@@ -113,7 +113,7 @@

         return method(*self.args[1:])

-    #@-node:execute
+    #@-node:run
     #@+node:cmd_init
     def cmd_init(self, *args):

@@ -173,14 +173,17 @@
     #@+node:cmd_start
     def cmd_start(self, *args):

+        conf = self.conf
+        kw = self.kw
+    
         print "starting freedisk service..."
         fs = freenetfs.FreenetFS(
                 conf.mountpoint,
                 fcpHost=conf.fcpHost,
                 fcpPort=conf.fcpPort,
                 verbosity=conf.fcpVerbosity,
-                debug=debug,
-                multithreaded=multithreaded,
+                debug=kw['debug'],
+                multithreaded=kw['multithreaded'],
                 )

         # spawn a process to run it
@@ -223,9 +226,7 @@
                 file(pubKeyPath, "w").write(disk.uri)
                 file(privKeyPath, "w").write(disk.privUri)
                 file(passwdPath, "w").write(disk.passwd)
-                
-        
-    #@nonl
+    
     #@-node:cmd_start
     #@+node:cmd_stop
     def cmd_stop(self, *args):
@@ -356,26 +357,39 @@

     #@-node:cmd_update
     #@+node:cmd_commit
-    print "commit: %s: launching.." % diskname
+    def cmd_commit(self, *args):
+        """
+        commits a freedisk *to* freenet
+        """
+        cmdPath = self.cmdPath
+        diskname = self.diskname

-    f = file(cmdPath, "w")
-    f.write("commit")
-    f.flush()
-    f.close()
+        print "commit: %s: launching.." % diskname
+        
+        f = file(cmdPath, "w")
+        f.write("commit")
+        f.flush()
+        f.close()

     #@-node:cmd_commit
     #@+node:cmd_list
-    disks = conf.getDisks()
+    def cmd_list(self, *args):
+        """
+        Produces a list of mounted freedisks
+        """
+        conf = self.conf

-    if disks:
-        print "Currently mounted freedisks:"
-        for d in disks:
-            print "  %s:" % d.name
-            print "    uri=%s" % d.uri
-            print "    passwd=%s" % d.passwd
-    else:
-        print "No freedisks mounted"
-    
+        disks = conf.getDisks()
+        
+        if disks:
+            print "Currently mounted freedisks:"
+            for d in disks:
+                print "  %s:" % d.name
+                print "    uri=%s" % d.uri
+                print "    passwd=%s" % d.passwd
+        else:
+            print "No freedisks mounted"
+        
     #@-node:cmd_list
     #@+node:cmd_cmd
     def cmd_cmd(self, *args):


Reply via email to