Author: aum
Date: 2006-05-11 01:07:59 +0000 (Thu, 11 May 2006)
New Revision: 8651

Modified:
   trunk/apps/pyFreenet/code.leo
   trunk/apps/pyFreenet/fcp.py
   trunk/apps/pyFreenet/sitemgr.py
Log:
Added help message to sitemgr.py
Remove those (annoying to some) leo markups


Modified: trunk/apps/pyFreenet/code.leo
===================================================================
--- trunk/apps/pyFreenet/code.leo       2006-05-11 00:56:32 UTC (rev 8650)
+++ trunk/apps/pyFreenet/code.leo       2006-05-11 01:07:59 UTC (rev 8651)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <leo_file>
 <leo_header file_format="2" tnodes="0" max_tnode_index="6" clone_windows="0"/>
-<globals body_outline_ratio="0.208333333333">
+<globals body_outline_ratio="0.290740740741">
        <global_window_position top="21" left="104" height="668" width="1080"/>
        <global_log_window_position top="0" left="0" height="0" width="0"/>
 </globals>
@@ -132,7 +132,7 @@
 <v t="aum.20060509223528.119"><vh>exceptions</vh></v>
 </v>
 <v t="aum.20060511003500" tnodeList="aum.20060511003500"><vh>@file 
test.py</vh></v>
-<v t="aum.20060511101147" a="E" 
tnodeList="aum.20060511101147,aum.20060511113333,aum.20060511113333.1,aum.20060511114439,aum.20060511114439.1,aum.20060511114439.2,aum.20060511120059,aum.20060511114604,aum.20060511114604.1,aum.20060511113333.3,aum.20060511120024"><vh>@file
 sitemgr.py</vh>
+<v t="aum.20060511101147" a="E" 
tnodeList="aum.20060511101147,aum.20060511113333,aum.20060511113333.1,aum.20060511114439,aum.20060511114439.1,aum.20060511114439.2,aum.20060511120059,aum.20060511114604,aum.20060511114604.1,aum.20060511113333.3,aum.20060511130507,aum.20060511120024"><vh>@nosent
 sitemgr.py</vh>
 <v t="aum.20060511113333"><vh>imports</vh></v>
 <v t="aum.20060511113333.1"><vh>config</vh></v>
 <v t="aum.20060511114439" a="E"><vh>class SiteMgr</vh>
@@ -141,11 +141,12 @@
 <v t="aum.20060511120059"><vh>createNode</vh></v>
 <v t="aum.20060511114604"><vh>loadConfig</vh></v>
 <v t="aum.20060511114604.1"><vh>saveConfig</vh></v>
-<v t="aum.20060511113333.3" a="V"><vh>update</vh></v>
+<v t="aum.20060511113333.3"><vh>update</vh></v>
 </v>
+<v t="aum.20060511130507" a="V"><vh>help</vh></v>
 <v t="aum.20060511120024"><vh>mainline</vh></v>
 </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.20060506224238,aum.20060506224238.1,aum.20060506231352,aum.20060507003931,aum.20060511001853,aum.20060506231352.1,aum.20060506232639,aum.20060506232639.1,aum.20060506223545,aum.20060506231352.2,aum.20060506220856,aum.20060506222005,aum.20060507124316,aum.20060511103841,aum.20060511103841.1,aum.20060511103952,aum.20060511103952.1,aum.20060509184020,aum.20060507155016,aum.20060507162314,aum.20060507162543,aum.20060507162314.1,aum.20060509194923,aum.20060507162314.2,aum.20060507162314.3,aum.20060507162543.1,aum.20060507154638,aum.20060507163143,aum.20060509184020.1,aum.20060509184020.2,aum.20060509224119,aum.20060509224221,aum.20060507195029,aum.20060507195029.1,aum.20060506224545"><vh>@file
 fcp.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.20060506224238,aum.20060506224238.1,aum.20060506231352,aum.20060507003931,aum.20060511001853,aum.20060506231352.1,aum.20060506232639,aum.20060506232639.1,aum.20060506223545,aum.20060506231352.2,aum.20060506220856,aum.20060506222005,aum.20060507124316,aum.20060511103841,aum.20060511103841.1,aum.20060511103952,aum.20060511103952.1,aum.20060509184020,aum.20060507155016,aum.20060507162314,aum.20060507162543,aum.20060507162314.1,aum.20060509194923,aum.20060507162314.2,aum.20060507162314.3,aum.20060507162543.1,aum.20060507154638,aum.20060507163143,aum.20060509184020.1,aum.20060509184020.2,aum.20060509224119,aum.20060509224221,aum.20060507195029,aum.20060507195029.1,aum.20060506224545"><vh>@nosent
 fcp.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>
