Author: aum
Date: 2006-06-04 08:10:02 +0000 (Sun, 04 Jun 2006)
New Revision: 9041
Modified:
trunk/apps/pyFreenet/code.leo
trunk/apps/pyFreenet/fcpget
trunk/apps/pyFreenet/fcpget.py
trunk/apps/pyFreenet/fcpput
trunk/apps/pyFreenet/fcpput.py
trunk/apps/pyFreenet/freedisk.py
Log:
Added persistence support to fcpget/fcpput
Modified: trunk/apps/pyFreenet/code.leo
===================================================================
--- trunk/apps/pyFreenet/code.leo 2006-06-04 08:00:16 UTC (rev 9040)
+++ trunk/apps/pyFreenet/code.leo 2006-06-04 08:10:02 UTC (rev 9041)
@@ -300,7 +300,7 @@
<v t="aum.20060521131205"><vh>globals</vh></v>
<v t="aum.20060521131205.1"><vh>usage</vh></v>
<v t="aum.20060521131205.2"><vh>help</vh></v>
-<v t="aum.20060521111727.2"><vh>main</vh></v>
+<v t="aum.20060521111727.2" a="V"><vh>main</vh></v>
<v t="aum.20060521111727.3"><vh>mainline</vh></v>
</v>
</v>
@@ -321,7 +321,7 @@
<v t="aum.20060521134737.1"><vh>imports</vh></v>
<v t="aum.20060521134737.2"><vh>globals</vh></v>
<v t="aum.20060521134737.3"><vh>usage</vh></v>
-<v t="aum.20060521134737.4" a="V"><vh>help</vh></v>
+<v t="aum.20060521134737.4"><vh>help</vh></v>
<v t="aum.20060521134737.5"><vh>main</vh></v>
<v t="aum.20060521134737.6"><vh>mainline</vh></v>
</v>
@@ -363,7 +363,7 @@
<v t="aum.20060521163241" a="E"><vh>freedisk</vh>
<v t="aum.20060529191729" tnodeList="aum.20060529191729"><vh>@file
mount.freenetfs</vh></v>
<v t="aum.20060602094531" a="E"><vh>Front ends</vh>
-<v t="aum.20060530170840" a="EO"
tnodeList="aum.20060530170840,aum.20060529123536.1,aum.20060529163723,aum.20060529163723.1,aum.20060603114446,aum.20060604194409,aum.20060604194834,aum.20060603114247,aum.20060530143459.3,aum.20060530143459.4,aum.20060530143459.5,aum.20060530143459.6,aum.20060530143459.7,aum.20060530143459.8,aum.20060530143459.9,aum.20060603164555,aum.20060604144241,aum.20060603121718,aum.20060603125105,aum.20060603121718.1,aum.20060603121848,aum.20060603122324,aum.20060603125848,aum.20060603132557,aum.20060603131227,aum.20060603154804,aum.20060603155318,aum.20060603162815,aum.20060603155642,aum.20060603125405,aum.20060603125405.1,aum.20060529164147,aum.20060529164147.1,aum.20060530160322,aum.20060531160838,aum.20060603100604,aum.20060603100604.1,aum.20060603100604.2,aum.20060604143852,aum.20060603125812,aum.20060603132247,aum.20060529163723.2,aum.20060530142805.1,aum.20060530143459,aum.20060530143459.2,aum.20060529163723.4"><vh>@file
freedisk.py</vh>
+<v t="aum.20060530170840" a="E"
tnodeList="aum.20060530170840,aum.20060529123536.1,aum.20060529163723,aum.20060529163723.1,aum.20060603114446,aum.20060604194409,aum.20060604194834,aum.20060603114247,aum.20060530143459.3,aum.20060530143459.4,aum.20060530143459.5,aum.20060530143459.6,aum.20060530143459.7,aum.20060530143459.8,aum.20060530143459.9,aum.20060603164555,aum.20060604144241,aum.20060603121718,aum.20060603125105,aum.20060603121718.1,aum.20060603121848,aum.20060603122324,aum.20060603125848,aum.20060603132557,aum.20060603131227,aum.20060603154804,aum.20060603155318,aum.20060603162815,aum.20060603155642,aum.20060603125405,aum.20060603125405.1,aum.20060529164147,aum.20060529164147.1,aum.20060530160322,aum.20060531160838,aum.20060603100604,aum.20060603100604.1,aum.20060603100604.2,aum.20060604143852,aum.20060603125812,aum.20060603132247,aum.20060529163723.2,aum.20060530142805.1,aum.20060530143459,aum.20060604200719,aum.20060529163723.4"><vh>@file
freedisk.py</vh>
<v t="aum.20060529123536.1" a="E"><vh>freedisk app</vh>
<v t="aum.20060529163723"><vh>imports</vh></v>
<v t="aum.20060529163723.1"><vh>globals</vh></v>
@@ -409,12 +409,12 @@
<v t="aum.20060529163723.2" a="E"><vh>main</vh>
<v t="aum.20060530142805.1"><vh><<set defaults>></vh></v>
<v t="aum.20060530143459"><vh><<process args>></vh></v>
-<v t="aum.20060530143459.2" a="E"><vh><<execute command>></vh></v>
+<v t="aum.20060604200719"><vh><<execute command>></vh></v>
</v>
<v t="aum.20060529163723.4"><vh>mainline</vh></v>
</v>
</v>
-<v t="aum.20060530170840.1" a="O"
tnodeList="aum.20060530170840.1,aum.20060529123536.1,aum.20060529163723,aum.20060529163723.1,aum.20060603114446,aum.20060604194409,aum.20060604194834,aum.20060603114247,aum.20060530143459.3,aum.20060530143459.4,aum.20060530143459.5,aum.20060530143459.6,aum.20060530143459.7,aum.20060530143459.8,aum.20060530143459.9,aum.20060603164555,aum.20060604144241,aum.20060603121718,aum.20060603125105,aum.20060603121718.1,aum.20060603121848,aum.20060603122324,aum.20060603125848,aum.20060603132557,aum.20060603131227,aum.20060603154804,aum.20060603155318,aum.20060603162815,aum.20060603155642,aum.20060603125405,aum.20060603125405.1,aum.20060529164147,aum.20060529164147.1,aum.20060530160322,aum.20060531160838,aum.20060603100604,aum.20060603100604.1,aum.20060603100604.2,aum.20060604143852,aum.20060603125812,aum.20060603132247,aum.20060529163723.2,aum.20060530142805.1,aum.20060530143459,aum.20060530143459.2,aum.20060529163723.4"><vh>@file
freedisk</vh>
+<v t="aum.20060530170840.1"
tnodeList="aum.20060530170840.1,aum.20060529123536.1,aum.20060529163723,aum.20060529163723.1,aum.20060603114446,aum.20060604194409,aum.20060604194834,aum.20060603114247,aum.20060530143459.3,aum.20060530143459.4,aum.20060530143459.5,aum.20060530143459.6,aum.20060530143459.7,aum.20060530143459.8,aum.20060530143459.9,aum.20060603164555,aum.20060604144241,aum.20060603121718,aum.20060603125105,aum.20060603121718.1,aum.20060603121848,aum.20060603122324,aum.20060603125848,aum.20060603132557,aum.20060603131227,aum.20060603154804,aum.20060603155318,aum.20060603162815,aum.20060603155642,aum.20060603125405,aum.20060603125405.1,aum.20060529164147,aum.20060529164147.1,aum.20060530160322,aum.20060531160838,aum.20060603100604,aum.20060603100604.1,aum.20060603100604.2,aum.20060604143852,aum.20060603125812,aum.20060603132247,aum.20060529163723.2,aum.20060530142805.1,aum.20060530143459,aum.20060604200719,aum.20060529163723.4"><vh>@file
freedisk</vh>
<v t="aum.20060529123536.1" a="E"><vh>freedisk app</vh>
<v t="aum.20060529163723"><vh>imports</vh></v>
<v t="aum.20060529163723.1"><vh>globals</vh></v>
@@ -460,7 +460,7 @@
<v t="aum.20060529163723.2" a="E"><vh>main</vh>
<v t="aum.20060530142805.1"><vh><<set defaults>></vh></v>
<v t="aum.20060530143459"><vh><<process args>></vh></v>
-<v t="aum.20060530143459.2" a="E"><vh><<execute command>></vh></v>
+<v t="aum.20060604200719"><vh><<execute command>></vh></v>
</v>
<v t="aum.20060529163723.4"><vh>mainline</vh></v>
</v>
@@ -8797,6 +8797,7 @@
opts = {
"Verbosity" : 0,
+ "Persistence" : "connection",
}
# process command line switches
@@ -8804,7 +8805,7 @@
cmdopts, args = getopt.getopt(
sys.argv[1:],
"?hvH:P:g",
- ["help", "verbose", "fcpHost=", "fcpPort=", "global",
+ ["help", "verbose", "fcpHost=", "fcpPort=", "global",
"persistence=",
]
)
except getopt.GetoptError:
@@ -8833,6 +8834,11 @@
except:
usage("Invalid fcpPort argument %s" % repr(a))
+ if o in ("-p", "--persistence"):
+ if a not in ("connection", "reboot", "forever"):
+ usage("Persistence must be one of 'connection', 'reboot',
'forever'")
+ opts['Persistence'] = a
+
if o in ("-g", "--global"):
opts['Global'] = "true"
@@ -8953,6 +8959,8 @@
print " Connect to FCP service at host <hostname>"
print " -P, --fcpPort=<portnum>"
print " Connect to FCP service at port <portnum>"
+ print " -p, --persistence="
+ print " Set the persistence type, one of 'connection', 'reboot' or
'forever'"
print " -g, --global"
print " Do it on the FCP global queue"
print
@@ -9031,6 +9039,8 @@
print " an attempt will be made to guess it from the filename. If no"
print " filename is given, or if this attempt fails, the mimetype"
print " 'text/plain' will be used as a fallback"
+ print " -p, --persistence="
+ print " Set the persistence type, one of 'connection', 'reboot' or
'forever'"
print " -g, --global"
print " Do it on the FCP global queue"
print
@@ -9054,6 +9064,7 @@
opts = {
"Verbosity" : 0,
+ "Persistence" : "connection",
}
# process command line switches
@@ -9062,6 +9073,7 @@
sys.argv[1:],
"?hvH:P:m:g",
["help", "verbose", "fcpHost=", "fcpPort=", "mimetype=", "global",
+ "persistence=",
]
)
except getopt.GetoptError:
@@ -9093,6 +9105,11 @@
if o in ("-m", "--mimetype"):
mimetype = a
+ if o in ("-p", "--persistence"):
+ if a not in ("connection", "reboot", "forever"):
+ usage("Persistence must be one of 'connection', 'reboot',
'forever'")
+ opts['Persistence'] = a
+
if o in ("-g", "--global"):
opts['Global'] = "true"
@@ -11724,16 +11741,10 @@
"""
Front end
"""
- <<global vars>>
-
<<set defaults>>
<<process args>>
- <<get config>>
-
- <<validate args>>
-
<<execute command>>
</t>
@@ -11840,44 +11851,6 @@
opts['multithreaded'] = True
</t>
-<t tx="aum.20060530143459.2"># start a freenetfs mount
-if cmd in ['init', 'setup']:
- <<init>>
-
-elif cmd in ['start', 'mount']:
- <<start>>
-
-elif cmd in ['umount', 'unmount', 'stop']:
- <<stop>>
-
-elif cmd == 'new':
- <<new>>
-
-elif cmd == 'add':
- <<add>>
-
-elif cmd == 'del':
- <<del>>
-
-elif cmd == 'update':
- <<update>>
-
-elif cmd == 'commit':
- <<commit>>
-
-elif cmd == 'list':
- <<list>>
-
-elif cmd == 'cmd':
- <<cmd>>
-
-
-
-
-else:
- usage("Unrecognised command: %s" % cmd)
-
-</t>
<t tx="aum.20060530143459.3">
print "starting freedisk service..."
fs = freenetfs.FreenetFS(
@@ -12868,6 +12841,11 @@
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
+
</t>
<t tx="aum.20060604194834">def execute(self):
"""
@@ -12881,5 +12859,8 @@
return method(*self.args[1:])
</t>
+<t tx="aum.20060604200719">mgr = FreediskMgr(**opts)
+
+</t>
</tnodes>
</leo_file>
Modified: trunk/apps/pyFreenet/fcpget
===================================================================
--- trunk/apps/pyFreenet/fcpget 2006-06-04 08:00:16 UTC (rev 9040)
+++ trunk/apps/pyFreenet/fcpget 2006-06-04 08:10:02 UTC (rev 9041)
@@ -47,6 +47,8 @@
print " Connect to FCP service at host <hostname>"
print " -P, --fcpPort=<portnum>"
print " Connect to FCP service at port <portnum>"
+ print " -p, --persistence="
+ print " Set the persistence type, one of 'connection', 'reboot' or
'forever'"
print " -g, --global"
print " Do it on the FCP global queue"
print
@@ -68,6 +70,7 @@
opts = {
"Verbosity" : 0,
+ "Persistence" : "connection",
}
# process command line switches
@@ -75,7 +78,7 @@
cmdopts, args = getopt.getopt(
sys.argv[1:],
"?hvH:P:g",
- ["help", "verbose", "fcpHost=", "fcpPort=", "global",
+ ["help", "verbose", "fcpHost=", "fcpPort=", "global",
"persistence=",
]
)
except getopt.GetoptError:
@@ -104,6 +107,11 @@
except:
usage("Invalid fcpPort argument %s" % repr(a))
+ if o in ("-p", "--persistence"):
+ if a not in ("connection", "reboot", "forever"):
+ usage("Persistence must be one of 'connection', 'reboot',
'forever'")
+ opts['Persistence'] = a
+
if o in ("-g", "--global"):
opts['Global'] = "true"
Modified: trunk/apps/pyFreenet/fcpget.py
===================================================================
--- trunk/apps/pyFreenet/fcpget.py 2006-06-04 08:00:16 UTC (rev 9040)
+++ trunk/apps/pyFreenet/fcpget.py 2006-06-04 08:10:02 UTC (rev 9041)
@@ -47,6 +47,8 @@
print " Connect to FCP service at host <hostname>"
print " -P, --fcpPort=<portnum>"
print " Connect to FCP service at port <portnum>"
+ print " -p, --persistence="
+ print " Set the persistence type, one of 'connection', 'reboot' or
'forever'"
print " -g, --global"
print " Do it on the FCP global queue"
print
@@ -68,6 +70,7 @@
opts = {
"Verbosity" : 0,
+ "Persistence" : "connection",
}
# process command line switches
@@ -75,7 +78,7 @@
cmdopts, args = getopt.getopt(
sys.argv[1:],
"?hvH:P:g",
- ["help", "verbose", "fcpHost=", "fcpPort=", "global",
+ ["help", "verbose", "fcpHost=", "fcpPort=", "global",
"persistence=",
]
)
except getopt.GetoptError:
@@ -104,6 +107,11 @@
except:
usage("Invalid fcpPort argument %s" % repr(a))
+ if o in ("-p", "--persistence"):
+ if a not in ("connection", "reboot", "forever"):
+ usage("Persistence must be one of 'connection', 'reboot',
'forever'")
+ opts['Persistence'] = a
+
if o in ("-g", "--global"):
opts['Global'] = "true"
Modified: trunk/apps/pyFreenet/fcpput
===================================================================
--- trunk/apps/pyFreenet/fcpput 2006-06-04 08:00:16 UTC (rev 9040)
+++ trunk/apps/pyFreenet/fcpput 2006-06-04 08:10:02 UTC (rev 9041)
@@ -50,6 +50,8 @@
print " an attempt will be made to guess it from the filename. If no"
print " filename is given, or if this attempt fails, the mimetype"
print " 'text/plain' will be used as a fallback"
+ print " -p, --persistence="
+ print " Set the persistence type, one of 'connection', 'reboot' or
'forever'"
print " -g, --global"
print " Do it on the FCP global queue"
print
@@ -72,6 +74,7 @@
opts = {
"Verbosity" : 0,
+ "Persistence" : "connection",
}
# process command line switches
@@ -80,6 +83,7 @@
sys.argv[1:],
"?hvH:P:m:g",
["help", "verbose", "fcpHost=", "fcpPort=", "mimetype=", "global",
+ "persistence=",
]
)
except getopt.GetoptError:
@@ -111,6 +115,11 @@
if o in ("-m", "--mimetype"):
mimetype = a
+ if o in ("-p", "--persistence"):
+ if a not in ("connection", "reboot", "forever"):
+ usage("Persistence must be one of 'connection', 'reboot',
'forever'")
+ opts['Persistence'] = a
+
if o in ("-g", "--global"):
opts['Global'] = "true"
Modified: trunk/apps/pyFreenet/fcpput.py
===================================================================
--- trunk/apps/pyFreenet/fcpput.py 2006-06-04 08:00:16 UTC (rev 9040)
+++ trunk/apps/pyFreenet/fcpput.py 2006-06-04 08:10:02 UTC (rev 9041)
@@ -50,6 +50,8 @@
print " an attempt will be made to guess it from the filename. If no"
print " filename is given, or if this attempt fails, the mimetype"
print " 'text/plain' will be used as a fallback"
+ print " -p, --persistence="
+ print " Set the persistence type, one of 'connection', 'reboot' or
'forever'"
print " -g, --global"
print " Do it on the FCP global queue"
print
@@ -72,6 +74,7 @@
opts = {
"Verbosity" : 0,
+ "Persistence" : "connection",
}
# process command line switches
@@ -80,6 +83,7 @@
sys.argv[1:],
"?hvH:P:m:g",
["help", "verbose", "fcpHost=", "fcpPort=", "mimetype=", "global",
+ "persistence=",
]
)
except getopt.GetoptError:
@@ -111,6 +115,11 @@
if o in ("-m", "--mimetype"):
mimetype = a
+ if o in ("-p", "--persistence"):
+ if a not in ("connection", "reboot", "forever"):
+ usage("Persistence must be one of 'connection', 'reboot',
'forever'")
+ opts['Persistence'] = a
+
if o in ("-g", "--global"):
opts['Global'] = "true"
Modified: trunk/apps/pyFreenet/freedisk.py
===================================================================
--- trunk/apps/pyFreenet/freedisk.py 2006-06-04 08:00:16 UTC (rev 9040)
+++ trunk/apps/pyFreenet/freedisk.py 2006-06-04 08:10:02 UTC (rev 9041)
@@ -58,6 +58,296 @@
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 <freediskname>" % 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:execute
+ def execute(self):
+ """
+ Executes the given command
+ """
+ cmd = self.cmd
+ method = getattr(self, "cmd_"+cmd, None)
+ if not method:
+ usage("Unrecognised command '%s'" % cmd)
+
+ return method(*self.args[1:])
+
+ #@-node:execute
+ #@+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
+
+ print "starting freedisk service..."
+ fs = freenetfs.FreenetFS(
+ conf.mountpoint,
+ fcpHost=conf.fcpHost,
+ fcpPort=conf.fcpPort,
+ verbosity=conf.fcpVerbosity,
+ debug=debug,
+ multithreaded=multithreaded,
+ )
+
+ # spawn a process to run it
+ if os.fork() == 0:
+ print "Mounting freenet fs at %s" % conf.mountpoint
+ fs.run()
+ else:
+ # parent process
+ 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:
+
+ 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)
+
+ # 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)
+
+ #@-node:cmd_start
+ #@+node:cmd_stop
+ os.system("umount %s" % conf.mountpoint)
+
+ #@-node:cmd_stop
+ #@+node:cmd_new
+ #print "new: %s: NOT IMPLEMENTED" % diskname
+
+ 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]
+
+ # 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(pubKeyPath, "w").write(pubKey)
+ file(privKeyPath, "w").write(privKey)
+ file(passwdPath, "w").write(passwd)
+
+ # and, of course, update config
+ conf.addDisk(diskname, pubKey, privKey, passwd)
+
+ #@-node:cmd_new
+ #@+node:cmd_add
+ # get uri
+ if nargs < 3:
+ usage("add: Missing URI")
+ uri = args[2]
+
+ #print "add: %s: NOT IMPLEMENTED" % diskname
+
+ # barf if a freedisk of that name is already mounted
+ if os.path.exists(diskPath):
+ usage("Freedisk %s seems to be already mounted" % diskname)
+
+ # 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)
+
+ # set the keys
+
+ if fcp.node.uriIsPrivate(uri):
+ path = privKeyPath
+ else:
+ path = pubKeyPath
+ f = file(path, "w")
+ f.write(uri)
+ f.flush()
+ f.close()
+
+ #@-node:cmd_add
+ #@+node:cmd_del
+ disk = conf.getDisk(diskname)
+
+ if not isinstance(disk, XMLNode):
+ usage("No such disk '%s'" % diskname)
+
+ conf.delDisk(diskname)
+
+ path = os.path.join(conf.mountpoint, "usr", diskname)
+ os.rmdir(path)
+
+ #@-node:cmd_del
+ #@+node:cmd_update
+ print "update: %s: NOT IMPLEMENTED" % diskname
+
+ f = file(cmdPath, "w")
+ f.write("update")
+ f.flush()
+ f.close()
+
+ #@-node:cmd_update
+ #@+node:cmd_commit
+ 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()
+
+ 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 = " ".join(args)
+ print repr(doFsCommand(cmd))
+
+ #@-node:cmd_cmd
#@-others
#@-node:class FreediskMgr
@@ -406,21 +696,17 @@
"""
Front end
"""
- #@ <<global vars>>
- #@+node:<<global vars>>
- # some globals
-
- global Verbosity, verbose, configFile, conf
-
- #@-node:<<global vars>>
- #@nl
-
#@ <<set defaults>>
#@+node:<<set defaults>>
# create defaults
- debug = False
- multithreaded = False
+ opts = {
+ 'debug' : False,
+ 'multithreaded' : False,
+ 'configFile' : configFile,
+ 'verbosity' : fcp.ERROR,
+ 'Verbosity' : 1023,
+ }
#@-node:<<set defaults>>
#@nl
@@ -442,8 +728,6 @@
# print help information and exit:
usage()
sys.exit(2)
- output = None
- verbose = False
#print cmdopts
for o, a in cmdopts:
@@ -452,345 +736,26 @@
help()
if o in ("-v", "--verbose"):
- verbosity = fcp.node.DETAIL
+ opts['verbosity'] = fcp.node.DETAIL
opts['Verbosity'] = 1023
verbose = True
if o in ("-c", "--config"):
- configFile = a
+ opts['configFile'] = a
if o in ("-d", "--debug"):
- debug = True
+ opts['debug'] = True
if o in ("-m", "--multithreaded"):
- multithreaded = True
+ opts['multithreaded'] = True
#@-node:<<process args>>
#@nl
- #@ <<get config>>
- #@+node:<<get config>>
- # load config, if any
-
- #print "loading freedisk config"
-
- conf = FreediskConfig(configFile)
-
- #ipython(conf)
-
- #@-node:<<get config>>
- #@nl
-
- #@ <<validate args>>
- #@+node:<<validate args>>
- # validate args
-
- nargs = len(args)
- if nargs == 0:
- usage("No command given")
-
- 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 <freediskname>" % cmd)
- diskname = args[1]
-
- # get paths to freedisk dir and pseudo-files
- diskPath = os.path.join(conf.mountpoint, "usr", diskname)
- pubKeyPath = os.path.join(diskPath, ".publickey")
- privKeyPath = os.path.join(diskPath, ".privatekey")
- passwdPath = os.path.join(diskPath, ".passwd")
- cmdPath = os.path.join(diskPath, ".cmd")
- statusPath = os.path.join(diskPath, ".status")
-
- #@-node:<<validate args>>
- #@nl
-
#@ <<execute command>>
#@+node:<<execute command>>
- # start a freenetfs mount
- if cmd in ['init', 'setup']:
- #@ <<init>>
- #@+node:<<init>>
- # initialise/change freedisk config
-
- print "Freedisk configuration"
- print
- print "Your freedisk config will normally be stored in the file:"
- print " %s" % 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:<<init>>
- #@nl
+ mgr = FreediskMgr(**opts)
- elif cmd in ['start', 'mount']:
- #@ <<start>>
- #@+node:<<start>>
- print "starting freedisk service..."
- fs = freenetfs.FreenetFS(
- conf.mountpoint,
- fcpHost=conf.fcpHost,
- fcpPort=conf.fcpPort,
- verbosity=conf.fcpVerbosity,
- debug=debug,
- multithreaded=multithreaded,
- )
-
- # spawn a process to run it
- if os.fork() == 0:
- print "Mounting freenet fs at %s" % conf.mountpoint
- fs.run()
- else:
- # parent process
- 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:
-
- 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)
-
- # 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)
-
- #@-node:<<start>>
- #@nl
-
- elif cmd in ['umount', 'unmount', 'stop']:
- #@ <<stop>>
- #@+node:<<stop>>
- os.system("umount %s" % conf.mountpoint)
-
- #@-node:<<stop>>
- #@nl
-
- elif cmd == 'new':
- #@ <<new>>
- #@+node:<<new>>
- #print "new: %s: NOT IMPLEMENTED" % diskname
-
- 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]
-
- # 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(pubKeyPath, "w").write(pubKey)
- file(privKeyPath, "w").write(privKey)
- file(passwdPath, "w").write(passwd)
-
- # and, of course, update config
- conf.addDisk(diskname, pubKey, privKey, passwd)
-
- #@-node:<<new>>
- #@nl
-
- elif cmd == 'add':
- #@ <<add>>
- #@+node:<<add>>
- # get uri
- if nargs < 3:
- usage("add: Missing URI")
- uri = args[2]
-
- #print "add: %s: NOT IMPLEMENTED" % diskname
-
- # barf if a freedisk of that name is already mounted
- if os.path.exists(diskPath):
- usage("Freedisk %s seems to be already mounted" % diskname)
-
- # 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)
-
- # set the keys
-
- if fcp.node.uriIsPrivate(uri):
- path = privKeyPath
- else:
- path = pubKeyPath
- f = file(path, "w")
- f.write(uri)
- f.flush()
- f.close()
-
- #@-node:<<add>>
- #@nl
-
- elif cmd == 'del':
- #@ <<del>>
- #@+node:<<del>>
- disk = conf.getDisk(diskname)
-
- if not isinstance(disk, XMLNode):
- usage("No such disk '%s'" % diskname)
-
- conf.delDisk(diskname)
-
- path = os.path.join(conf.mountpoint, "usr", diskname)
- os.rmdir(path)
-
- #@-node:<<del>>
- #@nl
-
- elif cmd == 'update':
- #@ <<update>>
- #@+node:<<update>>
- print "update: %s: NOT IMPLEMENTED" % diskname
-
- f = file(cmdPath, "w")
- f.write("update")
- f.flush()
- f.close()
-
- #@-node:<<update>>
- #@nl
-
- elif cmd == 'commit':
- #@ <<commit>>
- #@+node:<<commit>>
- print "commit: %s: launching.." % diskname
-
- f = file(cmdPath, "w")
- f.write("commit")
- f.flush()
- f.close()
-
- #@-node:<<commit>>
- #@nl
-
- elif cmd == 'list':
- #@ <<list>>
- #@+node:<<list>>
- 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:<<list>>
- #@nl
-
- elif cmd == 'cmd':
- #@ <<cmd>>
- #@+node:<<cmd>>
- # arbitrary command, for testing
-
- cmd = " ".join(args[1:])
-
- print repr(doFsCommand(cmd))
-
- #@-node:<<cmd>>
- #@nl
-
-
-
-
- else:
- usage("Unrecognised command: %s" % cmd)
-
#@-node:<<execute command>>
#@nl