-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DBD to SQL converter script #140
base: master
Are you sure you want to change the base?
Conversation
I'd suggest to instead have |
Great idea! What about the diagnostic prints - redirect them to stderr or just disable with this default |
Unix tools usually just have no output unless there is an error, which is printed to stderr, so the question vanishes. If you do want to have unconditional debug output, stderr still seems to be the right choice. The implementation looks fine. Another standard which I forgot to mention, which also avoids the "is the variable a file or a string?" thing is to have -from io import TextIOWrapper
from sys import stdout, stderr
parser = ArgumentParser();
group = parser.add_mutually_exclusive_group();
group.add_argument('--layout', type=str, help="target layout, e.g. '90747013'");
group.add_argument('--build', type=str, help="target build, e.g. '10.0.0.43342'");
parser.add_argument('dbds', type=str, nargs='*', help='directory with / list of for dbd files to process');
-parser.add_argument('--output', type=str, default=stdout, help='file to dump sql to');
+parser.add_argument('--output', type=str, default='-', help='file to dump sql to');
args = parser.parse_args();
dbds:list[str] = args.dbds or os.path.join(
os.path.dirname( # WoWDBDefs/
os.path.dirname( # code/
os.path.dirname( # Python/
os.path.abspath(__file__) # ./dbd_to_sql.py
))),
'definitions'
);
if not dbds[0].endswith(dbd.file_suffix):
dbds = glob(os.path.join(dbds[0], '*.dbd'));
-outfile:TextIOWrapper = args.output;
-if type(outfile) != TextIOWrapper:
- outfile = open(outfile, 'a');
+outfile = sys.stdout if args.output == '-' else open(outfile, 'a'); |
The script uses a global variable keys to store primary key information. Consider passing this information as a parameter to functions instead of using a global variable. |
Script for creating SQL table structure statements from .dbd files. My intention would be to use it as a precursor to CSV import, because on its own the latter doesn't create any indices or foreign keys.
TODO items:
SpellVisualMissile.SpellVisualMissileSetID
which sometimes cause FK errors on creation even withFOREIGN_KEY_CHECKS=0
, so I left them as simple indices for now.