@@ -6363,6 +6364,8 @@

     if not os.path.isfile(configFile):
         self.createConfig()
+        print "New config file created at %s"
+        print "Please edit that file and add your freesites"

     self.loadConfig()

@@ -6441,6 +6444,9 @@
 </t>
 <t tx="aum.20060511120024">if __name__ == '__main__':

+    if '-h' in sys.argv:
+        help()
+
     if '-v' in sys.argv:
         verbosity = fcp.DETAIL

@@ -6464,5 +6470,24 @@
     self.node = fcp.FCPNodeConnection(**kw)

 </t>
+<t tx="aum.20060511130507">def help():
+    print "%s: A console-based, cron-able freesite inserter" % sys.argv[0]
+    print "This utility inserts/updates freesites, and is"
+    print "driven by a simple config file."
+    print
+    print "The first time you run this utility, a config file"
+    print "will be created for you in your home directory,"
+    print "You will be told where this file is (~/.freesites on *nix"
+    print "or ~/freesites.ini on doze)"
+    print "then you can edit this file and add details of"
+    print "your freesites, and run it again."
+    print
+    print "Note - freesites are only updated if they have"
+    print "changed since the last update, because a hash"
+    print "of each site gets stored in the config"
+
+    sys.exit(0)
+
+</t>
 </tnodes>
 </leo_file>

Modified: trunk/apps/pyFreenet/fcp.py
===================================================================
--- trunk/apps/pyFreenet/fcp.py 2006-05-11 00:56:32 UTC (rev 8650)
+++ trunk/apps/pyFreenet/fcp.py 2006-05-11 01:07:59 UTC (rev 8651)
@@ -1,7 +1,4 @@
 #!/usr/bin/env python
-#@+leo-ver=4
-#@+node:@file fcp.py
-#@@first
 """
 An implementation of a freenet client library for
 FCP v2
@@ -21,14 +18,10 @@

 """

-#@+others
-#@+node:imports
 import sys, os, socket, time, thread, threading, mimetypes, sha

 from SimpleXMLRPCServer import SimpleXMLRPCServer

-#@-node:imports
-#@+node:exceptions
 class ConnectionRefused(Exception):
     """
     cannot connect to given host/port
@@ -60,8 +53,6 @@
 class FCPProtocolError(FCPException):
     pass

-#@-node:exceptions
-#@+node:globals
 defaultFCPHost = "127.0.0.1"
 defaultFCPPort = 9481

@@ -84,15 +75,11 @@
 DETAIL = 5
 DEBUG = 6

-#@-node:globals
-#@+node:class FCPNodeConnection
 class FCPNodeConnection:
     """
     Low-level transport for connections to
     FCP port
     """
-    #@    @+others
-    #@+node:__init__
     def __init__(self, **kw):
         """
         Create a connection object
@@ -136,8 +123,6 @@
         # launch receiver thread
         #thread.start_new_thread(self.rxThread, ())

-    #@-node:__init__
-    #@+node:__del__
     def __del__(self):
         """
         object is getting cleaned up, so disconnect
@@ -149,12 +134,8 @@
         if self.logfile not in [sys.stdout, sys.stderr]:
             self.logfile.close()

-    #@-node:__del__
-    #@+node:High Level Methods
     # high level client methods

-    #@+others
-    #@+node:hello
     def hello(self):

         self._sendMessage("ClientHello", 
@@ -164,8 +145,6 @@
         resp = self._receiveMessage()
         return resp

-    #@-node:hello
-    #@+node:get
     def get(self, uri, **kw):
         """
         Does a direct get of a key
@@ -262,8 +241,6 @@
         else:
             raise FCPException(resp)

-    #@-node:get
-    #@+node:put
     def put(self, uri="CHK@", **kw):
         """
         Inserts a key
@@ -415,8 +392,6 @@
         else:
             raise FCPException(resp2)

-    #@-node:put
-    #@+node:putdir
     def putdir(self, uri, **kw):
         """
         Inserts a freesite
@@ -515,8 +490,6 @@
         else:
             raise FCPException(resp2)

