/
utils.py
66 lines (45 loc) · 1.57 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
Copyright (C) 2017-2024 Vanessa Sochat.
This Source Code Form is subject to the terms of the
Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
Modified from https://github.com/Visual-mov/Colorful-Julia (MIT License)
"""
from scif.logger import bot
from scif.defaults import SCIF_BASE
import sys
import os
def parse_input_preferences(recipe, quiet=False):
"""parse a recipe|app, meaning a list of one or more things that could be
any of the following:
Returns
=======
parsed: a dictionary lookup with keys for app, recipe, and quiet.
"""
# if coming from inspect, will be string
if not isinstance(recipe, list):
recipe = [recipe]
# First case: recipe and app
if len(recipe) > 1:
app = recipe[1]
recipe = recipe[0]
quiet = True
# Second case, no input or recipe|app
else:
app = None
# If no recipe provided, assume loading base
if len(recipe) == 0:
recipe = SCIF_BASE
# Otherwise, we need to figure out if recipe or base
else:
recipe = recipe[0]
# If recipe doesn't exist as a file, assume it's an app
if not os.path.exists(recipe):
app = recipe
recipe = SCIF_BASE
# If the recipe provided is a file, no app detection
else:
quiet = True
# Return the parsed data structure
parsed = {"quiet": quiet, "app": app, "recipe": recipe}
return parsed