add CLI downloader

This commit is contained in:
Christopher Roy Bratusek 2012-11-19 23:00:16 +01:00
parent 636c441cdb
commit 7cf09f792c
2 changed files with 106 additions and 11 deletions

View File

@ -327,6 +327,18 @@ class Unpacking(Thread):
self.qobject.emit(SIGNAL("Exception"),e)
self.qobject.emit(SIGNAL("Done"))
class UnpackingCLI(Thread):
def __init__(self, wadpath, dirpath):
Thread.__init__(self)
self.wadpath = wadpath
self.dirpath = dirpath
def run(self):
try:
WAD.loadFile(self.wadpath).dumpDir(self.dirpath)
except Exception, e:
print e
print "Done"
class Packing(Unpacking):
def __init__(self, dirpath, wadpath, QMW, deletedir = False):
Unpacking.__init__(self, wadpath, dirpath, QMW)
@ -350,6 +362,25 @@ class Packing(Unpacking):
self.qobject.emit(SIGNAL("Exception"),e)
self.qobject.emit(SIGNAL("Done"))
class PackingCLI(UnpackingCLI):
def __init__(self, dirpath, wadpath, deletedir = False):
UnpackingCLI.__init__(self, wadpath, dirpath)
self.deletedir = deletedir
def run(self):
try:
print self.dirpath
print self.wadpath
WAD.loadDir(self.dirpath).dumpFile(self.wadpath)
if self.deletedir:
print "Cleaning temporary files"
rmtree(self.dirpath)
except Exception, e:
if self.deletedir:
print "Cleaning temporary files"
rmtree(self.dirpath)
print e
print "Done"
class nusDownloading(Unpacking):
def __init__(self, titleid, version, outputdir, decrypt, QMW):
Unpacking.__init__(self, None, outputdir, QMW)
@ -376,6 +407,29 @@ class nusDownloading(Unpacking):
self.qobject.emit(SIGNAL("Exception"),Errormsg)
self.qobject.emit(SIGNAL("Done"))
class nusDownloadingCLI(UnpackingCLI):
def __init__(self, titleid, version, outputdir, decrypt, pack):
UnpackingCLI.__init__(self, None, outputdir)
if version != None:
self.version = int(version)
else:
self.version = None
self.decrypt = decrypt
self.titleid = titleid
self.pack = pack
self.outputdir = outputdir
def run(self):
try:
if self.pack:
self.dirpath = tempfile.gettempdir() + "/NUS_"+ str(time.time()).replace(".","")
NUS(self.titleid, self.version).download(self.dirpath, decrypt = False)
self.packing = PackingCLI(self.dirpath, str(self.outputdir), True)
self.packing.start()
else:
NUS(self.titleid,self.version).download(self.dirpath, decrypt = self.decrypt)
except Exception, e:
print e
#Statusbar messages
#FIXME: Why don't they get translated? It's frustrating
DOWNLOADING = QT_TR_NOOP("Downloading files from NUS... This may take a while, please, be patient.")

View File

@ -1,25 +1,64 @@
#!/usr/bin/env python
#coding=utf-8
import sys
import optparse
from optparse import OptionParser
from optparse import Option, OptionValueError
from PyQt4.QtGui import QApplication
from PyQt4.QtCore import QTranslator, QString, QLocale
from GUI.VenPri import MWQwad
from GUI.VenPri import nusDownloadingCLI
from TitleIDs import TitleDict
parser = optparse.OptionParser("qwad <option> [value]\
\n\nQwad (c) 2012 Christopher Roy Bratusek\
\nLicensed under the GNU GENERAL PUBLIC LICENSE v3")
class MultipleOption(Option):
ACTIONS = Option.ACTIONS + ("extend",)
STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",)
TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",)
ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",)
def take_action(self, action, dest, opt, value, values, parser):
if action == "extend":
values.ensure_value(dest, []).append(value)
else:
Option.take_action(self, action, dest, opt, value, values, parser)
VERSION = '0.6'
def main():
description = """NUS-Downloader, WadManager for Linux"""
parser = OptionParser(option_class=MultipleOption,
usage='usage: qwad [OPTIONS] ARGUMENT',
description=description)
parser.add_option('-d', '--downloads',
action="extend", type="string",
dest='download',
metavar='Arguments',
help='IOS Version OutPut DeCrypt')
parser.add_option("-v", "--version", dest="version",
action="store_true", default=False, help="print version and exit")
(options, args) = parser.parse_args()
#if len(sys.argv) == 1:
# parser.parse_args(['--help'])
options, args = parser.parse_args()
if options.version:
print "0.6"
print "%s" % VERSION
sys.exit(0)
if __name__ == "__main__":
if options.download:
if "IOS" in str(args[0]):
xarg = TitleDict[str(args[0])]
print "%s" % xarg
print "%d" % int(str(xarg).lower(),16)
nusdow = nusDownloadingCLI(int(str(xarg).lower(),16), args[1], args[2], args[3], args[4])
else:
print "%s" % args[0]
print "%d" % int(str(args[0]).lower(),16)
nusdow = nusDownloadingCLI(int(str(args[0]).lower(),16), args[1], args[2], args[3], args[4])
nusdow.start()
sys.exit(0)
os.chdir(os.getenv("HOME"))
translator = QTranslator()
translator.load(QString("i18n/Qwad_%1").arg(QLocale.system().name()))
qttranslator = QTranslator()
@ -33,3 +72,5 @@ if __name__ == "__main__":
VentanaP.show()
sys.exit(Vapp.exec_())
if __name__ == "__main__":
main()