-    #@-node:putdir
-    #@+node:genkey
     def genkey(self, id=None):
         """
         Generates and returns an SSK keypair
@@ -535,17 +508,11 @@

         return resp['RequestURI'], resp['InsertURI']

-    #@-node:genkey
-    #@-others



-    #@-node:High Level Methods
-    #@+node:Receiver Thread
     # methods for receiver thread

-    #@+others
-    #@+node:_rxThread
     def _rxThread(self):
         """
         Receives all incoming messages
@@ -559,20 +526,12 @@
                 self.socketLock.release()
                 continue

-    #@-node:_rxThread
-    #@-others

-    #@-node:Receiver Thread
-    #@+node:Low Level Methods
     # low level noce comms methods

-    #@+others
-    #@+node:_getUniqueId
     def _getUniqueId(self):
         return "id" + str(int(time.time() * 1000000))

-    #@-node:_getUniqueId
-    #@+node:_sendMessage
     def _sendMessage(self, msgType, sendEndMessage=True, **kw):
         """
         low level message send
@@ -614,8 +573,6 @@

         self.socket.send(raw)

-    #@-node:_sendMessage
-    #@+node:_receiveMessage
     def _receiveMessage(self):
         """
         Receives and returns a message as a dict
@@ -697,8 +654,6 @@
         # all done
         return items

-    #@-node:_receiveMessage
-    #@+node:_log
     def _log(self, level, msg):
         """
         Logs a message. If level > verbosity, don't output it
@@ -710,10 +665,6 @@
         self.logfile.write(msg)
         self.logfile.flush()

-    #@-node:_log
-    #@-others
-    #@-node:Low Level Methods
-    #@+node:class JobTicket
     class JobTicket:
         """
         A JobTicket is an object returned to clients making
@@ -725,8 +676,6 @@
             - poll the job for completion status
             - receive a callback upon completion
         """
-        #@    @+others
-        #@+node:__init__
         def __init__(self, id):
             """
             You should never instantiate a JobTicket object yourself
@@ -734,56 +683,36 @@
             self.id = id
             self.queue = Queue.Queue()

-        #@-node:__init__
-        #@+node:isDone
         def isComplete(self):
             """
             Returns True if the job has been completed
             """

-        #@-node:isDone
-        #@+node:wait
         def wait(self, timeout=None):
             """
             Waits forever (or for a given timeout) for a job to complete
             """
-        #@-node:wait
-        #@-others

-    #@-node:class JobTicket
-    #@-others

-#@-node:class FCPNodeConnection
-#@+node:XML-RPC Server
-#@+others
-#@+node:class FreenetXMLRPCRequest
 class FreenetXMLRPCRequest:
     """
     Simple class which exposes basic primitives
     for freenet xmlrpc server
     """
-    #@    @+others
-    #@+node:__init__
     def __init__(self, **kw):

         self.kw = kw

-    #@-node:__init__
-    #@+node:_getNode
     def _getNode(self):

         node = FCPNodeConnection(**self.kw)
         node.hello()
         return node

-    #@-node:_getNode
-    #@+node:_hello
     def _hello(self):

         self.node.hello()

-    #@-node:_hello
-    #@+node:hello
     def hello(self):
         """
         pings the FCP interface. just creates the connection,
@@ -794,8 +723,6 @@

         node = self._getNode()

-    #@-node:hello
-    #@+node:get
     def get(self, uri, options=None):
         """
         Performs a fetch of a key
@@ -812,8 +739,6 @@

         return node.get(uri, **options)

-    #@-node:get
-    #@+node:put
     def put(self, uri, options=None):
         """
         Inserts data to node
@@ -830,19 +755,13 @@

         return node.put(uri, data=data, **options)

-    #@-node:put
-    #@+node:genkey
     def genkey(self):

         node = self._getNode()

         return self.node.genkey()

-    #@-node:genkey
-    #@-others

-#@-node:class FreenetXMLRPCRequest
-#@+node:runServer
 def runServer(**kw):
     """
     Runs a basic XML-RPC server for FCP access
@@ -859,19 +778,11 @@
     server.register_introspection_methods()
     server.serve_forever()

-#@-node:runServer
-#@+node:testServer
 def testServer():

     runServer(host="", fcpHost="10.0.0.1", verbosity=DETAIL)

-#@-node:testServer
-#@-others

-#@-node:XML-RPC Server
-#@+node:util funcs
-#@+others
-#@+node:toBool
 def toBool(arg):
     try:
         arg = int(arg)
@@ -891,8 +802,6 @@
     else:
         return False

