0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 04:47:18 +08:00

heavy refactoring

This commit is contained in:
strangeqargo 2016-05-05 23:08:27 +03:00
parent ffc2dd0f3c
commit e457757ec5

View File

@ -32,9 +32,11 @@ import os
import pprint import pprint
# error codes, we should refactor this later # error codes, we should refactor this later
ERROR_BAD_ARGS = 1
ERROR_DATA_TYPE = 10 ERROR_DATA_TYPE = 10
ERROR_STRANGE_PARSING = 20 ERROR_STRANGE_PARSING = 20
from pyparsing import CaselessLiteral, Literal, SkipTo, restOfLine, oneOf, ZeroOrMore, Optional, Combine, Suppress, \ from pyparsing import CaselessLiteral, Literal, SkipTo, restOfLine, oneOf, ZeroOrMore, Optional, Combine, Suppress, \
WordStart, WordEnd, Word, alphas, alphanums, nums, QuotedString, nestedExpr, MatchFirst, OneOrMore, delimitedList, Or, Group, ParseException WordStart, WordEnd, Word, alphas, alphanums, nums, QuotedString, nestedExpr, MatchFirst, OneOrMore, delimitedList, Or, Group, ParseException
@ -71,54 +73,52 @@ def setArgumentBool(s, bool_value):
globals()[var_name] = bool_value globals()[var_name] = bool_value
def usage(): def usage(optionalArgs = []):
print('Usage: ddl2cpp [-no-timestamp-warning] <path to ddl> <path to target (without extension, e.g. /tmp/MyTable)> <namespace>') argString = ''
for arg in optionalArgs:
argString = argString + '[-[no-]'+arg+'] '
print('Usage: ddl2cpp '+ argString +' <path to ddl> <path to target (without extension, e.g. /tmp/MyTable)> <namespace>')
optionalArgs = [
# if -some-key is present, it will set variable someKey to True
# if -no-some-key is present, it will set variable someKey to False
'-timestamp-warning', # timeStampWarning = True
# '-no-time-stamp-warning' # timeStampWarning = False
'-fail-on-parse', # failOnParse = True
'-warn-on-parse' # warnOnParse = True
]
# ARGUMENT PARSING # ARGUMENT PARSING
if len(sys.argv) < (4): if len(sys.argv) < (4):
usage() usage(optionalArgs)
sys.exit(20) sys.exit(ERROR_BAD_ARGS)
firstPositional = 1 firstPositional = 1
timestampWarning = True timestampWarning = True
failOnParse = False failOnParse = False
warnOnParse = True warnOnParse = False
parseError = "parsing error, possible reason: can't parse default value for a field" parseError = "Parsing error, possible reason: can't parse default value for a field"
optionalArgs = {
# if -some-key is present, it will set variable someKey to True
# if -no-some-key is present, it will set variable someKey to False
'timestamp-warning', # timeStampWarning = True
# '-no-time-stamp-warning' # timeStampWarning = False
'fail-on-parse' # failOnParse = True
'warn-on-parse' # warnOnParse = True
}
if len(sys.argv) >= 4: if len(sys.argv) >= 4:
for arg in sys.argv: for arg in sys.argv:
noArg = arg.replace('-no-', '') #print(arg)
noArg = arg.replace('-no-', '-')
print(noArg) print(noArg)
if arg in optionalArgs: if arg in optionalArgs:
print ("AAAA")
print (noArg)
setArgumentBool(arg, True) setArgumentBool(arg, True)
firstPositional += 1 firstPositional += 1
elif noArg in optionalArgs: elif noArg in optionalArgs:
print ("BBBB")
setArgumentBool(noArg, False) setArgumentBool(noArg, False)
firstPositional += 1 firstPositional += 1
else: else:
print ("abcd") pass
print(arg)
pathToDdl = sys.argv[firstPositional] pathToDdl = sys.argv[firstPositional]
pathToHeader = sys.argv[firstPositional + 1] + '.h' pathToHeader = sys.argv[firstPositional + 1] + '.h'
namespace = sys.argv[firstPositional + 2] namespace = sys.argv[firstPositional + 2]
print (pathToDdl)
sys.exit(0)
INCLUDE = 'sqlpp11' INCLUDE = 'sqlpp11'
NAMESPACE = 'sqlpp' NAMESPACE = 'sqlpp'
@ -183,16 +183,15 @@ if failOnParse:
try: try:
tableCreations = ddl.parseFile(pathToDdl) tableCreations = ddl.parseFile(pathToDdl)
except ParseException as e: except ParseException as e:
print(parseError) print(parseError + '. Exiting [-no-fail-on-parse]')
sys.exit() sys.exit(ERROR_STRANGE_PARSING)
else: else:
ddl = ZeroOrMore(Suppress(SkipTo(createTable, False)) + createTable) ddl = ZeroOrMore(Suppress(SkipTo(createTable, False)) + createTable)
ddl.ignore(ddlComment) ddl.ignore(ddlComment)
tableCreations = ddl.parseFile(pathToDdl) tableCreations = ddl.parseFile(pathToDdl)
if warnOnParse: if warnOnParse:
print(parseError) print(parseError + '. Continuing [-no-warn-on-parse]')
# PROCESS DDL # PROCESS DDL