Add check for source existing in inq add
This commit is contained in:
parent
d98fb246c0
commit
73c2319645
|
@ -85,6 +85,7 @@ def command_add(args):
|
||||||
parser.add_argument("--body", help="HTML")
|
parser.add_argument("--body", help="HTML")
|
||||||
parser.add_argument("--tags", help="Comma-separated list")
|
parser.add_argument("--tags", help="Comma-separated list")
|
||||||
parser.add_argument("--ttl", type=int, help="Cleanup protection in seconds")
|
parser.add_argument("--ttl", type=int, help="Cleanup protection in seconds")
|
||||||
|
parser.add_argument("--create", action="store_true", help="Create source if it doesn't exist")
|
||||||
args = parser.parse_args(args)
|
args = parser.parse_args(args)
|
||||||
|
|
||||||
if not args.title:
|
if not args.title:
|
||||||
|
@ -94,6 +95,15 @@ def command_add(args):
|
||||||
logger.error("Couldn't find dungeon. Set INQUISITOR_DUNGEON or cd to parent folder of ./dungeon")
|
logger.error("Couldn't find dungeon. Set INQUISITOR_DUNGEON or cd to parent folder of ./dungeon")
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
source = args.source or 'inquisitor'
|
||||||
|
cell_path = os.path.join(DUNGEON_PATH, source)
|
||||||
|
if not os.path.isdir(cell_path):
|
||||||
|
if args.create:
|
||||||
|
os.mkdir(cell_path)
|
||||||
|
else:
|
||||||
|
logger.error("Source '{}' does not exist".format(source))
|
||||||
|
return -1
|
||||||
|
|
||||||
from importer import populate_new
|
from importer import populate_new
|
||||||
item = {
|
item = {
|
||||||
'id': '{:x}'.format(random.getrandbits(16 * 4)),
|
'id': '{:x}'.format(random.getrandbits(16 * 4)),
|
||||||
|
@ -109,6 +119,7 @@ def command_add(args):
|
||||||
if args.tags: item['tags'] = [str(tag) for tag in args.tags]
|
if args.tags: item['tags'] = [str(tag) for tag in args.tags]
|
||||||
if args.ttl: item['ttl'] = int(args.ttl)
|
if args.ttl: item['ttl'] = int(args.ttl)
|
||||||
populate_new(item)
|
populate_new(item)
|
||||||
|
|
||||||
s = json.dumps(item, indent=2)
|
s = json.dumps(item, indent=2)
|
||||||
path = os.path.join(DUNGEON_PATH, item['source'], item['id'] + '.item')
|
path = os.path.join(DUNGEON_PATH, item['source'], item['id'] + '.item')
|
||||||
with open(path, 'w', encoding='utf8') as f:
|
with open(path, 'w', encoding='utf8') as f:
|
||||||
|
|
Loading…
Reference in New Issue