Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.

Commit 6603069

Browse files
Merge pull request #5 from provenance-io/command-split-fixes
Command split fixes
2 parents c1568c1 + 00233a6 commit 6603069

File tree

8 files changed

+52
-99
lines changed

8 files changed

+52
-99
lines changed

forgepb/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from command_line import root_cmd
1+
from forgepb.command_line import root_cmd
22

33
if __name__ == '__main__':
44
try:

forgepb/builder.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def build(environment, network, config, provenance_branch=None, version=None, ar
3636
version = provenance_branch
3737
branches = utils.get_remote_branches()
3838
repo = git.Repo(provenance_path)
39-
print(branches)
4039
try:
4140
if provenance_branch in branches:
4241
repo.git.checkout(provenance_branch)
@@ -229,22 +228,27 @@ def spawnDaemon(node_command, version, network, config, log_path):
229228

230229

231230
def start_node(node_command, version, network, config, log_path):
232-
log = open(log_path, 'w+')
233-
print('Running {}'.format(''.join(node_command)))
234-
print('You can view the logs here: {}'.format(log_path))
235-
process = subprocess.Popen(
236-
node_command, shell=False, stdout=log, stderr=log)
237-
if network == 'localnet':
238-
config[network][version]['run-command'] = node_command
239-
config[network][version]['log-path'] = log_path
240-
else:
241-
config[network]['run-command'] = node_command
242-
config[network]['log-path'] = log_path
243-
config['running-node'] = True
244-
config['running-node-info'] = {
245-
"pid": process.pid,
246-
"version": version,
247-
"network": network
248-
}
249-
utils.save_config(config)
250-
process.wait()
231+
try:
232+
log = open(log_path, 'w+')
233+
print('Running {}'.format(' '.join(node_command)))
234+
print('You can view the logs here: {}'.format(log_path))
235+
process = subprocess.Popen(
236+
node_command, shell=False, stdout=log, stderr=log)
237+
if network == 'localnet':
238+
config[network][version]['run-command'] = node_command
239+
config[network][version]['log-path'] = log_path
240+
else:
241+
config[network]['run-command'] = node_command
242+
config[network]['log-path'] = log_path
243+
config['running-node'] = True
244+
config['running-node-info'] = {
245+
"pid": process.pid,
246+
"version": version,
247+
"network": network
248+
}
249+
utils.save_config(config)
250+
process.wait()
251+
except FileNotFoundError:
252+
print("It looks like a node was initialized and deleted.\nForge is removing this from the config so you can run the same command again and the node will be initialized and started.".format())
253+
config.pop(network)
254+
utils.save_config(config)

forgepb/cmd/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import click
22

3-
from cmd.node import *
4-
from cmd.config import *
5-
from cmd.provenance import *
3+
from forgepb.cmd.config import *
4+
from forgepb.cmd.node import *
5+
from forgepb.cmd.provenance import *
66

77

88
@click.group("node", help="Interact with nodes")
@@ -12,6 +12,7 @@ def node_cmd(): pass
1212
@click.group("config")
1313
def config_cmd(): pass
1414

15+
1516
@click.group("provenance", help="Retrieve information on provenance")
1617
def provenance_cmd(): pass
1718

@@ -23,8 +24,7 @@ def provenance_cmd(): pass
2324
node_cmd.add_command(node_init_cmd)
2425
node_cmd.add_command(list_mnemonic_cmd)
2526

26-
config_cmd.add_command(list_config_cmd)
2727
config_cmd.add_command(change_save_loc_cmd)
2828

2929
provenance_cmd.add_command(list_tags_cmd)
30-
provenance_cmd.add_command(list_branches_cmd)
30+
provenance_cmd.add_command(list_branches_cmd)

forgepb/cmd/config.py

Lines changed: 14 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,26 @@
1-
import json
2-
import os
31
import click
42

5-
from forgepb import utils, builder, forge, config_handler, global_
6-
7-
8-
@click.command(
9-
'list',
10-
help='List config information about localnet nodes that have been initialized'
11-
)
12-
@click.option(
13-
"-t",
14-
"--tag",
15-
"tag",
16-
default=None,
17-
help="Release tag used to specify the localnet config to display")
18-
@click.option(
19-
'-b',
20-
'--provenance-branch',
21-
'provenance_branch',
22-
type=click.STRING,
23-
help='Provenance branch used to specify the localnet config to display')
24-
def list_config_cmd(tag, provenance_branch):
25-
# get config or set location of config to be made
26-
if not os.path.exists(global_.CONFIG_PATH + "/config.json"):
27-
config = config_handler.set_build_location()
28-
else:
29-
config = utils.load_config()
30-
provenance_path = config['saveDir'] + "forge" + "/provenance"
31-
# Retrieve the config information if it exists, else display a message saying that it couldn't be found
32-
try:
33-
if tag:
34-
if tag not in utils.get_versions():
35-
print(
36-
"The version entered doesn't exist in provenance. Please run 'forge -lsv' to list all versions")
37-
else:
38-
print(json.dumps(config['localnet'][tag], indent=4))
39-
elif provenance_branch:
40-
if provenance_branch not in utils.get_remote_branches():
41-
print(
42-
"The version entered doesn't exist in provenance. Please run 'forge -lsv' to list all versions")
43-
else:
44-
print(json.dumps(config['localnet']
45-
[provenance_branch], indent=4))
46-
else:
47-
print(json.dumps(config['localnet'], indent=4))
48-
except KeyError:
49-
print("No nodes found.")
50-
except:
51-
print("No nodes have been initialized.")
3+
from forgepb import config_handler, utils
524

535

546
@click.command(
557
'save_location',
568
help='Change the save location of forge'
579
)
58-
@click.option(
59-
'-p',
60-
'--path',
10+
@click.argument(
6111
'path',
62-
type=click.STRING,
63-
help='Existing path that forge will save initialized nodes into'
12+
type=str,
13+
required=False,
6414
)
6515
def change_save_loc_cmd(path):
66-
config_handler.check_save_location(path)
16+
if path is None:
17+
if not utils.exists_config():
18+
print("save_location=None")
19+
return
20+
21+
cfg = utils.load_config()
22+
print(cfg["saveDir"])
23+
return
24+
else:
25+
config_handler.check_save_location(path)
6726
return

forgepb/cmd/provenance.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import sys
21
import click
32

4-
import utils
5-
6-
7-
sys.path.insert(1, './forgepb')
3+
from forgepb import utils
84

95

106
@click.command(

forgepb/command_line.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
import sys
2-
31
import click
42

5-
sys.path.insert(1, './forgepb')
6-
sys.path.insert(1, './forgepb/cmd')
7-
import forge
8-
from cmd import node_cmd, config_cmd, provenance_cmd
3+
from forgepb import forge, cmd
94

105

116
class CustomMultiCommand(click.Group):
12-
137
def command(self, *args, **kwargs):
148
"""Behaves the same as `click.Group.command()` except if passed
159
a list of names, all after the first will be aliases for the first.
@@ -42,9 +36,9 @@ def start_wizard():
4236
forge.main()
4337

4438

45-
root_cmd.add_command(node_cmd)
46-
root_cmd.add_command(config_cmd)
47-
root_cmd.add_command(provenance_cmd)
39+
root_cmd.add_command(cmd.node_cmd)
40+
root_cmd.add_command(cmd.config_cmd)
41+
root_cmd.add_command(cmd.provenance_cmd)
4842

4943
# Point for setup.py to point to for installing
5044
start = click.CommandCollection(sources=[root_cmd])

forgepb/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def collect_args(args):
126126
while not args_complete:
127127
try:
128128
cleveldb = input(
129-
"Build environment with C Level DB? Usually not required for local testing. [No]\n")
129+
"Build environment with C Level DB? Usually not required for local testing. [No]/yes\n")
130130
if not cleveldb:
131131
args.append("WITH_CLEVELDB=no")
132132
args_complete = True

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
setup(
99
name="forge.pb",
10-
version="1.0.0",
10+
version="1.0.1",
1111
url='https://github.com/provenance-io/forge.pb',
1212
author='Wyatt Baker',
1313
author_email='wbaker@figure.com',
14-
packages=['forgepb'],
14+
packages=['forgepb','forgepb.cmd'],
1515
install_requires = [requirements],
1616
python_requires='>=3.6',
1717
entry_points={

0 commit comments

Comments
 (0)