-#@-node:toBool
-#@+node:readdir
 def readdir(dirpath, prefix='', gethashes=False):
     """
     Reads a directory, returning a sequence of file dicts.
@@ -941,8 +850,6 @@

     return entries

-#@-node:readdir
-#@+node:guessMimetype
 def guessMimetype(filename):
     """
     Returns a guess of a mimetype based on a filename's extension
@@ -951,11 +858,7 @@
     if m == None:
         m = "text/plain"
     return m
-#@-node:guessMimetype
-#@-others

-#@-node:util funcs
-#@+node:usage
 def usage(msg="", ret=1):

     if msg:
@@ -988,8 +891,6 @@

     sys.exit(ret)

-#@-node:usage
-#@+node:main
 def main():
     """
     When this script is executed, it runs the XML-RPC server
@@ -1050,14 +951,8 @@



-#@-node:main
-#@+node:mainline
 if __name__ == '__main__':

     main()

-#@-node:mainline
-#@-others

-#@-node:@file fcp.py
-#@-leo

Modified: trunk/apps/pyFreenet/sitemgr.py
===================================================================
--- trunk/apps/pyFreenet/sitemgr.py     2006-05-11 00:56:32 UTC (rev 8650)
+++ trunk/apps/pyFreenet/sitemgr.py     2006-05-11 01:07:59 UTC (rev 8651)
@@ -1,32 +1,21 @@
 #! /usr/bin/env python
-#@+leo-ver=4
-#@+node:@file sitemgr.py
-#@@first
 """
 A small freesite insertion/management utility
 """
-#@+others
-#@+node:imports
 import fcp, sys, os, sha

 from ConfigParser import SafeConfigParser

-#@-node:imports
-#@+node:config
 fcpHost = "thoth"
 fcpPort = None
 #verbosity = fcp.DETAIL
 verbosity = None
 logfile = None

-#@-node:config
-#@+node:class SiteMgr
 class SiteMgr:
     """
     Manages insertion and updating of freesites
     """
-    #@    @+others
-    #@+node:__init__
     def __init__(self, configFile=None, **kw):
         """
         Creates a site manager object.
@@ -52,11 +41,11 @@

         if not os.path.isfile(configFile):
             self.createConfig()
+            print "New config file created at %s"
+            print "Please edit that file and add your freesites"

         self.loadConfig()

-    #@-node:__init__
-    #@+node:createConfig
     def createConfig(self):
         """
         Creates a whole new config
@@ -79,8 +68,6 @@
             "",
             ]))

-    #@-node:createConfig
-    #@+node:createNode
     def createNode(self, **kw):

         kw = {}
@@ -96,8 +83,6 @@

         self.node = fcp.FCPNodeConnection(**kw)

-    #@-node:createNode
-    #@+node:loadConfig
     def loadConfig(self):
         """
         Loads the sites config file into self.config as a SafeConfigParser
@@ -133,8 +118,6 @@
         if needToSave:
             self.saveConfig()

-    #@-node:loadConfig
-    #@+node:saveConfig
     def saveConfig(self):
         """
         Saves the amended config file to disk
@@ -147,8 +130,6 @@

         f.close()

-    #@-node:saveConfig
-    #@+node:update
     def update(self):
         """
         Insert/update all registered freesites
@@ -180,20 +161,33 @@
         if noSites:
             print "No sites needed updating"

-    #@-node:update
-    #@-others

-#@-node:class SiteMgr
-#@+node:mainline
+def help():
+    print "%s: A console-based, cron-able freesite inserter" % sys.argv[0]
+    print "This utility inserts/updates freesites, and is"
+    print "driven by a simple config file."
+    print
+    print "The first time you run this utility, a config file"
+    print "will be created for you in your home directory,"
+    print "You will be told where this file is (~/.freesites on *nix"
+    print "or ~/freesites.ini on doze)"
+    print "then you can edit this file and add details of"
+    print "your freesites, and run it again."
+    print
+    print "Note - freesites are only updated if they have"
+    print "changed since the last update, because a hash"
+    print "of each site gets stored in the config"
+
+    sys.exit(0)
+
 if __name__ == '__main__':

+    if '-h' in sys.argv:
+        help()
+
     if '-v' in sys.argv:
         verbosity = fcp.DETAIL

     s = SiteMgr()
     s.update()

-#@-node:mainline
-#@-others
-#@-node:@file sitemgr.py
-#@-leo


Reply via email to