-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnftgen.py
executable file
·148 lines (127 loc) · 3.95 KB
/
nftgen.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python3
import os
# third-party
import yaml
# utils
import src.utils as su
# logging
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
BASE_DIR = os.path.dirname(os.path.realpath(__file__))
def make_args():
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--debug", action="store_true")
parser.add_argument("--env", action="store", help="default: devnet")
parser.add_argument(
"-p", "--project", action="store", help="project name, default is 'example'"
)
parser.add_argument(
"-c",
"--config",
action="store",
help="full path to config file, default is 'config.ini'",
)
parser.add_argument(
"--initialize", action="store_true", help="initialize project directories"
)
parser.add_argument(
"--generate-metadata",
action="store_true",
help="generate metadata from example template",
)
parser.add_argument(
"--generate-images",
action="store_true",
help="generate imates from traits",
)
parser.add_argument(
"--combine-assets", action="store_true", help="images and metadata into assets"
)
parser.add_argument(
"--validate",
action="store_true",
help="validate images and metadata with project validation settings",
)
parser.add_argument(
"--overwrite", action="store_true", help="allow overwriting metadata"
)
parser.add_argument(
"--react-env", action="store_true", help="frontend env to stdout"
)
parser.add_argument(
"--react-env-start-date",
action="store",
help="default is now, format is: 'DD MMM YYYY HH:MM:SS GMT'",
)
parser.add_argument(
"--react-env-candy-machine-id",
action="store",
help="candy machine address from 'metaplex create_candy_machine'",
)
parser.add_argument(
"--override-treasury-address",
action="store",
metavar="KEYPAIR",
help="override treasury address to use keypair instead of creator address",
)
parser.set_defaults(project="example", env="devnet")
args = parser.parse_args()
return args
def main():
args = make_args()
if args.debug:
logger.setLevel(logging.DEBUG)
# config
# ------
if not args.config:
config_fpath = os.path.join(BASE_DIR, "config.yaml")
else:
config_fpath = args.config
logger.info(f"Using config: {config_fpath}")
with open(config_fpath, "r", encoding="utf-8") as f:
config = yaml.load(f, Loader=yaml.FullLoader)
su.validate_config(config=config, project_name=args.project)
# initialize
# ----------
if args.initialize:
su.initialize_project_folder(config=config, project_name=args.project)
# generate
# --------
if args.generate_metadata:
su.generate_metadata_project(
config=config, project_name=args.project, overwrite=args.overwrite
)
# validate
# --------
if args.validate:
su.validate_project(
config=config,
project_name=args.project,
)
# images
# ------
if args.generate_images:
su.generate_images_project(
config=config, project_name=args.project, overwrite=args.overwrite
)
# assets
# ------
if args.combine_assets:
su.combine_assets_project(
config=config, project_name=args.project, overwrite=args.overwrite
)
# react env for frontend
# ----------------------
if args.react_env:
su.react_env_for_project(
config=config,
project_name=args.project,
react_env_candy_machine_id=args.react_env_candy_machine_id,
env=args.env,
react_env_start_date=args.react_env_start_date,
override_treasury_address=args.override_treasury_address,
)
if __name__ == "__main__":
main()