summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xpyLoadCli.py120
-rw-r--r--pyLoadCore.py40
2 files changed, 118 insertions, 42 deletions
diff --git a/pyLoadCli.py b/pyLoadCli.py
index 1d7a05155..69f7b22ab 100755
--- a/pyLoadCli.py
+++ b/pyLoadCli.py
@@ -17,13 +17,16 @@
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
###
+from getopt import GetoptError
+from getopt import getopt
+import gettext
import os
import os.path
-import gettext
from os.path import abspath
from os.path import dirname
from os.path import join
import sys
+from sys import exit
import threading
import time
from time import sleep
@@ -430,6 +433,29 @@ def mag(string):
def white(string):
return "\033[1;37m" + string + "\033[0m"
+def print_help():
+ print ""
+ print "pyloadCli Copyright (c) 2008-2010 the pyLoad Team"
+ print ""
+ print "Usage: [python] pyLoadCli.py [options] [server url]"
+ print ""
+ print "<server url>"
+ print "The server url has this format: http://username:passwort@adress:port"
+ print ""
+ print "<Options>"
+ print " -l, --local", " " * 6, "Use the local settings in config file"
+ print " -u, --username=<username>"
+ print " " * 20, "Specify username"
+ print ""
+ print " -a, --address=<adress>"
+ print " " * 20, "Specify adress (default=127.0.0.1)"
+ print ""
+ print " -p, --port", " " * 7, "Specify port (default=7272)"
+ print " -s, --ssl", " " * 8, "Enable ssl (default=off)"
+ print " -h, --help", " " * 7, "Display this help screen"
+ print ""
+
+
if __name__ == "__main__":
xmlconfig = XMLConfigParser(join(abspath(dirname(__file__)), "module", "config", "core.xml"))
@@ -438,40 +464,70 @@ if __name__ == "__main__":
translation = gettext.translation("pyLoadCli", join(abspath(dirname(__file__)), "locale"), languages=[config['general']['language']])
translation.install(unicode=(True if sys.stdout.encoding.lower().startswith("utf") else False))
+ server_url = ""
+ username = ""
+ password = ""
+ addr = ""
+ port = ""
+ ssl = None
+
if len(sys.argv) > 1:
-
- shortOptions = 'l'
- longOptions = ['local']
- opts, extraparams = __import__("getopt").getopt(sys.argv[1:], shortOptions, longOptions)
- for option, params in opts:
- if option in ("-l", "--local"):
-
- ssl = ""
- if config['ssl']['activated']:
- ssl = "s"
-
- server_url = "http%s://%s:%s@%s:%s/" % (
- ssl,
- config['remote']['username'],
- config['remote']['password'],
- config['remote']['listenaddr'],
- config['remote']['port']
- )
+
+ addr = "127.0.0.1"
+ port = "7272"
+ ssl = ""
+
+ shortOptions = 'lu:a:p:s:h'
+ longOptions = ['local', "username=", "adress=", "port=", "ssl=", "help"]
+
+ try:
+ opts, extraparams = getopt(sys.argv[1:], shortOptions, longOptions)
+ for option, params in opts:
+ if option in ("-l", "--local"):
+
+ if config['ssl']['activated']:
+ ssl = "s"
+
+ username = config['remote']['username']
+ password = config['remote']['password']
+ addr = config['remote']['listenaddr']
+ port = config['remote']['port']
+ if option in ("-u", "--username"):
+ username = params
+ if option in ("-a", "--adress"):
+ addr = params
+ if option in ("-p", "--port"):
+ port = params
+ if option in ("-s", "--ssl"):
+ if params.lower() == "true":
+ ssl = "s"
+ if option in ("-h", "--help"):
+ print_help()
+ exit()
+ except GetoptError:
+ print 'Unknown Argument(s) "%s"' % " ".join(sys.argv[1:])
+ print_help()
+ exit()
+
if len(extraparams) == 1:
server_url = sys.argv[1]
- else:
- username = raw_input(_("Username: "))
- address = raw_input(_("Adress: "))
- ssl = raw_input(_("Use SSL? ([y]/n): "))
- if ssl == "y" or ssl == "":
- ssl = "s"
- else:
- ssl = ""
- port = raw_input(_("Port: "))
- from getpass import getpass
- password = getpass(_("Password: "))
-
- server_url = "http%s://%s:%s@%s:%s/" % (ssl, username, password, address, port)
+
+ if not server_url:
+ if not username: username = raw_input(_("Username: "))
+ if not addr: addr = raw_input(_("Adress: "))
+ if ssl == None:
+ ssl = raw_input(_("Use SSL? ([y]/n): "))
+ if ssl == "y" or ssl == "":
+ ssl = "s"
+ else:
+ ssl = ""
+ if not port: port = raw_input(_("Port: "))
+ if not password:
+ from getpass import getpass
+ password = getpass(_("Password: "))
+
+ server_url = "http%s://%s:%s@%s:%s/" % (ssl, username, password, addr, port)
+
#print server_url
cli = pyLoadCli(server_url)
diff --git a/pyLoadCore.py b/pyLoadCore.py
index 9501631f8..7bd42c906 100644
--- a/pyLoadCore.py
+++ b/pyLoadCore.py
@@ -22,6 +22,7 @@
"""
CURRENT_VERSION = '0.3.2'
+from getopt import GetoptError
from getopt import getopt
import gettext
from glob import glob
@@ -42,10 +43,10 @@ from os.path import isabs
from os.path import join
from re import sub
import subprocess
+import sys
from sys import argv
from sys import executable
from sys import exit
-import sys
from sys import path
from sys import stdout
from sys import version_info
@@ -73,21 +74,40 @@ class Core(object):
self.arg_links = []
if len(argv) > 1:
try:
- options, arguments = getopt(argv[1:], 'vcl:d')
+ options, args = getopt(argv[1:], 'vca:hd', ["version", "clear", "add=", "help", "debug"])
for option, argument in options:
- if option == "-v":
+ if option in ("-v", "--version"):
print "pyLoad", CURRENT_VERSION
exit()
- elif option == "-c":
+ elif option in ("-c", "--clear"):
remove(join("module", "links.pkl"))
print "Removed Linklist"
- elif option == "-l":
+ elif option in ("-a", "--add"):
self.arg_links.append(argument)
print "Added %s" % argument
- elif option == "-d":
+ elif option in ("-h", "--help"):
+ self.print_help()
+ exit()
+ elif option in ("-d", "--debug"):
self.doDebug = True
- except:
+ except GetoptError:
print 'Unknown Argument(s) "%s"' % " ".join(argv[1:])
+ self.print_help()
+ exit()
+
+ def print_help(self):
+ print ""
+ print "pyload %s Copyright (c) 2008-2010 the pyLoad Team" % CURRENT_VERSION
+ print ""
+ print "Usage: [python] pyLoadCore.py [options]"
+ print ""
+ print "<Options>"
+ print " -v, --version", " " * 4, "Print version to terminal"
+ print " -c, --clear", " " * 6, "Delete the saved linklist"
+ print " -a, --add=<list>", " " * 1, "Add the specified links"
+ print " -d, --debug", " " * 6, "Enable debug mode"
+ print " -h, --help", " " * 7, "Display this help screen"
+ print ""
def toggle_pause(self):
if self.thread_list.pause:
@@ -354,7 +374,7 @@ class Core(object):
def check_update(self):
try:
if self.config['updates']['search_updates']:
- version_check = Request().load("http://get.pyload.org/check/%s/" % (CURRENT_VERSION, ))
+ version_check = Request().load("http://get.pyload.org/check/%s/" % (CURRENT_VERSION,))
if version_check == "":
self.logger.info(_("No Updates for pyLoad"))
return False
@@ -372,9 +392,9 @@ class Core(object):
try:
if self.config['updates']['search_updates']:
if self.core.config['updates']['install_updates']:
- version_check = Request().load("http://get.pyload.org/get/update/%s/" % (CURRENT_VERSION, ))
+ version_check = Request().load("http://get.pyload.org/get/update/%s/" % (CURRENT_VERSION,))
else:
- version_check = Request().load("http://get.pyload.org/check/%s/" % (CURRENT_VERSION, ))
+ version_check = Request().load("http://get.pyload.org/check/%s/" % (CURRENT_VERSION,))
if version_check == "":
return False
else: