Skip to content

Instantly share code, notes, and snippets.

@jnns
Last active December 15, 2015 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnns/5308837 to your computer and use it in GitHub Desktop.
Save jnns/5308837 to your computer and use it in GitHub Desktop.
Decrypts a TVA result folder.
#!/usr/bin/env python
#! -*- coding: utf-8 -*-
__license__ = "GPL"
__version__ = "1.0"
import os
import re
import shutil
CWD = os.getcwd()
def get_recordfile_name(file):
return file[1:-1] + ".tvr"
def read_name_from_record(file):
record = open(os.path.join(CWD, file, get_recordfile_name(file)), "r")
WORDCHARS = re.compile("\w+")
name = "".join((record.readlines()[:2]))
return "".join(WORDCHARS.findall(name)).lower()
def rename_folder_and_files(file):
src = os.path.join(CWD, file)
dst = os.path.join(CWD, "decrypted", read_name_from_record(file))
try:
shutil.copytree(src, dst)
except Exception as e:
print e
for f in os.listdir(dst):
print f
m = re.search("^(\w+)([\.\w]+)$", f)
try:
os.rename(os.path.join(dst, f), os.path.join(dst,
read_name_from_record(file) + m.group(2)))
except AttributeError:
print "Error occurred while renaming %s" % f
def main():
files = [f for f in os.listdir(CWD) if f[0] == "{"]
for file in files:
try:
if "{%s}" % file is not read_name_from_record(file):
print "Renaming: %s" % file
rename_folder_and_files(file)
else:
print "Already renamed: %" % file
except IOError:
print "No record file for %s" % file
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment