From zothar at freenetproject.org Mon Apr 16 01:17:21 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Mon, 16 Apr 2007 01:17:21 +0000 (UTC) Subject: [Pyfreenet] r12760 - trunk/apps/pyFreenet Message-ID: <20070416011721.8424C479805@emu.freenetproject.org> Author: zothar Date: 2007-04-16 01:17:21 +0000 (Mon, 16 Apr 2007) New Revision: 12760 Added: trunk/apps/pyFreenet/fcp_to_mrtg_bridge.py trunk/apps/pyFreenet/fcp_to_rrdtool_bridge.py Log: pyFreenet: Adding FCP-to-MRTG bridge and FCP-to-rrdtool bridge. Note that since MRTG doesn't directly graph non-integer numbers such as the node's location, you may prefer to use the bridge to rrdtool. Added: trunk/apps/pyFreenet/fcp_to_mrtg_bridge.py =================================================================== --- trunk/apps/pyFreenet/fcp_to_mrtg_bridge.py (rev 0) +++ trunk/apps/pyFreenet/fcp_to_mrtg_bridge.py 2007-04-16 01:17:21 UTC (rev 12760) @@ -0,0 +1,113 @@ +#!/usr/bin/env python +""" +Output specified node stats in a format expected by MRTG + +This code was written by Zothar, April 2007, released under the GNU Lesser General +Public License. + +No warranty, yada yada + +Note: MRTG doesn't seem to handle non-integer numbers as anything but truncated (rounded?) integers + +""" + +import fcp; +import sys; + +stat_fields = []; + +host = "127.0.0.1"; +port = 9481; + +list_fields_flag = False; + +def usage(): + print "Usage: %s [[:]] ," % ( sys.argv[ 0 ] ); + print " %s [[:]] --list-fields" % ( sys.argv[ 0 ] ); + print; + print "Example:"; + print " %s averagePingTime,runningThreadCount" % ( sys.argv[ 0 ] ); + +argv = sys.argv; +arg0 = argv[ 0 ]; +argv = argv[ 1: ]; +argc = len( argv ); +if( 0 == argc ): + usage(); + sys.exit( 1 ); +for arg in argv: + if( "--" == arg[ :2 ] ): + option = arg[ 2: ]; + if( "list-fields" == option ): + list_fields_flag = True; + else: + print "Unknown option: %s" % ( arg ); + print; + usage(); + sys.exit( 1 ); + i = arg.find( ":" ); + if( -1 != i ): + argfields = arg.split( ":" ); + if( 2 != len( argfields )): + usage(); + sys.exit( 1 ); + host = argfields[ 0 ]; + port = int( argfields[ 1 ] ); + continue; + i = arg.find( "," ); + if( -1 != i ): + argfields = arg.split( "," ); + for argfield in argfields: + if( 0 == len( argfield )): + continue; + stat_fields.append( argfield ); + continue; + i = arg.find( "." ); + if( -1 != i ): + host = arg; + continue; + stat_fields.append( arg ); + +if( 2 != len( stat_fields ) and not list_fields_flag ): + print "Must specify two stat_fields when not using --list-fields"; + print; + usage(); + sys.exit( 1 ); + +f = fcp.FCPNode( host = host, port = port ); +entry = f.refstats( WithVolatile = True ); +f.shutdown(); +if( list_fields_flag ): + keys = entry.keys(); + keys.sort(); + print "Volatile fields:"; + for key in keys: + if( not key.startswith( "volatile." )): + continue; + print key[ 9: ]; + print; + print "non-volatile fields:" + for key in keys: + if( key.startswith( "volatile." )): + continue; + print key; +else: + for stat_field in stat_fields: + try: + datum_string = entry[ "volatile." + stat_field ]; + except KeyError, msg: + try: + datum_string = entry[ stat_field ]; + except KeyError, msg: + print "0"; + continue; + datum = float( datum_string ); + try: + test_datum = int( datum ); + except ValueError, msg: + test_datum = None; + if( test_datum == datum ): + datum = test_datum; + print "%s" % ( datum ); + print "%s" % ( entry[ "volatile.uptimeSeconds" ] ); + print "%s" % ( entry[ "myName" ] ); Property changes on: trunk/apps/pyFreenet/fcp_to_mrtg_bridge.py ___________________________________________________________________ Name: svn:executable + * Added: trunk/apps/pyFreenet/fcp_to_rrdtool_bridge.py =================================================================== --- trunk/apps/pyFreenet/fcp_to_rrdtool_bridge.py (rev 0) +++ trunk/apps/pyFreenet/fcp_to_rrdtool_bridge.py 2007-04-16 01:17:21 UTC (rev 12760) @@ -0,0 +1,114 @@ +#!/usr/bin/env python +""" +Output specified node stats in a format expected by rrdtool + +This code was written by Zothar, April 2007, released under the GNU Lesser General +Public License. + +No warranty, yada yada + +Example usage: rrdtool update freenet.rrd `/usr/local/pyFreenet/fcp_to_rrdtool_bridge.py averagePingTime,RunningThreadCount,location,locationChangePerSession` +""" + +import fcp; +import sys; + +stat_fields = []; + +host = "127.0.0.1"; +port = 9481; + +list_fields_flag = False; + +def usage(): + print "Usage: %s [[:]] [[, ...]]" % ( sys.argv[ 0 ] ); + print " %s [[:]] --list-fields" % ( sys.argv[ 0 ] ); + print; + print "Example:"; + print " %s averagePingTime,runningThreadCount,location,locationChangePerSession" % ( sys.argv[ 0 ] ); + +argv = sys.argv; +arg0 = argv[ 0 ]; +argv = argv[ 1: ]; +argc = len( argv ); +if( 0 == argc ): + usage(); + sys.exit( 1 ); +for arg in argv: + if( "--" == arg[ :2 ] ): + option = arg[ 2: ]; + if( "list-fields" == option ): + list_fields_flag = True; + else: + print "Unknown option: %s" % ( arg ); + print; + usage(); + sys.exit( 1 ); + i = arg.find( ":" ); + if( -1 != i ): + argfields = arg.split( ":" ); + if( 2 != len( argfields )): + usage(); + sys.exit( 1 ); + host = argfields[ 0 ]; + port = int( argfields[ 1 ] ); + continue; + i = arg.find( "," ); + if( -1 != i ): + argfields = arg.split( "," ); + for argfield in argfields: + if( 0 == len( argfield )): + continue; + stat_fields.append( argfield ); + continue; + i = arg.find( "." ); + if( -1 != i ): + host = arg; + continue; + stat_fields.append( arg ); + +if( 0 == len( stat_fields ) and not list_fields_flag ): + print "Must specify stat_fields when not using --list-fields"; + print; + usage(); + sys.exit( 1 ); + +f = fcp.FCPNode( host = host, port = port ); +entry = f.refstats( WithVolatile = True ); +f.shutdown(); +if( list_fields_flag ): + keys = entry.keys(); + keys.sort(); + print "Volatile fields:"; + for key in keys: + if( not key.startswith( "volatile." )): + continue; + print key[ 9: ]; + print; + print "non-volatile fields:" + for key in keys: + if( key.startswith( "volatile." )): + continue; + print key; +else: + field_count = 0; + sys.stdout.write( "N" ); + for stat_field in stat_fields: + try: + datum_string = entry[ "volatile." + stat_field ]; + except KeyError, msg: + try: + datum_string = entry[ stat_field ]; + except KeyError, msg: + datum_string = "0"; + field_count += 1; + datum = float( datum_string ); + try: + test_datum = int( datum ); + except ValueError, msg: + test_datum = None; + if( test_datum == datum ): + datum = test_datum; + sys.stdout.write( ":%s" % ( datum )); + sys.stdout.write( "\n" ); + sys.stdout.flush(); Property changes on: trunk/apps/pyFreenet/fcp_to_rrdtool_bridge.py ___________________________________________________________________ Name: svn:executable + * From nextgens at freenetproject.org Sat Apr 21 11:22:13 2007 From: nextgens at freenetproject.org (nextgens at freenetproject.org) Date: Sat, 21 Apr 2007 11:22:13 +0000 (UTC) Subject: [Pyfreenet] r12836 - in trunk/apps/pyFreenet: . fcp Message-ID: <20070421112213.F11E947980A@emu.freenetproject.org> Author: nextgens Date: 2007-04-21 11:22:13 +0000 (Sat, 21 Apr 2007) New Revision: 12836 Modified: trunk/apps/pyFreenet/fcp/sitemgr.py trunk/apps/pyFreenet/freesitemgr Log: pyFreenet: implement #1307 ... yes it's a hack; SiteMGR shouldn't have the index/mimetype; it should be fixed at creation time Modified: trunk/apps/pyFreenet/fcp/sitemgr.py =================================================================== --- trunk/apps/pyFreenet/fcp/sitemgr.py 2007-04-21 09:35:50 UTC (rev 12835) +++ trunk/apps/pyFreenet/fcp/sitemgr.py 2007-04-21 11:22:13 UTC (rev 12836) @@ -61,6 +61,9 @@ self.priority = kw.get('priority', defaultPriority) self.chkCalcNode = kw.get('chkCalcNode', None) + + self.index = kw.get('index', 'index.html') + self.mtype = kw.get('mtype', 'text/html') self.load() @@ -199,6 +202,8 @@ verbosity=self.verbosity, Verbosity=self.Verbosity, priority=self.priority, + index=self.index, + mtype=self.mtype, **kw) self.sites.append(site) @@ -411,7 +416,10 @@ self.path = os.path.join(self.basedir, self.name) self.Verbosity = kw.get('Verbosity', 0) self.chkCalcNode = kw.get('chkCalcNode', self.node) - + + self.index = kw.get('index', 'index.html') + self.mtype = kw.get('mtype', 'text/html') + #print "Verbosity=%s" % self.Verbosity self.fileLock = threading.Lock() @@ -421,13 +429,14 @@ self.save() # barf if directory is invalid - #if not (os.path.isdir(self.dir) \ - # and os.path.isfile(os.path.join(self.dir, "index.html"))): - # raise Exception("Site %s, directory %s, no index.html present" % ( - # self.name, self.dir)) if not (os.path.isdir(self.dir)): raise Exception("Site %s, directory %s nonexistent" % ( self.name, self.dir)) +# if not (os.path.isdir(self.dir) \ +# and os.path.isfile(os.path.join(self.dir, self.index)) \ +# and not self.insertingIndex): +# raise Exception("Site %s, directory %s, no %s present" % ( +# self.name, self.dir, self.index)) #@-node:__init__ #@+node:load @@ -582,6 +591,8 @@ writeVars(updateInProgress=self.updateInProgress) writeVars(insertingManifest=self.insertingManifest) writeVars(insertingIndex=self.insertingIndex) + writeVars(index=self.index) + writeVars(mtype=self.mtype) w("\n") writeVars("Detailed site contents", files=self.files) @@ -804,8 +815,8 @@ missing = [] if not jobs.has_key("__manifest"): missing.append('__manifest') - if self.insertingIndex and not jobs.has_key('index.html'): - missing.append('index.html') + if self.insertingIndex and not jobs.has_key(self.index): + missing.append(self.index) for rec in self.files: if rec['state'] == 'waiting' and not jobs.has_key(rec['name']): missing.append(rec['name']) @@ -909,7 +920,7 @@ self.uriPriv = updateEdition(self.uriPriv, edition) self.save() - elif name == 'index.html': + elif name == self.index: if isinstance(result, Exception): self.needToUpdate = True else: @@ -920,7 +931,7 @@ # that file is now done rec['uri'] = result rec['state'] = 'idle' - elif name not in ['__manifest', 'index.html']: + elif name not in ['__manifest', self.index]: self.log(ERROR, "insert:%s: Don't have a record for file %s" % ( self.name, name)) @@ -1065,14 +1076,14 @@ """ generate and insert an index.html if none exists """ - # got an actual index.html file? - indexRec = self.filesDict.get("index.html", None) + # got an actual index file? + indexRec = self.filesDict.get(self.index, None) if indexRec: # dumb hack - calculate uri if missing if not indexRec.get('uri', None): indexRec['uri'] = self.chkCalcNode.genchk( data=file(indexRec['path'], "rb").read(), - mimetype="text/html") + mimetype=self.mtype) # yes, remember its uri for the manifest self.indexUri = indexRec['uri'] @@ -1178,7 +1189,7 @@ "URI=%s" % self.uriPriv, "Persistence=forever", "Global=true", - "DefaultName=index.html", + "DefaultName=%s" % self.index, ] # add each file's entry to the command buffer @@ -1187,7 +1198,7 @@ # start with index.html's uri msgLines.extend([ - "Files.%d.Name=index.html" % n, + "Files.%d.Name=%s" % (n, self.index), "Files.%d.UploadFrom=redirect" % n, "Files.%d.TargetURI=%s" % (n, self.indexUri), ]) @@ -1195,7 +1206,7 @@ # now add the rest of the files, but not index.html for rec in self.files: - if rec['name'] == 'index.html': + if rec['name'] == self.index: continue # don't add if the file failed to insert Modified: trunk/apps/pyFreenet/freesitemgr =================================================================== --- trunk/apps/pyFreenet/freesitemgr 2007-04-21 09:35:50 UTC (rev 12835) +++ trunk/apps/pyFreenet/freesitemgr 2007-04-21 11:22:13 UTC (rev 12836) @@ -123,9 +123,9 @@ if not os.path.isdir(sitedir): print "'%s' is not a directory, try again" % sitedir continue - #elif not os.path.isfile(os.path.join(sitedir, "index.html")): - # print "'%s' has no index.html, try again" % sitedir - # continue + elif not os.path.isfile(os.path.join(sitedir, sitemgr.index)): + print "'%s' has no %s, try again" % (sitedir, sitemgr.index) + continue break while 1: @@ -145,7 +145,7 @@ break uriPub = fixUri(uriPub, sitename) uriPriv = fixUri(uriPriv, sitename) - + # good to go - add the site sitemgr.addSite(name=sitename, dir=sitedir, uriPub=uriPub, uriPriv=uriPriv) @@ -246,6 +246,10 @@ print " - run verbosely, set this twice for even more noise" print " -q, --quiet" print " - run quietly" + print " -i, --index" + print " - index file (default is index.html)" + print " -m, --mime-type" + print " - mime-type of the index file (default is \"text/html\")" print " -l, --logfile=filename" print " - location of logfile (default %s)" % logFile print " -r, --priority" @@ -315,12 +319,12 @@ try: cmdopts, args = getopt.getopt( sys.argv[1:], - "?hvc:l:r:fCV", + "?hvc:l:r:fCVi:m:", ["help", "verbose", "config-dir=", "logfile=", "max-concurrent=", "force", "priority", "cron", "chk-calculation-node=", - "version", + "version", "index", "mime-type", ] ) except getopt.GetoptError: @@ -353,6 +357,12 @@ if o in ("-l", "--logfile"): opts['logfile'] = a + if o in ("-i", "--index"): + opts['index'] = a + + if o in ("-m", "--mime-type"): + opts['mtype'] = a + if o == '--chk-calculation-node': chkNode = getChkCalcNode(a) if not chkNode: From nextgens at freenetproject.org Sat Apr 21 11:34:23 2007 From: nextgens at freenetproject.org (nextgens at freenetproject.org) Date: Sat, 21 Apr 2007 11:34:23 +0000 (UTC) Subject: [Pyfreenet] r12837 - trunk/apps/pyFreenet/fcp Message-ID: <20070421113423.ECE8D479949@emu.freenetproject.org> Author: nextgens Date: 2007-04-21 11:34:23 +0000 (Sat, 21 Apr 2007) New Revision: 12837 Modified: trunk/apps/pyFreenet/fcp/node.py Log: pyFreenet: implement #1309: now the library handles PutFetchable messages Modified: trunk/apps/pyFreenet/fcp/node.py =================================================================== --- trunk/apps/pyFreenet/fcp/node.py 2007-04-21 11:22:13 UTC (rev 12836) +++ trunk/apps/pyFreenet/fcp/node.py 2007-04-21 11:34:23 UTC (rev 12837) @@ -2013,6 +2013,12 @@ job.callback('failed', msg) job._putResult(FCPPutFailed(msg)) return + + if hdr == 'PutFetchable': + uri = msg['URI'] + job.kw['URI'] = uri + job.callback('pending', msg) + return # ----------------------------- # handle progress messages @@ -2028,7 +2034,7 @@ if hdr == 'SimpleProgress': job.callback('pending', msg) return - + # ----------------------------- # handle peer management messages From nextgens at freenetproject.org Sat Apr 21 12:12:06 2007 From: nextgens at freenetproject.org (nextgens at freenetproject.org) Date: Sat, 21 Apr 2007 12:12:06 +0000 (UTC) Subject: [Pyfreenet] r12838 - trunk/apps/pyFreenet/fcp Message-ID: <20070421121206.1C7994791BF@emu.freenetproject.org> Author: nextgens Date: 2007-04-21 12:12:05 +0000 (Sat, 21 Apr 2007) New Revision: 12838 Modified: trunk/apps/pyFreenet/fcp/node.py Log: pyFreenet: implement #1315: now fcplib handles PersistentRequestRemoved properly Modified: trunk/apps/pyFreenet/fcp/node.py =================================================================== --- trunk/apps/pyFreenet/fcp/node.py 2007-04-21 11:34:23 UTC (rev 12837) +++ trunk/apps/pyFreenet/fcp/node.py 2007-04-21 12:12:05 UTC (rev 12838) @@ -1656,9 +1656,6 @@ self._submitCmd(id, "RemovePersistentRequest", Identifier=id, Global=True, async=True, waituntilsent=True) - if self.jobs.has_key(id): - del self.jobs[id] - #@-node:clearGlobalJob #@+node:setVerbosity def setVerbosity(self, verbosity): @@ -2112,6 +2109,11 @@ job.callback('successful', job.msgs) job._putResult(job.msgs) return + + if hdr == 'PersistentRequestRemoved': + if self.jobs.has_key(id): + del self.jobs[id] + return # ----------------------------- # handle NodeData From zothar at freenetproject.org Sun Apr 22 14:49:57 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 22 Apr 2007 14:49:57 +0000 (UTC) Subject: [Pyfreenet] r12865 - trunk/apps/pyFreenet Message-ID: <20070422144957.70544479856@emu.freenetproject.org> Author: zothar Date: 2007-04-22 14:49:57 +0000 (Sun, 22 Apr 2007) New Revision: 12865 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: Tell the user where we're reading our configuration from Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-04-22 14:26:45 UTC (rev 12864) +++ trunk/apps/pyFreenet/refbot.py 2007-04-22 14:49:57 UTC (rev 12865) @@ -544,6 +544,7 @@ opts = {} exec file(self.confpath).read() in opts + log("Read configuration from %s" % self.confpath) return opts #@-node:load From zothar at freenetproject.org Sun Apr 22 15:02:23 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 22 Apr 2007 15:02:23 +0000 (UTC) Subject: [Pyfreenet] r12867 - trunk/apps/pyFreenet Message-ID: <20070422150223.26367479EAC@emu.freenetproject.org> Author: zothar Date: 2007-04-22 15:02:23 +0000 (Sun, 22 Apr 2007) New Revision: 12867 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: Refer to the wiki for installation instead of directly to the SVN tarball. Some were confused by the .tbz extension thinking that it couldn't be used on Windows. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-04-22 14:54:16 UTC (rev 12866) +++ trunk/apps/pyFreenet/refbot.py 2007-04-22 15:02:23 UTC (rev 12867) @@ -816,7 +816,7 @@ bot2bot_string = "(bot2bot)"; self.action( self.channel, - "is a Freenet NodeRef Swap-bot owned by %s (install pyfcp from http://downloads.freenetproject.org/alpha/pyFreenet/pyFreenet-latest.tbz then run refbot.py; run updater.py periodically)(r%s/r%s)%s" % ( self.owner, FreenetNodeRefBot.svnRevision, MiniBot.svnRevision, bot2bot_string ) + "is a Freenet NodeRef Swap-bot owned by %s (install pyfcp as detailed at http://wiki.freenetproject.org/Refbot then run refbot.py; run updater.py periodically)(r%s/r%s)%s" % ( self.owner, FreenetNodeRefBot.svnRevision, MiniBot.svnRevision, bot2bot_string ) ) if(self.spam_interval > 0 and not self.bot2bot_trades_only_enabled): self.after(self.spam_interval, self.spamChannel) @@ -1380,7 +1380,7 @@ self.privmsg( "I am a bot for exchanging freenet noderefs", - "I am part of pyfcp. To run your own copy of me, install pyfcp from http://downloads.freenetproject.org/alpha/pyFreenet/pyFreenet-latest.tbz and then run refbot.py", + "I am part of pyfcp. To run your own copy of me, install pyfcp as detailed at http://wiki.freenetproject.org/Refbot and then run refbot.py", "If you do run your own copy of me, you'll want to run my updater.py script periodically to make sure you have my latest features and bug fixes.", "My version numbers are refbot.py at r%s and minibot.py at r%s" % (FreenetNodeRefBot.svnRevision, MiniBot.svnRevision), "Available commands:", From zothar at freenetproject.org Sun Apr 22 22:05:54 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 22 Apr 2007 22:05:54 +0000 (UTC) Subject: [Pyfreenet] r12880 - trunk/apps/pyFreenet Message-ID: <20070422220554.C72CC479F90@emu.freenetproject.org> Author: zothar Date: 2007-04-22 22:05:54 +0000 (Sun, 22 Apr 2007) New Revision: 12880 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: Sanity check the advertised ref on refbot startup. Shutdown an FCP connection more cleanly before exiting in some places. Promote some prints to log() calls. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-04-22 22:00:39 UTC (rev 12879) +++ trunk/apps/pyFreenet/refbot.py 2007-04-22 22:05:54 UTC (rev 12880) @@ -279,7 +279,8 @@ try: f = fcp.FCPNode( host = self.fcp_host, port = self.fcp_port ) if( f.nodeBuild < self.minimumNodeBuild ): - log("This version of the refbot requires your node be running build %d or higher. Please upgrade your Freenet node and try again." % ( self.minimumNodeBuild )) + log("ERROR: This version of the refbot requires your node be running build %d or higher. Please upgrade your Freenet node and try again." % ( self.minimumNodeBuild )) + f.shutdown() my_exit( 1 ) try: noderef = f.refstats(); @@ -287,15 +288,88 @@ noderef = noderef[ 0 ]; self.nodeIdentity = noderef[ "identity" ]; except Exception, msg: - print "Failed to get the node's identity via FCP. This is an odd error this refbot developer is not sure of a reason for."; + log("ERROR: Failed to get the node's identity via FCP. This is an odd error this refbot developer is not sure of a reason for."); + f.shutdown() my_exit( 1 ) + except Exception, msg: + log("ERROR: Failed to connect to node via FCP (%s:%d). Check your fcp host and port settings on both the node and the bot config." % ( self.fcp_host, self.fcp_port )); f.shutdown() - except Exception, msg: - print "Failed to connect to node via FCP (%s:%d). Check your fcp host and port settings on both the node and the bot config." % ( self.fcp_host, self.fcp_port ); my_exit( 1 ) del noderef[ "header" ]; self.nodeRef = noderef; + while( 'y' != opts['bot2bot_trades_only'] ): + log("Getting advertised ref from URL..."); + try: + openurl = urllib2.urlopen(opts['refurl']) + refbuf = openurl.read(20*1024) # read up to 20 KiB + openurl.close() + refmemfile = StringIO.StringIO(refbuf) + reflines = refmemfile.readlines() + refmemfile.close(); + except Exception, msg: + log("ERROR: Failed to get advertised ref from URL."); + opts['refurl'] = self.prompt("URL of your noderef", opts['refurl']) + continue; + log("Checking syntax of advertised ref..."); + ref_fieldset = {}; + end_found = False + for refline in reflines: + refline = refline.strip(); + if("" == refline): + continue; + if("end" == refline.lower()): + end_found = True + break; + reflinefields = refline.split("=", 1) + if(2 != len(reflinefields)): + continue; + if(not ref_fieldset.has_key(reflinefields[ 0 ])): + ref_fieldset[ reflinefields[ 0 ]] = reflinefields[ 1 ] + ref_has_syntax_problem = False; + if(not end_found): + log("ERROR: Advertised ref does not contain an \"End\" line."); + ref_has_syntax_problem = True; + required_ref_fields = [ "dsaGroup.g", "dsaGroup.p", "dsaGroup.q", "dsaPubKey.y", "identity", "location", "myName", "sig" ]; + for require_ref_field in required_ref_fields: + if(not ref_fieldset.has_key(require_ref_field)): + log("ERROR: No %s field in ref" % ( require_ref_field )); + ref_has_syntax_problem = True; + if(ref_has_syntax_problem): + opts['refurl'] = self.prompt("URL of your noderef", opts['refurl']) + continue; + if( ref_fieldset[ "identity" ] != self.nodeIdentity ): + log("ERROR: The advertised ref's identity does not match the node's identity; perhaps your FCP host/port setting is wrong?"); + opts['refurl'] = self.prompt("URL of your noderef", opts['refurl']) + continue; + log("Test adding advertised ref..."); + try: + addpeer_result = f.addpeer( kwdict = ref_fieldset ) + except fcp.node.FCPException, msg: + if( 21 == msg.info[ 'Code' ] ): + log("ERROR: The node had trouble parsing the advertised ref"); + opts['refurl'] = self.prompt("URL of your noderef", opts['refurl']) + continue; + elif( 27 == msg.info[ 'Code' ] ): + log("ERROR: The node could not verify the signature of the advertised ref"); + opts['refurl'] = self.prompt("URL of your noderef", opts['refurl']) + continue; + elif( 28 == msg.info[ 'Code' ] ): + log("The advertised ref appears to be good"); + break; + elif( 29 == msg.info[ 'Code' ] ): + log("ERROR: The node has a peer with the advertised ref; perhaps your FCP host/port setting is wrong?"); + f.shutdown() + my_exit( 1 ) + log("ERROR: The node had trouble test-adding the advertised ref and gave us an unexpected error; perhaps you need to run updater.py"); + f.shutdown() + my_exit( 1 ) + except Exception, msg: + log("ERROR: caught generic exception adding peer: %s" % ( msg )); + f.shutdown() + my_exit( 1 ) + f.shutdown() + self.nrefs = 0 log("Getting Peer Update...") @@ -406,9 +480,9 @@ self.setup_bot2bot_trades( opts ) self.setup_bot2bot_trades_only( opts ) if( 'y' != opts['bot2bot_trades_only'] ): - opts['refurl'] = self.prompt("URL of your noderef") + opts['refurl'] = self.prompt("URL of your noderef") else: - opts['refurl'] = ''; + opts['refurl'] = ''; self.setup_privmsg_only( opts ) opts['greetinterval'] = 1800 From zothar at freenetproject.org Sun Apr 22 23:18:24 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 22 Apr 2007 23:18:24 +0000 (UTC) Subject: [Pyfreenet] r12885 - trunk/apps/pyFreenet Message-ID: <20070422231824.ECE864798DD@emu.freenetproject.org> Author: zothar Date: 2007-04-22 23:18:24 +0000 (Sun, 22 Apr 2007) New Revision: 12885 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: refactor into setup_refurl() Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-04-22 22:48:49 UTC (rev 12884) +++ trunk/apps/pyFreenet/refbot.py 2007-04-22 23:18:24 UTC (rev 12885) @@ -309,7 +309,7 @@ refmemfile.close(); except Exception, msg: log("ERROR: Failed to get advertised ref from URL."); - opts['refurl'] = self.prompt("URL of your noderef", opts['refurl']) + self.setup_refurl( opts ); continue; log("Checking syntax of advertised ref..."); ref_fieldset = {}; @@ -336,11 +336,11 @@ log("ERROR: No %s field in ref" % ( require_ref_field )); ref_has_syntax_problem = True; if(ref_has_syntax_problem): - opts['refurl'] = self.prompt("URL of your noderef", opts['refurl']) + self.setup_refurl( opts ); continue; if( ref_fieldset[ "identity" ] != self.nodeIdentity ): log("ERROR: The advertised ref's identity does not match the node's identity; perhaps your FCP host/port setting is wrong?"); - opts['refurl'] = self.prompt("URL of your noderef", opts['refurl']) + self.setup_refurl( opts ); continue; log("Test adding advertised ref..."); try: @@ -348,11 +348,11 @@ except fcp.node.FCPException, msg: if( 21 == msg.info[ 'Code' ] ): log("ERROR: The node had trouble parsing the advertised ref"); - opts['refurl'] = self.prompt("URL of your noderef", opts['refurl']) + self.setup_refurl( opts ); continue; elif( 27 == msg.info[ 'Code' ] ): log("ERROR: The node could not verify the signature of the advertised ref"); - opts['refurl'] = self.prompt("URL of your noderef", opts['refurl']) + self.setup_refurl( opts ); continue; elif( 28 == msg.info[ 'Code' ] ): log("The advertised ref appears to be good"); @@ -479,10 +479,8 @@ #self.setup_bot2bot_announce( opts ) **FIXME** Not implemented yet self.setup_bot2bot_trades( opts ) self.setup_bot2bot_trades_only( opts ) - if( 'y' != opts['bot2bot_trades_only'] ): - opts['refurl'] = self.prompt("URL of your noderef") - else: - opts['refurl'] = ''; + opts['refurl'] = ''; + self.setup_refurl( opts ); self.setup_privmsg_only( opts ) opts['greetinterval'] = 1800 @@ -564,6 +562,16 @@ opts['privmsg_only'] = 'y'; #@-node:setup_privmsg_only + #@+node:setup_refurl + def setup_refurl(self, opts): + """ + """ + if( 'y' != opts['bot2bot_trades_only'] ): + opts['refurl'] = self.prompt("URL of your noderef") + else: + opts['refurl'] = ''; + + #@-node:setup_refurl #@+node:save def save(self): From zothar at freenetproject.org Tue Apr 24 00:26:39 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Tue, 24 Apr 2007 00:26:39 +0000 (UTC) Subject: [Pyfreenet] r12912 - trunk/apps/pyFreenet Message-ID: <20070424002639.78B1D4798D0@emu.freenetproject.org> Author: zothar Date: 2007-04-24 00:26:39 +0000 (Tue, 24 Apr 2007) New Revision: 12912 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: Be backwards compatible with pre-1030 nodes when doing advertised ref sanity checking. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-04-23 23:12:05 UTC (rev 12911) +++ trunk/apps/pyFreenet/refbot.py 2007-04-24 00:26:39 UTC (rev 12912) @@ -368,6 +368,11 @@ log("ERROR: caught generic exception adding peer: %s" % ( msg )); f.shutdown() my_exit( 1 ) + try: + f.removepeer(ref_fieldset[ "identity" ] ); + except Exception, msg: + pass; + break; f.shutdown() self.nrefs = 0 From zothar at freenetproject.org Fri Apr 27 00:01:56 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Fri, 27 Apr 2007 00:01:56 +0000 (UTC) Subject: [Pyfreenet] r13004 - trunk/apps/pyFreenet Message-ID: <20070427000156.CCC2B47A068@emu.freenetproject.org> Author: zothar Date: 2007-04-27 00:01:56 +0000 (Fri, 27 Apr 2007) New Revision: 13004 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: Refuse spaces in the node's name used by the bot. Complain about configuration file corruption more gracefully. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-04-26 23:45:58 UTC (rev 13003) +++ trunk/apps/pyFreenet/refbot.py 2007-04-27 00:01:56 UTC (rev 13004) @@ -87,8 +87,25 @@ # load, or create, a config if os.path.isfile(confpath): - opts = self.load() + try: + opts = self.load() + except Exception, msg: + print "ERROR loading configuration file: %s" % ( msg ); + print "ERROR: Failed to load configuration file. Perhaps it is corrupted?"; + my_exit( 1 ); needToSave = False + if( len( opts['usernick'] ) > 12 ): + print "The node's name used by the bot cannot be any longer than 12 characters because the bot's IRC nickname cannot be any longer than 16 characters and the bot IRC nickname will be this value with '_bot' added to the end. Try again." + self.setup_usernick( opts ) + needToSave = True + elif( opts['usernick'][ -4: ].lower() == "_bot" ): + print "The node's name used by the bot should not end in \"_bot\" because the bot IRC nickname will use the this node's name with '_bot' added to the end. Try again." + self.setup_usernick( opts ) + needToSave = True + elif( ' ' in opts['usernick'] ): + print "The node's name used by the bot should not contain spaces because the bot IRC nickname cannot contain spaces. Try again." + self.setup_usernick( opts ) + needToSave = True else: opts = self.setup() needToSave = True @@ -434,17 +451,10 @@ print "** so that someone else can't /msg your bot and shut it down" print "** while you're away. Use /msg nickserv register " opts['ownerircnick'] = self.prompt("Enter your usual freenode.net IRC nick") + opts['usernick'] = opts['ownerircnick'] print - print "** Give a short 12 character or less version of your node's name; The bot will tack \"_bot\" onto the end of it to form it's IRC nick" - while( 1 ): - opts['usernick'] = self.prompt("Enter your node's name", opts['ownerircnick']) - if( len( opts['usernick'] ) > 12 ): - print "The node's name used by the bot cannot be any longer than 12 characters because the bot's IRC nickname cannot be any longer than 16 characters and the bot IRC nickname will be this value with '_bot' added to the end. Try again." - elif( opts['usernick'][ -4: ].lower() == "_bot" ): - print "The node's name used by the bot should not end in \"_bot\" because the bot IRC nickname will use the this node's name with '_bot' added to the end. Try again." - else: - break - print; + self.setup_usernick( opts ) + print print "** You need to choose a new password, since this bot will" print "** register this password with freenode 'nickserv', and" print "** on subsequent runs, will identify with this password" @@ -577,6 +587,23 @@ opts['refurl'] = ''; #@-node:setup_refurl + #@+node:setup_usernick + def setup_usernick(self, opts): + """ + """ + print "** Give a short 12 character or less version of your node's name; The bot will tack \"_bot\" onto the end of it to form it's IRC nick" + while( 1 ): + opts['usernick'] = self.prompt("Enter your node's name", opts['usernick']) + if( len( opts['usernick'] ) > 12 ): + print "The node's name used by the bot cannot be any longer than 12 characters because the bot's IRC nickname cannot be any longer than 16 characters and the bot IRC nickname will be this value with '_bot' added to the end. Try again." + elif( opts['usernick'][ -4: ].lower() == "_bot" ): + print "The node's name used by the bot should not end in \"_bot\" because the bot IRC nickname will use the this node's name with '_bot' added to the end. Try again." + elif( ' ' in opts['usernick'] ): + print "The node's name used by the bot should not contain spaces because the bot IRC nickname cannot contain spaces. Try again." + else: + break + + #@-node:setup_usernick #@+node:save def save(self): From zothar at freenetproject.org Fri Apr 27 00:18:02 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Fri, 27 Apr 2007 00:18:02 +0000 (UTC) Subject: [Pyfreenet] r13005 - trunk/apps/pyFreenet Message-ID: <20070427001802.E71F6479754@emu.freenetproject.org> Author: zothar Date: 2007-04-27 00:18:02 +0000 (Fri, 27 Apr 2007) New Revision: 13005 Modified: trunk/apps/pyFreenet/refbot.py Log: refbot: Refuse periods in the node's name used by the bot as well. Modified: trunk/apps/pyFreenet/refbot.py =================================================================== --- trunk/apps/pyFreenet/refbot.py 2007-04-27 00:01:56 UTC (rev 13004) +++ trunk/apps/pyFreenet/refbot.py 2007-04-27 00:18:02 UTC (rev 13005) @@ -106,6 +106,10 @@ print "The node's name used by the bot should not contain spaces because the bot IRC nickname cannot contain spaces. Try again." self.setup_usernick( opts ) needToSave = True + elif( '.' in opts['usernick'] ): + print "The node's name used by the bot should not contain periods because the bot IRC nickname cannot contain periods. Try again." + self.setup_usernick( opts ) + needToSave = True else: opts = self.setup() needToSave = True @@ -600,6 +604,8 @@ print "The node's name used by the bot should not end in \"_bot\" because the bot IRC nickname will use the this node's name with '_bot' added to the end. Try again." elif( ' ' in opts['usernick'] ): print "The node's name used by the bot should not contain spaces because the bot IRC nickname cannot contain spaces. Try again." + elif( '.' in opts['usernick'] ): + print "The node's name used by the bot should not contain periods because the bot IRC nickname cannot contain periods. Try again." else: break From pyfreenet at freenetproject.org Fri Apr 27 12:20:21 2007 From: pyfreenet at freenetproject.org (Investor Morgan) Date: Fri, 27 Apr 2007 12:20:21 +0000 (UTC) Subject: [Pyfreenet] *****SPAM***** Daily News 16664221 Message-ID: <20070427-42022.6769.qmail@h44.130.29.71.ip.alltel.net> An embedded and charset-unspecified text was scrubbed... Name: not available Url: http://emu.freenetproject.org/pipermail/pyfreenet/attachments/20070427/0d0a6f6d/attachment.txt -------------- next part -------------- An embedded message was scrubbed... From: Investor Morgan Subject: Daily News 16664221 Date: Fri, 27 Apr 2007 12:20:21 +0000 (UTC) Size: 5829 Url: http://emu.freenetproject.org/pipermail/pyfreenet/attachments/20070427/0d0a6f6d/attachment.eml From pyfreenet at freenetproject.org Sat Apr 28 02:57:53 2007 From: pyfreenet at freenetproject.org (Canadian Doctor Mia) Date: Sat, 28 Apr 2007 02:57:53 +0000 (UTC) Subject: [Pyfreenet] MedHelp 72903 Message-ID: <20070427055746.124081.qmail@pool-71-243-45-174.bos.east.verizon.net> An HTML attachment was scrubbed... URL: http://emu.freenetproject.org/pipermail/pyfreenet/attachments/20070428/45b221be/attachment.htm From nextgens at freenetproject.org Sat Apr 21 09:35:52 2007 From: nextgens at freenetproject.org (nextgens at freenetproject.org) Date: Sat, 21 Apr 2007 09:35:52 -0000 Subject: [Pyfreenet] r12835 - trunk/apps/pyFreenet Message-ID: <20070421093550.7AB97479F66@emu.freenetproject.org> Author: nextgens Date: 2007-04-21 09:35:50 +0000 (Sat, 21 Apr 2007) New Revision: 12835 Removed: trunk/apps/pyFreenet/fcpgenkey.py trunk/apps/pyFreenet/fcpget.py trunk/apps/pyFreenet/fcpinvertkey.py trunk/apps/pyFreenet/fcpnames.py trunk/apps/pyFreenet/fcpput.py trunk/apps/pyFreenet/fcpredirect.py trunk/apps/pyFreenet/fproxyproxy.py trunk/apps/pyFreenet/freedisk.py trunk/apps/pyFreenet/freesitemgr.py Modified: trunk/apps/pyFreenet/fcpgenkey trunk/apps/pyFreenet/fcpnames trunk/apps/pyFreenet/fcpredirect trunk/apps/pyFreenet/fcpxmlrpc.cgi trunk/apps/pyFreenet/fproxyproxy trunk/apps/pyFreenet/setup.py trunk/apps/pyFreenet/tutorial.py Log: pyfreenet: remove useless files, set svn:executable where needed Property changes on: trunk/apps/pyFreenet/fcpgenkey ___________________________________________________________________ Name: svn:executable + * Deleted: trunk/apps/pyFreenet/fcpgenkey.py =================================================================== --- trunk/apps/pyFreenet/fcpgenkey.py 2007-04-21 00:07:29 UTC (rev 12834) +++ trunk/apps/pyFreenet/fcpgenkey.py 2007-04-21 09:35:50 UTC (rev 12835) @@ -1,4 +0,0 @@ -#!/usr/bin/env python -import fcp -fcp.genkey.main() - Deleted: trunk/apps/pyFreenet/fcpget.py =================================================================== --- trunk/apps/pyFreenet/fcpget.py 2007-04-21 00:07:29 UTC (rev 12834) +++ trunk/apps/pyFreenet/fcpget.py 2007-04-21 09:35:50 UTC (rev 12835) @@ -1,4 +0,0 @@ -#!/usr/bin/env python -import fcp -fcp.get.main() - Deleted: trunk/apps/pyFreenet/fcpinvertkey.py =================================================================== --- trunk/apps/pyFreenet/fcpinvertkey.py 2007-04-21 00:07:29 UTC (rev 12834) +++ trunk/apps/pyFreenet/fcpinvertkey.py 2007-04-21 09:35:50 UTC (rev 12835) @@ -1,4 +0,0 @@ -#!/usr/bin/env python -import fcp -fcp.invertkey.main() - Property changes on: trunk/apps/pyFreenet/fcpnames ___________________________________________________________________ Name: svn:executable + * Deleted: trunk/apps/pyFreenet/fcpnames.py =================================================================== --- trunk/apps/pyFreenet/fcpnames.py 2007-04-21 00:07:29 UTC (rev 12834) +++ trunk/apps/pyFreenet/fcpnames.py 2007-04-21 09:35:50 UTC (rev 12835) @@ -1,4 +0,0 @@ -#!/usr/bin/env python -import fcp -fcp.names.main() - Deleted: trunk/apps/pyFreenet/fcpput.py =================================================================== --- trunk/apps/pyFreenet/fcpput.py 2007-04-21 00:07:29 UTC (rev 12834) +++ trunk/apps/pyFreenet/fcpput.py 2007-04-21 09:35:50 UTC (rev 12835) @@ -1,3 +0,0 @@ -#!/usr/bin/env python -import fcp -fcp.put.main() Property changes on: trunk/apps/pyFreenet/fcpredirect ___________________________________________________________________ Name: svn:executable + * Deleted: trunk/apps/pyFreenet/fcpredirect.py =================================================================== --- trunk/apps/pyFreenet/fcpredirect.py 2007-04-21 00:07:29 UTC (rev 12834) +++ trunk/apps/pyFreenet/fcpredirect.py 2007-04-21 09:35:50 UTC (rev 12835) @@ -1,4 +0,0 @@ -#!/usr/bin/env python -import fcp -fcp.redirect.main() - Property changes on: trunk/apps/pyFreenet/fcpxmlrpc.cgi ___________________________________________________________________ Name: svn:executable + * Property changes on: trunk/apps/pyFreenet/fproxyproxy ___________________________________________________________________ Name: svn:executable + * Deleted: trunk/apps/pyFreenet/fproxyproxy.py =================================================================== --- trunk/apps/pyFreenet/fproxyproxy.py 2007-04-21 00:07:29 UTC (rev 12834) +++ trunk/apps/pyFreenet/fproxyproxy.py 2007-04-21 09:35:50 UTC (rev 12835) @@ -1,4 +0,0 @@ -#! /usr/bin/env python -import fcp -fcp.fproxyproxy.main() - Deleted: trunk/apps/pyFreenet/freedisk.py =================================================================== --- trunk/apps/pyFreenet/freedisk.py 2007-04-21 00:07:29 UTC (rev 12834) +++ trunk/apps/pyFreenet/freedisk.py 2007-04-21 09:35:50 UTC (rev 12835) @@ -1,909 +0,0 @@ -#! /usr/bin/env python -#@+leo-ver=4 -#@+node:@file freedisk.py -#@@first -#@@language python -#@+others -#@+node:freedisk app -""" -freedisk is a command-line utility for creating, -mounting and synchronising freenet freedisks - -Invoke with -h for help -""" -#@+others -#@+node:imports -import sys, os -import getopt -import traceback -import time -import sha -import getpass - -try: - import fcp - from fcp import node, freenetfs - from fcp.xmlobject import XMLFile, XMLNode -except: - print "** PyFCP core module 'fcp' not installed." - print "** Please refer to the INSTALL file within the PyFCP source package" - sys.exit(1) - -try: - import SSLCrypto - - -except: - SSLCrypto = None - print "** WARNING! SSLCrypto module not installed" - print "** Please refer to the INSTALL file within the PyFCP source package" - -#@-node:imports -#@+node:globals -# args shorthand -argv = sys.argv -argc = len(argv) -progname = argv[0] - -# default config file stuff -homedir = os.path.expanduser("~") -configFile = os.path.join(homedir, ".freediskrc") - -defaultMountpoint = os.path.join(homedir, "freedisk") - -#@-node:globals -#@+node:class FreediskMgr -class FreediskMgr: - """ - Freedisk manager class - """ - #@ @+others - #@+node:__init__ - def __init__(self, *args, **kw): - - self.args = args - self.kw = kw - - configFile = self.configFile = kw['configFile'] - conf = self.conf = FreediskConfig(configFile) - #ipython(conf) - - - # validate args - nargs = len(args) - if nargs == 0: - usage("No command given") - - cmd = self.cmd = args[0] - - # barf if not 'init' and no config - if cmd != 'init' and not os.path.isfile(configFile): - usage("Config file %s does not exist\nRun '%s init' to create it" % ( - configFile, progname)) - - # validate args count for cmds needing diskname arg - if cmd in ['new', 'add', 'del', 'update', 'commit']: - if nargs < 2: - usage("%s: Missing argument " % cmd) - diskname = self.diskname = args[1] - - # get paths to freedisk dir and pseudo-files - self.diskPath = os.path.join(conf.mountpoint, "usr", diskname) - self.pubKeyPath = os.path.join(self.diskPath, ".publickey") - self.privKeyPath = os.path.join(self.diskPath, ".privatekey") - self.passwdPath = os.path.join(self.diskPath, ".passwd") - self.cmdPath = os.path.join(self.diskPath, ".cmd") - self.statusPath = os.path.join(self.diskPath, ".status") - - # implement command synonyms - self.cmd_setup = self.cmd_init - self.cmd_mount = self.cmd_start - self.cmd_unmoutn = self.cmd_umount = self.cmd_stop - - #@-node:__init__ - #@+node:run - def run(self): - """ - Executes the given command - """ - cmd = self.cmd - method = getattr(self, "cmd_"+cmd, None) - if not method: - usage("Unrecognised command '%s'" % cmd) - - result = method(*self.args[1:]) or "" - - return result - - #@-node:run - #@+node:cmd_init - def cmd_init(self, *args): - - conf = self.conf - - # initialise/change freedisk config - - print "Freedisk configuration" - print - print "Your freedisk config will normally be stored in the file:" - print " %s" % self.configFile - - # allow password change - if conf.passwd: - # got a password already - prmt = "Do you wish to change your config password" - else: - # new password - prmt = "Do you wish to encrypt this file" - if getyesno(prmt): - passwd = getpasswd("New Password", True) - conf.setPassword(passwd) - print "Password successfully changed" - - # host parms - fcpHost = raw_input("Freenet FCP Hostname: [%s] " % conf.fcpHost).strip() - if fcpHost: - conf.fcpHost = fcpHost - - fcpPort = raw_input("Freenet FCP Port: [%s] "% conf.fcpPort).strip() - if fcpPort: - conf.fcpPort = fcpPort - - print "Freenet verbosity:" - print " (0=SILENT, 1=FATAL, 2=CRITICAL, 3=ERROR" - print " 4=INFO, 5=DETAIL, 6=DEBUG)" - v = raw_input("[%s] " % conf.fcpVerbosity).strip() - if v: - conf.fcpVerbosity = v - - while 1: - m = raw_input("Mountpoint [%s] " % conf.mountpoint).strip() \ - or conf.mountpoint - if m: - if not os.path.isdir(m): - print "No such directory '%s'" % m - elif not os.path.exists(m): - print "%s is not a directory" % m - else: - conf.mountpoint = m - mountpoint = m - break - - print "Freedisk configuration successfully changed" - - #@-node:cmd_init - #@+node:cmd_start - def cmd_start(self, *args): - - conf = self.conf - kw = self.kw - - # spawn the child - print "Spawning freenetfs filesystem process..." - os.system("freedisk run &") - - # wait for child to bring up the fs, via a very crude test - keyDir = os.path.join(conf.mountpoint, "keys") - print "Waiting for disk to come up..." - while not os.path.isdir(keyDir): - time.sleep(1) - disks = conf.getDisks() - - if disks: - print "Freenetfs now mounted, adding existing disks..." - else: - print "Freenetfs now mounted, no freedisks at present" - - for disk in disks: - - #break - - diskPath = os.path.join(conf.mountpoint, "usr", disk.name) - - # barf if a freedisk of that name is already mounted - if os.path.exists(diskPath): - usage("Freedisk %s seems to be already mounted" % disk.name) - - self.doFsCommand("mount %s|%s|%s" % ( - disk.name, disk.uri, disk.passwd)) - - if 0: - # mkdir to create the freedisk dir - os.mkdir(diskPath) - - pubKeyPath = os.path.join(diskPath, ".publickey") - privKeyPath = os.path.join(diskPath, ".privatekey") - passwdPath = os.path.join(diskPath, ".passwd") - - # wait for the pseudo-files to come into existence - while not os.path.isfile(privKeyPath): - time.sleep(0.1) - - # set the key and password - file(pubKeyPath, "w").write(disk.uri) - file(privKeyPath, "w").write(disk.privUri) - file(passwdPath, "w").write(disk.passwd) - - #while True: - # time.sleep(1) - - #@-node:cmd_start - #@+node:cmd_run - def cmd_run(self, *args): - """ - become the foreground FUSE process. - - This is launched by 'freedisk start' - """ - conf = self.conf - kw = self.kw - - print "Creating freenetfs filesystem..." - fs = freenetfs.FreenetFuseFS( - conf.mountpoint, - fcpHost=conf.fcpHost, - fcpPort=conf.fcpPort, - verbosity=conf.fcpVerbosity, - debug=kw['debug'], - multithreaded=kw['multithreaded'], - ) - - # never returns, until fs is unmounted - print "Freenetfs filesystem now alive..." - fs.run() - - #@-node:cmd_run - #@+node:cmd_stop - def cmd_stop(self, *args): - """ - Unmount the freenetfs - """ - os.system("umount %s" % self.conf.mountpoint) - - #@-node:cmd_stop - #@+node:cmd_new - def cmd_new(self, *args): - """ - Creates a new freedisk with a random key - """ - #print "new: %s: NOT IMPLEMENTED" % diskname - - conf = self.conf - diskname = self.diskname - diskPath = self.diskPath - - if os.path.exists(diskPath): - usage("Freedisk %s seems to be already mounted" % diskname) - - # get a password if desired - passwd = getpasswd("Encrypt disk with password", True) - - # get a new private key - keyDir = os.path.join(conf.mountpoint, "keys") - if not os.path.isdir(keyDir): - print "No keys directory %s" % keyDir - print "Is your freenetfs mounted?" - usage("Freenetfs not mounted") - keyName = "freedisk_%s_%s" % (diskname, int(time.time()*1000000)) - keyPath = os.path.join(keyDir, keyName) - - keys = file(keyPath).read().strip().split("\n") - pubKey, privKey = [k.split("/")[0].split("freenet:")[-1] for k in keys] - - print self.doFsCommand("mount %s|%s|%s" % (diskname, privKey, passwd)) - - # and, of course, update config - conf.addDisk(diskname, privKey, passwd) - - return - - - # deprecated - - if 0: - # mkdir to create the freedisk dir - os.mkdir(diskPath) - - # wait for the pseudo-files to come into existence - while not os.path.isfile(privKeyPath): - time.sleep(0.1) - - #status("About to write to %s" % privKeyPath) - - file(self.pubKeyPath, "w").write(pubKey) - file(self.privKeyPath, "w").write(privKey) - file(self.passwdPath, "w").write(passwd) - - #@-node:cmd_new - #@+node:cmd_add - def cmd_add(self, *args): - - nargs = len(args) - - diskname = self.diskname - conf = self.conf - - # get uri - if nargs < 2: - usage("add: Missing URI") - uri = args[1] - - #print "add: %s: NOT IMPLEMENTED" % diskname - - # barf if a freedisk of that name is already mounted - if os.path.exists(self.diskPath): - usage("Freedisk %s seems to be already mounted" % diskname) - - # get a password if desired - passwd = getpasswd("Disk's password", True) - - print self.doFsCommand("mount %s|%s|%s" % (diskname, uri, passwd)) - - # and, of course, update config - conf.addDisk(diskname, uri, passwd) - - return - - # deprecated - - if 0: - # mkdir to create the freedisk dir - os.mkdir(self.diskPath) - - # wait for the pseudo-files to come into existence - while not os.path.isfile(self.privKeyPath): - time.sleep(0.1) - - # set the keys - - if fcp.node.uriIsPrivate(uri): - path = privKeyPath - else: - path = pubKeyPath - f = file(path, "w") - f.write(uri) - f.flush() - f.close() - - - #@nonl - #@-node:cmd_add - #@+node:cmd_del - def cmd_del(self, *args): - """ - unmounts a freedisk - """ - conf = self.conf - diskname = self.diskname - - disk = conf.getDisk(diskname) - - if not isinstance(disk, XMLNode): - usage("No such disk '%s'" % diskname) - - self.doFsCommand("umount %s" % diskname) - - conf.delDisk(diskname) - - return - - # deprecated - - path = os.path.join(conf.mountpoint, "usr", diskname) - os.rmdir(path) - - #@-node:cmd_del - #@+node:cmd_update - def cmd_update(self, *args): - """ - Updates a freedisk *from* freenet - """ - conf = self.conf - diskname = self.diskname - - disk = conf.getDisk(diskname) - - if not isinstance(disk, XMLNode): - usage("No such disk '%s'" % diskname) - - self.doFsCommand("update %s" % diskname) - - return - - # deprecated - - cmdPath = self.cmdPath - diskname = self.diskname - - print "update: %s: NOT IMPLEMENTED" % diskname - - f = file(cmdPath, "w") - f.write("update") - f.flush() - f.close() - - #@-node:cmd_update - #@+node:cmd_commit - def cmd_commit(self, *args): - """ - commits a freedisk *to* freenet - """ - conf = self.conf - diskname = self.diskname - - disk = conf.getDisk(diskname) - - if not isinstance(disk, XMLNode): - usage("No such disk '%s'" % diskname) - - res = self.doFsCommand("commit %s" % diskname) - - return res - - # deprecated - - cmdPath = self.cmdPath - diskname = self.diskname - - print "commit: %s: launching.." % diskname - - f = file(cmdPath, "w") - f.write("commit") - f.flush() - f.close() - - #@-node:cmd_commit - #@+node:cmd_list - def cmd_list(self, *args): - """ - Produces a list of mounted freedisks - """ - conf = self.conf - - 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): - - # arbitrary command, for testing - cmd = args[0] + "|".join(args[1:]) - print repr(self.doFsCommand(cmd)) - - #@-node:cmd_cmd - #@+node:doFsCommand - def doFsCommand(self, cmd): - """ - Executes a command via base64-encoded file - """ - cmdBase64 = fcp.node.base64encode(cmd) - if len(cmdBase64) > 254: - raise Exception("Command too long") - - path = self.conf.mountpoint + "/cmds/" + cmdBase64 - return file(path).read() - - #@-node:doFsCommand - #@-others - -#@-node:class FreediskMgr -#@+node:class FreediskConfig -class FreediskConfig: - """ - allows for loading/saving/changing freedisk configs - """ - #@ @+others - #@+node:attribs - _intAttribs = ["fcpPort", "fcpVerbosity"] - - _strAttribs = ["fcpHost", "mountpoint"] - - #@-node:attribs - #@+node:__init__ - def __init__(self, path, passwd=None): - """ - Create a config object from file at 'path', if it exists - """ - #print "FreediskConfig: path=%s" % path - - self.path = path - self.passwd = passwd - - if os.path.isfile(path): - self.load() - else: - self.create() - - self.root = self.xml.root - - #@-node:__init__ - #@+node:load - def load(self): - """ - Loads config from self.config - """ - # get the raw xml, plain or encrypted - ciphertext = file(self.path, "rb").read() - - plaintext = ciphertext - - # try to wrap into xml object - try: - xml = self.xml = XMLFile(raw=plaintext) - except: - i = 0 - while i < 3: - passwd = self.passwd = getpasswd("Freedisk config password") - plaintext = decrypt(self.passwd, ciphertext) - try: - xml = XMLFile(raw=plaintext) - break - except: - i += 1 - continue - if i == 3: - self.abort() - - self.xml = xml - self.root = xml.root - - #@-node:load - #@+node:create - def create(self): - """ - Creates a new config object - """ - self.xml = XMLFile(root="freedisk") - root = self.root = self.xml.root - - self.fcpHost = fcp.node.defaultFCPHost - self.fcpPort = fcp.node.defaultFCPPort - self.fcpVerbosity = fcp.node.defaultVerbosity - self.mountpoint = defaultMountpoint - - self.save() - - #@-node:create - #@+node:save - def save(self): - - plain = self.xml.toxml() - - if self.passwd: - cipher = encrypt(self.passwd, plain) - else: - cipher = plain - - f = file(self.path, "wb") - f.write(cipher) - f.flush() - f.close() - - #@-node:save - #@+node:abort - def abort(self): - - print "freedisk: Cannot decrypt freedisk config file '%s'" % self.path - print - print "If you truly can't remember the password, your only" - print "option now is to delete the config file and start again" - sys.exit(1) - - #@-node:abort - #@+node:setPassword - def setPassword(self, passwd): - - self.passwd = passwd - self.save() - - #@-node:setPassword - #@+node:addDisk - def addDisk(self, name, uri, passwd): - - d = self.getDisk(name) - if isinstance(d, XMLNode): - raise Exception("Disk '%s' already exists" % name) - - diskNode = self.root._addNode("disk") - diskNode.name = name - diskNode.uri = uri - diskNode.passwd = passwd - - self.save() - - #@-node:addDisk - #@+node:getDisk - def getDisk(self, name): - """ - Returns a record for a freedisk of name - """ - disks = self.root._getChild("disk") - - for d in disks: - if d.name == name: - return d - - return None - - #@-node:getDisk - #@+node:getDisks - def getDisks(self): - """ - Returns all freedisk records - """ - return self.root._getChild("disk") - - #@-node:getDisks - #@+node:delDisk - def delDisk(self, name): - """ - Removes disk of given name - """ - d = self.getDisk(name) - if not isinstance(d, XMLNode): - raise Exception("No such freedisk '%s'" % name) - - self.root._delChild(d) - - self.save() - - #@-node:delDisk - #@+node:__getattr__ - def __getattr__(self, attr): - - if attr in self._intAttribs: - try: - return int(getattr(self.root, attr)) - except: - raise AttributeError(attr) - - elif attr in self._strAttribs: - try: - return str(getattr(self.root, attr)) - except: - raise AttributeError(attr) - - else: - raise AttributeError(attr) - - #@-node:__getattr__ - #@+node:__setattr__ - def __setattr__(self, attr, val): - - if attr in self._intAttribs: - val = str(val) - setattr(self.root, attr, val) - self.save() - elif attr in self._strAttribs: - setattr(self.root, attr, val) - self.save() - else: - self.__dict__[attr] = val - - #@-node:__setattr__ - #@-others - -#@-node:class FreediskConfig -#@+node:usage -def usage(msg=None, ret=1): - """ - Prints usage message then exits - """ - if msg: - sys.stderr.write(msg+"\n") - sys.stderr.write("Usage: %s [options] [ []]\n" % progname) - sys.stderr.write("Type '%s -h' for help\n" % progname) - sys.exit(ret) - -#@-node:usage -#@+node:help -def help(): - """ - Display help info then exit - """ - print "%s: manage a freenetfs filesystem" % progname - print "Usage: %s [] []" % progname - print "Options:" - print " -h, --help Display this help" - print " -c, --config= Specify config file, default ~/.freediskrc" - print "Commands:" - print " init Edit configuration interactively" - print " mount Mount the freenetfs" - print " unmount Unmount the freenetfs" - print " new Create a new freedisk of name " - print " A new keypair will be generated." - print " add Add an existing freedisk of name " - print " and public key URI " - print " del Remove freedisk of name " - print " update Sync freedisk from freenet" - print " commit Commit freedisk into freenet" - print - print "Environment variables:" - print " FREEDISK_CONFIG - set this in place of '-c' argument" - - sys.exit(0) - -#@-node:help -#@+node:removeDirAndContents -def removeDirAndContents(path): - - files = os.listdir(path) - - for f in files: - fpath = os.path.join(path, f) - if os.path.isfile(fpath): - os.unlink(fpath) - elif os.path.isdir(fpath): - removeDirAndContents(fpath) - os.rmdir(path) - -#@-node:removeDirAndContents -#@+node:status -def status(msg): - sys.stdout.write(msg + "...") - time.sleep(1) - print - - -#@-node:status -#@+node:encrypt -def encrypt(passwd, s): - - passwd = sha.new(passwd).digest() - - if SSLCrypto: - # encrypt with blowfish 256, key=sha(password), IV=00000000 - return SSLCrypto.blowfish(passwd).encrypt(s) - else: - # no encyrption available, return plaintext - return s - -#@-node:encrypt -#@+node:decrypt -def decrypt(passwd, s): - - passwd = sha.new(passwd).digest() - - if SSLCrypto: - # decrypt with blowfish 256, key=sha(password), IV=00000000 - return SSLCrypto.blowfish(passwd).decrypt(s) - else: - # no encyrption available, return plaintext - return s - -#@-node:decrypt -#@+node:getpasswd -def getpasswd(prompt="Password", confirm=False): - - if not confirm: - return getpass.getpass(prompt+": ").strip() - - while 1: - passwd = getpass.getpass(prompt+": ").strip() - if passwd: - passwd1 = getpasswd("Verify password").strip() - if passwd == passwd1: - break - print "passwords do not match, please try again" - else: - break - - return passwd - -#@-node:getpasswd -#@+node:ipython -def ipython(o=None): - - from IPython.Shell import IPShellEmbed - - ipshell = IPShellEmbed() - - ipshell() # this call anywhere in your program will start IPython - -#@-node:ipython -#@+node:getyesno -def getyesno(prmt, dflt=True): - - if dflt: - ynprmt = "[Y/n] " - else: - ynprmt = "[y/N] " - - resp = raw_input(prmt + "? " + ynprmt).strip() - if not resp: - return dflt - resp = resp.lower()[0] - return resp == 'y' - -#@-node:getyesno -#@+node:main -def main(): - """ - Front end - """ - #@ <> - #@+node:<> - # create defaults - - opts = { - 'debug' : False, - 'multithreaded' : False, - 'configFile' : configFile, - 'verbosity' : fcp.ERROR, - 'Verbosity' : 1023, - } - - #@-node:<> - #@nl - - #@ <> - #@+node:<> - # process args - - try: - cmdopts, args = getopt.getopt( - sys.argv[1:], - "?hvc:dm", - ["help", "verbose", - "multithreaded", - "config=", "debug", - ] - ) - except getopt.GetoptError: - # print help information and exit: - usage() - sys.exit(2) - - #print cmdopts - for o, a in cmdopts: - - if o in ("-?", "-h", "--help"): - help() - - if o in ("-v", "--verbose"): - opts['verbosity'] = fcp.node.DETAIL - opts['Verbosity'] = 1023 - verbose = True - - if o in ("-c", "--config"): - opts['configFile'] = a - - if o in ("-d", "--debug"): - opts['debug'] = True - - if o in ("-m", "--multithreaded"): - opts['multithreaded'] = True - - #@-node:<> - #@nl - - #@ <> - #@+node:<> - mgr = FreediskMgr(*args, **opts) - - print mgr.run() - - #@-node:<> - #@nl - -#@-node:main -#@+node:mainline -if __name__ == '__main__': - main() - -#@-node:mainline -#@-others - -#@-node:freedisk app -#@-others -#@-node:@file freedisk.py -#@-leo Deleted: trunk/apps/pyFreenet/freesitemgr.py =================================================================== --- trunk/apps/pyFreenet/freesitemgr.py 2007-04-21 00:07:29 UTC (rev 12834) +++ trunk/apps/pyFreenet/freesitemgr.py 2007-04-21 09:35:50 UTC (rev 12835) @@ -1,492 +0,0 @@ -#!/usr/bin/env python -#@+leo-ver=4 -#@+node:@file freesitemgr.py -#@@first -#@+others -#@+node:freesitemgr-script -""" -A utility to update freesites from within a cron environment -""" -#@+others -#@+node:imports -import sys, os, time, commands, traceback, getopt - -import fcp.node -from fcp.sitemgr import SiteMgr, fixUri - -#@-node:imports -#@+node:globals -progname = sys.argv[0] - -# time we wait after starting fred, to allow the node to 'warm up' -# and make connections to its peers -startupTime = 180 - -# directory where we have freenet installed, -# change it as needed -#freenetDir = "/home/david/freenet" - -homeDir = os.path.expanduser("~") - -# derive path of freenet pid file, the (non)existence -# of which is the easiest test of whether the freenet -# node is running -#freenetPidFile = os.path.join(freenetDir, "Freenet.pid") - -logFile = os.path.join(homeDir, "updatesites.log") -pidFile = os.path.join(homeDir, "updatesites.pid") - -if sys.platform.startswith("win"): - confDirName = "freesitemgr" -else: - confDirName = ".freesitemgr" -confDir = os.path.join(homeDir, confDirName) - -#@-node:globals -#@+node:editCreateConfig -def editCreateConfig(sitemgr): - """ - Creates an initial config file interactively - """ - print "Setting up configuration file %s" % sitemgr.conffile - - # get fcp hostname - fcpHost = raw_input("FCP Hostname [%s] (* for all): " % sitemgr.fcpHost).strip() - if not fcpHost: - fcpHost = sitemgr.fcpHost - if fcpHost == '*': - fcpHost = "" - - # get fcp port - while 1: - fcpPort = raw_input("FCP Port [%s]: " % sitemgr.fcpPort).strip() - if not fcpPort: - fcpPort = sitemgr.fcpPort - try: - fcpPort = int(fcpPort) - except: - continue - break - - print "Trying FCP port at %s:%s" % (fcpHost, fcpPort) - try: - fcpnode = fcp.FCPNode(host=fcpHost, port=fcpPort) - except: - traceback.print_exc() - print "Failed to connect to FCP Port" - print "Please ensure your node is running, with its FCP port" - print "reachable at %s:%s, and try this command again" % (fcpHost, fcpPort) - print "Setup aborted" - return - - fcpnode.shutdown() - - sitemgr.fcpHost = fcpHost - sitemgr.fcpPort = fcpPort - - # confirm and save - if getyesno("Save configuration", True): - sitemgr.save() - - print "Configuration saved to %s" % sitemgr.conffile - -#@-node:editCreateConfig -#@+node:addSite -def addSite(sitemgr): - """ - Interactively adds a new site to config - """ - print "Add new site" - - if not sitemgr.node: - print "Cannot add site - no contact with node on %s:%s" % ( - sitemgr.fcpHost, sitemgr.fcpPort) - print "Please ensure your freenet node is running, or run" - print "'%s setup' to edit your FCP access address" % progname - - while 1: - sitename = raw_input("Name of freesite, or empty line to cancel: ").strip() - if not sitename: - print "Add site aborted" - return - elif sitemgr.hasSite(sitename): - print "Freesite '%s' already exists" % sitename - continue - break - - while 1: - sitedir = raw_input("Directory where freesite's files reside: ").strip() - if not sitedir: - print "Add site aborted" - return - sitedir = os.path.abspath(sitedir) - if not os.path.isdir(sitedir): - print "'%s' is not a directory, try again" % sitedir - continue - #elif not os.path.isfile(os.path.join(sitedir, "index.html")): - # print "'%s' has no index.html, try again" % sitedir - # continue - break - - while 1: - uriPriv = raw_input("Site private URI (if any - press ENTER for new\n: ").strip() - if not uriPriv: - uriPub, uriPriv = sitemgr.node.genkey() - else: - if not fcp.node.uriIsPrivate(uriPriv): - print "Sorry, that's a public URI, we need a private URI" - continue - try: - uriPub = sitemgr.node.invertprivate(uriPriv) - except: - traceback.print_exc() - print "Invalid private URI:\n %s" % uriPriv - continue - break - uriPub = fixUri(uriPub, sitename) - uriPriv = fixUri(uriPriv, sitename) - - # good to go - add the site - sitemgr.addSite(name=sitename, dir=sitedir, uriPub=uriPub, uriPriv=uriPriv) - - print "Added new freesite: '%s' => %s" % (sitename, sitedir) - -#@-node:addSite -#@+node:removeSite -def removeSite(sitemgr, sitename): - """ - tries to remove site from config - """ - if not sitemgr.hasSite(sitename): - print "No such freesite '%s'" % sitename - return - - if getyesno("Are you sure you wish to delete freesite '%s'" % sitename, False): - sitemgr.removeSite(sitename) - print "Removed freesite '%s'" % sitename - -#@-node:removeSite -#@+node:cancelUpdate -def cancelUpdate(sitemgr, sitename, force=False): - """ - tries to remove site from config - """ - if not sitemgr.hasSite(sitename): - print "No such freesite '%s'" % sitename - return - - doit = False - if force: - doit = True - elif getyesno("Are you sure you wish to cancel update for freesite '%s'" \ - % sitename, False): - doit = True - if doit: - sitemgr.cancelUpdate(sitename) - print "Cancelled update for freesite '%s'" % sitename - else: - print "Not cancelling update for freesite '%s'" % sitename - -#@-node:cancelUpdate -#@+node:getChkCalcNode -def getChkCalcNode(addr): - """ - yuck - using a separate node for chk calculation - """ - parts = addr.split(":") - nparts = len(parts) - if nparts == 1: - chkHost = addr - chkPort = fcp.node.defaultFCPPort - elif nparts == 2: - chkHost = parts[0] or fcp.node.defaultFCPHost - chkPort = parts[1] or fcp.node.defaultFCPPort - - try: - chkNode = fcp.node.FCPNode(host=chkHost, port=chkPort) - return chkNode - except: - return None - -#@-node:getChkCalcNode -#@+node:getYesNo -def getyesno(ques, default=False): - """ - prompt for yes/no answer, with default - """ - if default: - prmt = "[Y/n]" - else: - prmt = "[y/N]" - - resp = raw_input(ques + " " + prmt + " ").strip().lower() - - if not resp: - return default - #elif resp[0] in ['y', 't']: - elif resp[0] == 'y': - return True - else: - return False -#@-node:getYesNo -#@+node:help -def help(): - """ - dump help info and exit - """ - print "%s: a console-based USK freesite insertion utility" % progname - - print "Usage: %s [options] " % progname - print "Options:" - print " -h, --help" - print " - display this help message" - print " -c, --config-dir=path" - print " - use different config directory (default is %s)" % confDir - print " -v, --verbose" - print " - run verbosely, set this twice for even more noise" - print " -q, --quiet" - print " - run quietly" - print " -l, --logfile=filename" - print " - location of logfile (default %s)" % logFile - print " -r, --priority" - print " Set the priority (0 highest, 6 lowest, default 4)" - print " of 'forever', so the insert will resume if the node crashes" - print " -C, --cron" - print " Set options suitable for putting freesitemgr in your crontab," - print " and output a dated header with each site insert" - print " --chk-calculation-node=hostname[:port]" - print " Use a different node for CHK calculations, which can be a" - print " timesaver when inserting large amounts of data into a remote node" - print - print "Available Commands:" - print " setup - create/edit freesite config file interactively" - print " add - add new freesite - user will be prompted for" - print " details" - print " list [] - display a summary of all freesites, or a" - print " detailed report of one site if given" - print " listall - print detailed report of all sites" - print " remove - remove given freesite" - print " update [...] - reinsert freesites which have changed since" - print " they were last inserted. If no site names are" - print " given, then all freesites will be updated" - print " cancel ... - cancel any pending insert of freesite(s) ." - print " cleanup ... - clean up node queue for site(s) " - print " help - same as '-h', display this help page" - - sys.exit(0) - -#@-node:help -#@+node:usage -def usage(ret=-1, msg=None): - if msg != None: - print msg - print "Usage: %s [options] []" % progname - print "Do '%s -h' for help" % progname - - sys.exit(ret) - -#@-node:usage -#@+node:noNodeError -def noNodeError(sitemgr, msg): - print msg + ": cannot connect to node FCP port" - print "To use this command, you must have a freenet node running" - print "Please ensure your node FCP port is reachable at %s:%s" % ( - sitemgr.fcpHost, sitemgr.fcpPort) - print "or run '%s setup' to configure a different FCP port" % progname - sys.exit(1) - -#@-node:noNodeError -#@+node:main -def main(): - - force = False - cron = False - chkCalcNode = None - - # default job options - opts = { - "verbosity" : fcp.node.ERROR, - "Verbosity" : 0, - #"logfile" : logFile, - 'priority' : 3, - } - - # process command line switches - try: - cmdopts, args = getopt.getopt( - sys.argv[1:], - "?hvc:l:r:fCV", - ["help", "verbose", "config-dir=", "logfile=", - "max-concurrent=", "force", - "priority", "cron", - "chk-calculation-node=", - "version", - ] - ) - except getopt.GetoptError: - # print help information and exit: - usage() - sys.exit(2) - output = None - verbose = False - #print cmdopts - for o, a in cmdopts: - - if o in ("-?", "-h", "--help"): - help() - sys.exit(0) - - if o in ("-V", "--version"): - print "This is %s, version %s" % (progname, fcp.node.fcpVersion) - sys.exit(0) - - if o in ("-v", "--verbosity"): - opts['verbosity'] += 1 - opts['Verbosity'] = 1023 - - if o in ("-q", "--quiet"): - opts['verbosity'] = fcp.node.SILENT - - if o in ("-c", "--config-dir"): - opts['basedir'] = a - - if o in ("-l", "--logfile"): - opts['logfile'] = a - - if o == '--chk-calculation-node': - chkNode = getChkCalcNode(a) - if not chkNode: - usage("Failed to connect to specified CHK calc node '%s'" % a) - opts['chkCalcNode'] = chkNode - - if o in ("-r", "--priority"): - try: - pri = int(a) - if pri < 0 or pri > 6: - raise hell - except: - usage("Invalid priority '%s'" % pri) - opts['priority'] = int(a) - - if o in ("-f", "--force"): - force = True - - if o in ("-C", "--cron"): - opts['verbosity'] = fcp.node.INFO - opts['Verbosity'] = 1023 - cron = True - - # process command - if len(args) < 1: - usage(msg="No command given") - - cmd = args.pop(0) - - if cmd not in [ - 'setup','config','init', - 'add', - 'remove', - 'list', 'listall', - 'update', - 'cancel', "help", "cleanup", - ]: - usage(msg="Unrecognised command '%s'" % cmd) - - # we now have a likely valid command, so now we need a sitemgr - sitemgr = SiteMgr(**opts) - - if cmd in ['setup', 'init', 'config']: - editCreateConfig(sitemgr) - - elif cmd == 'help': - help() - sys.exit(0) - - elif cmd == 'add': - if not sitemgr.node: - noNodeError(sitemgr, "Cannot add site") - addSite(sitemgr) - - elif cmd == 'remove': - if not args: - print "Remove site: no freesites selected" - return - for sitename in args: - removeSite(sitemgr, sitename) - - elif cmd == 'cancel': - if not args: - print "Cancel site update: no freesites selected" - return - for sitename in args: - cancelUpdate(sitemgr, sitename, force) - - elif cmd == 'cleanup': - sitemgr.cleanup(*args) - - elif cmd in ['list', 'listall']: - if cmd == 'listall': - sites = [site.name for site in sitemgr.sites] - else: - sites = args - if not sites: - # summary list - names = [] - for site in sitemgr.sites: - if site.updateInProgress: - names.append("*"+site.name) - else: - names.append(site.name) - print " ".join(names) - else: - for sitename in sites: - if not sitemgr.hasSite(sitename): - print "No such site '%s'" % sitename - else: - site = sitemgr.getSite(sitename) - if site.updateInProgress: - state = "updating" - else: - state = "idle" - print "%s:" % sitename - print " state: %s" % state - print " dir: %s" % site.dir - print " uri: %s" % site.uriPub - print " privkey: %s" % site.uriPriv - #print " version: %s" % info['version'] - - pass - - elif cmd == 'update': - if not sitemgr.node: - noNodeError(sitemgr, "Cannot update freesites") - try: - if not args: - sites = sitemgr.getSiteNames() - else: - sites = args - sitemgr.insert(cron=cron, *args) - except KeyboardInterrupt: - print "freesitemgr: site inserts cancelled by user" - - try: - sitemgr.node.shutdown() - except: - traceback.print_exc() - try: - sitemgr.node.socket.close() - except: - pass - pass - -#@-node:main -#@+node:mainline -if __name__ == '__main__': - main() - -#@-node:mainline -#@-others -#@-node:freesitemgr-script -#@-others -#@-node:@file freesitemgr.py -#@-leo Property changes on: trunk/apps/pyFreenet/setup.py ___________________________________________________________________ Name: svn:executable + * Property changes on: trunk/apps/pyFreenet/tutorial.py ___________________________________________________________________ Name: svn:executable + * From email at email.com Fri Apr 13 19:22:07 2007 From: email at email.com (accounts-noreply@email.com) Date: Fri, 13 Apr 2007 19:22:07 -0000 Subject: [Pyfreenet] Cancelamento do seu e-mail Message-ID: <200704131802.l3DI2ekJ012461@climate.snu.ac.kr> An HTML attachment was scrubbed... URL: http://emu.freenetproject.org/pipermail/pyfreenet/attachments/20070413/d78b0074/attachment.htm From email at email.com Fri Apr 13 20:13:23 2007 From: email at email.com (accounts-noreply@email.com) Date: Fri, 13 Apr 2007 20:13:23 -0000 Subject: [Pyfreenet] Cancelamento do seu e-mail Message-ID: <200704131820.l3DIKTdm023818@climate.snu.ac.kr> An HTML attachment was scrubbed... URL: http://emu.freenetproject.org/pipermail/pyfreenet/attachments/20070413/78e7f61e/attachment.htm