forked from stx-labs/stacks.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblockstack
More file actions
executable file
·118 lines (89 loc) · 3.56 KB
/
blockstack
File metadata and controls
executable file
·118 lines (89 loc) · 3.56 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Blockstack-client
~~~~~
copyright: (c) 2014-2015 by Halfmoon Labs, Inc.
copyright: (c) 2016 by Blockstack.org
This file is part of Blockstack-client.
Blockstack-client is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Blockstack-client is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Blockstack-client. If not, see <http://www.gnu.org/licenses/>.
"""
import os
import sys
if sys.version_info.major != 2:
raise Exception("Python 3 is not supported")
if sys.version_info.minor < 7:
raise Exception("Python 2.7 or greater is required")
import traceback
import json
# Hack around absolute paths
current_dir = os.path.abspath(os.path.dirname(__file__))
parent_dir = os.path.abspath(current_dir + "/../")
sys.path.insert(0, parent_dir)
from blockstack_client.cli import run_cli, exit_with_error
from blockstack_client.config import get_logger, configure, CONFIG_PATH, client_uuid_path, VERSION
from blockstack_client.client import analytics_event, analytics_user_register, analytics_user_update
from blockstack_client.utils import pretty_print
def enable_debug( argv ):
"""
If '--debug' was passed, then activate debugging
by re-execing with BLOCKSTACK_DEBUG=1 set.
"""
new_argv = []
set_envar = False
debug = (os.environ.get("BLOCKSTACK_DEBUG", None) == "1")
set_debug = False
for arg in argv:
if not debug and arg == '--debug':
# will set debug
set_debug = True
set_envar = True
else:
# skip
new_argv.append(arg)
if set_envar:
if set_debug:
os.environ["BLOCKSTACK_DEBUG"] = "1"
os.execv( new_argv[0], new_argv )
return True
if __name__ == '__main__':
log = get_logger()
enable_debug( sys.argv )
uuid_path = client_uuid_path()
first_time = False
if not os.path.exists(uuid_path):
first_time = True
# make sure we have sane defaults, and we have registered this installation
res = configure(interactive=False, force=False)
if res.has_key('uuid') and first_time:
# prompt for email
print "Would you like to receive an email when there is a new release of this software available?"
email_addr = raw_input("Email address (leave blank to opt out): ")
# will only process real email addresses when we email announcements out
analytics_user_register( res['uuid'], email_addr )
try:
result = run_cli()
if 'error' in result:
if type(result) in [str, unicode]:
print >> sys.stderr, result
else:
print >> sys.stderr, result['error']
sys.exit(1)
else:
print json.dumps(result, indent=4, sort_keys=True)
sys.exit(0)
except Exception as e:
log.exception(e)
error_message = "Unexpected error:\n%s" % traceback.format_exc()
help_message = 'Try getting latest version of CLI'
help_message += ' with "sudo pip install blockstack --upgrade"'
exit_with_error(error_message, help_message)