Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3768467
read-token.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
read-token.py
View Options
#!/usr/bin/env python3
import
json
import
os
import
sys
# -------------------------------------------------------------
# Parse Phabricator configuration
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def
get_phabricator_configuration_path
():
candidates
=
[
os
.
environ
[
"HOME"
]
+
"/.arcrc"
,
"/usr/local/etc/arcrc"
,
"/etc/arcrc"
,
]
for
candidate
in
candidates
:
if
os
.
path
.
exists
(
candidate
):
return
candidate
raise
FileNotFoundError
(
"Can't find Arc configuration"
)
def
get_token
(
phabricator_url
):
config_path
=
get_phabricator_configuration_path
()
with
open
(
config_path
)
as
fd
:
config
=
json
.
load
(
fd
)
for
instance
,
args
in
config
.
get
(
"hosts"
,
{})
.
items
():
if
phabricator_url
in
instance
:
return
args
[
"token"
]
raise
RuntimeError
(
f
"{config_path} doesn't describe host {phabricator_url}"
)
# -------------------------------------------------------------
# Application entry point
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def
run
(
phabricator_url
):
token
=
get_token
(
phabricator_url
)
print
(
token
)
if
__name__
==
"__main__"
:
try
:
phabricator_url_fragment
=
sys
.
argv
[
1
]
except
IndexError
:
print
(
"Usage:"
,
sys
.
argv
[
0
],
"<Phabricator instance URL>"
,
file
=
sys
.
stderr
)
sys
.
exit
(
2
)
run
(
phabricator_url_fragment
)
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Mon, Nov 25, 08:08 (1 d, 9 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2259809
Default Alt Text
read-token.py (1 KB)
Attached To
Mode
rDEVTOOLS Nasqueron Devtools
Attached
Detach File
Event Timeline
Log In to Comment