Skip to content

Instantly share code, notes, and snippets.

@mahan
Last active November 17, 2015 08:52
Show Gist options
  • Save mahan/b3fbaa2770c448e98536 to your computer and use it in GitHub Desktop.
Save mahan/b3fbaa2770c448e98536 to your computer and use it in GitHub Desktop.
inpath = r"C:\develop\taric_work\taric_XML_v2\tot"
midpath = inpath + r".uncrypt"
outpath = inpath + r".unpack"
from os import listdir, path, makedirs, remove, rename
from os.path import isfile, join
from subprocess import call
def createDirIfNotExists(directory):
if not path.exists(directory):
makedirs(directory)
def main():
createDirIfNotExists(midpath)
createDirIfNotExists(outpath)
files_to_unpack = [ f for f in listdir(inpath) if isfile(join(inpath,f)) ]
for f in files_to_unpack:
gpgCmdLine = "gpg2 --batch --yes --output \"{2}\{1}\" \"{3}\{0}\"".format(f, path.splitext(f)[0], midpath, inpath)
print("gpgCmdLine: " + gpgCmdLine)
call(gpgCmdLine, shell=True)
f = path.splitext(f)[0]
z7cmdline = "\"C:\Program Files\\7-Zip\\7z.exe\" x -aoa -o" + outpath + " " + midpath + "\\" + f
print("z7cmdline: " + z7cmdline)
call(z7cmdline, shell=True)
#call([r"C:\Program Files\7-Zip\7z.exe", "x", "-aoa","-o{}".format(outpath), "{}\{}".format(midpath, f)], shell=True)
f = path.splitext(f)[0]
targetFile = "{}.xml".format(path.splitext(f)[0])
print("remove " + outpath + '\\' + targetFile)
if path.exists(outpath + '\\' + targetFile):
remove(outpath + '\\' + targetFile) #Remove targetfile if it's in the way
print("rename")
rename("{}\krypt.xml".format(outpath), outpath + '\\' + targetFile)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment