我发现有关 Verity 数据库结构的这些信息非常有用.ddd 文件 - Verity Documentum?
现在我想将旧的 Verity 数据库迁移到新的应用程序,因此我想将所有内容转储到文本文件中,并使用一个小工具对其进行解析。不幸的是,使用 browser.exe 我似乎一次只能看到一个条目,有没有办法一次性将所有内容转储到标准输出?
答案1
我找到了一个解决方案。它不是最好的,但至少是有用的:
import argparse
import json
import os
import re
import subprocess
parser = argparse.ArgumentParser(description='Dump MTL Verity ddd file into a text file')
parser.add_argument('input', metavar='DDD-FILE', nargs='+', help='MTL ddd input files')
parser.add_argument('-o','--output', metavar='JSON-FILE', help='JSON output file', required=True)
parser.add_argument('--browse-tool', metavar='TOOL', help='The browse tool to use', default='browse.exe')
args = parser.parse_args()
reNumEntries = re.compile('.*There are \(([0-9]+)\) entries in the field \(VdkVgwKey\).*')
reEntry = re.compile('[0-9]+ ([A-Za-z_0-9]+)[^=]+= (.*)')
reBadName = re.compile('.*_(IX|MI|MX|OF|SZ)')
reBadValue = re.compile('\(only [0-9]+ records\)')
def dump_ddd(ddd_file):
print('Dumping file {}'.format(ddd_file))
dump_cmd = [args.browse_tool, ddd_file]
with subprocess.Popen(dump_cmd, stdout = subprocess.PIPE, stdin = subprocess.PIPE) as proc:
proc.stdin.write(b'_\nc\nVdkVgwKey\n')
proc.stdin.flush()
numEntries = 0
for line in proc.stdout:
match = reNumEntries.match(line.decode('ascii'))
if match:
numEntries = int(match.group(1))
break
print('Found {} entries!'.format(numEntries))
inputStr = '\n'.join(str(i) for i in range(0, numEntries)) + '\n'
proc.stdin.write(inputStr.encode('ascii'))
proc.stdin.write(b'q\n')
proc.stdin.flush()
output, _ = proc.communicate(timeout=60)
data = []
entry = {}
for line in output.decode('ascii').split('\n'):
match = reEntry.match(line)
if match:
name = match.group(1)
if reBadName.match(name):
continue
if name == 'VdkVgwKey':
if entry:
data.append(entry)
entry = {}
continue
value = match.group(2)
if reBadValue.match(value):
value = str()
entry[name] = value
if entry:
data.append(entry)
return data
collection = []
for ddd_file in args.input:
collection += dump_ddd(ddd_file)
with open(args.output, 'w') as json_file:
json.dump(collection, json_file, indent=2)
print('Data written to the file {}'.format(args.output))