-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fcploadplugin #14
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
""" | ||
load a freenet plugin | ||
|
||
This is the guts of the command-line front-end app fcploadplugin | ||
""" | ||
|
||
#@+others | ||
#@+node:imports | ||
import argparse | ||
import sys | ||
import traceback | ||
import os.path | ||
from urlparse import urlparse | ||
|
||
from . import node | ||
from .arguments import add_default_arguments | ||
|
||
#@-node:imports | ||
#@+node:globals | ||
|
||
#@-node:globals | ||
#@+node:usage | ||
def create_parser(): | ||
''' | ||
Creates an argparse parser. | ||
''' | ||
parser = argparse.ArgumentParser( | ||
prog='fcploadplugin', | ||
description=''' | ||
A simple command-line freenet load plugin command. | ||
|
||
Loads a plugin to the running node. | ||
''', | ||
) | ||
add_default_arguments(parser) | ||
|
||
parser.add_argument( | ||
'plugin_uri', | ||
help=''' | ||
A URI that points to the plugin location. | ||
''', | ||
) | ||
|
||
return parser | ||
|
||
#@-node:help | ||
#@+node:main | ||
def main(argv=sys.argv[1:]): | ||
""" | ||
Front end for fcploadplugin utility | ||
""" | ||
|
||
# default job options | ||
verbosity = node.ERROR | ||
verbose = False | ||
|
||
parser = create_parser() | ||
args = parser.parse_args(argv) | ||
uri = args.plugin_uri | ||
|
||
keytypes = ["USK", "KSK", "SSK", "CHK"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There isn't a list of these already? |
||
|
||
if os.path.isfile(uri) \ | ||
or os.path.islink(uri) and os.path.isfile(os.path.realpath(uri)): | ||
if uri.endswith(".jar"): | ||
plugin_uri = uri | ||
elif urlparse(uri).scheme != "": | ||
plugin_uri = uri | ||
else: | ||
if not uri.startswith("freenet:"): | ||
uri = "freenet:" + uri | ||
if uri[len("freenet:"):len("freenet:")+3] in keytypes: | ||
plugin_uri = uri | ||
|
||
try: | ||
plugin_uri | ||
except NameError: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems a very strange way to check for validity. Do these bindings really not have some kind of key class that will parse them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is done in the same way at https://github.com/freenet/pyFreenet/blob/master/fcp/upload.py#L203 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay. These utilities could use some cleanup then - I don't see a good reason to parse like that. In addition, such common things should be implemented in the library instead of the included utilities to avoid such a large pressure toward duplicating code. I'm surprised there isn't a FreenetKey class in the library already. Is there a reason to parse this? My understanding is that the leading "freenet:" is unnecessary. There are no decisions made from parsing at this level other than to error out when it's invalid. Would it work to send it to the node without checking it and let the node return any errors? |
||
sys.stderr.write("The given plugin uri is not valid.\n") | ||
sys.exit(1) | ||
|
||
# try to create the node | ||
try: | ||
fcp_node = node.FCPNode(host=args.fcphost, port=args.fcpport, verbosity=verbosity, | ||
logfile=sys.stderr) | ||
except: | ||
if verbose: | ||
traceback.print_exc(file=sys.stderr) | ||
sys.stderr.write("Failed to connect to FCP service at %s:%d\n" % (args.fcphost, args.fcpport)) | ||
sys.exit(2) | ||
|
||
# send the LoadPlugin request | ||
fcp_node.fcpLoadPlugin(plugin_uri) | ||
|
||
fcp_node.shutdown() | ||
|
||
# successful | ||
print "Plugin successfully loaded." | ||
|
||
# all done | ||
sys.exit(0) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -418,6 +418,27 @@ def fcpPluginMessage(self, **kw): | |
params.update({'Param.%s' % str(key) : val}) | ||
|
||
return self._submitCmd(id, "FCPPluginMessage", **params) | ||
|
||
def fcpLoadPlugin(self, plugin_uri, **kw): | ||
""" | ||
Sends an LoadPlugin message | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "LoadPlugin" doesn't start with a vowel sound so "an" should be "a" here. |
||
|
||
Keywords: | ||
- PluginURL - An URI that point to the plugin location | ||
- URLType - Type of plugin source. (currently autodection does not work if | ||
the local file does not exist or type is 'url'), default Attempts autodetect | ||
- Store - If true, the plugin url is written to config, default false | ||
- OfficialSource - Means of obtaining an official plugin: freenet or HTTPS | ||
""" | ||
|
||
id = kw.pop("id", None) | ||
if not id: | ||
id = self._getUniqueId() | ||
|
||
params = dict(Identifier = id, | ||
PluginURL = plugin_uri) | ||
|
||
return self._submitCmd(id, "LoadPlugin", **params) | ||
|
||
#@+node:get | ||
def get(self, uri, **kw): | ||
|
@@ -2409,6 +2430,15 @@ def _on_rxMsg(self, msg): | |
job.callback('successful', job.msgs) | ||
job._putResult(job.msgs) | ||
return | ||
|
||
# ----------------------------- | ||
# handle LoadPlugin replies | ||
|
||
if hdr == 'PluginInfo': | ||
job._appendMsg(msg) | ||
job.callback('successful', job.msgs) | ||
job._putResult(job.msgs) | ||
return | ||
|
||
# ----------------------------- | ||
# handle peer management messages | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env python2 | ||
import fcp | ||
fcp.loadplugin.main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be good to clarify that this can either be a path in the filesystem (looks assumed to be the same as the node's) or a Freenet key.
EDIT: it looks like this would work for things like "official:WebOfTrust" too?