This repository was archived by the owner on Nov 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage
executable file
·74 lines (60 loc) · 2.07 KB
/
manage
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
#!/usr/bin/env python3
import datetime
import re
import subprocess
import click
import requests
@click.group(context_settings={"help_option_names": ["-h", "--help"]})
@click.version_option(
prog_name="manage", message="%(prog)s %(version)s: Manage all the things."
)
def cli():
pass
@cli.command()
@click.option("--ipns", is_flag=True, help="Link to IPNS.")
@click.option("-e", "--eternum-key", help="The Eternum key to use for pinning.")
def release(ipns, eternum_key):
"""Prepare a release."""
child = subprocess.Popen(
["ipfs", "add", "-Q", "-r", "ipfessay"], stdout=subprocess.PIPE
)
new_hash = child.stdout.read().decode("utf8").strip()
if not new_hash:
print("There was an error releasing.")
return
with open("README.md") as f:
readme = f.read()
readme = re.sub(
r"/ipfs/[a-zA-Z0-9]*?\n", r"/ipfs/%s\n" % new_hash, readme, count=2
)
readme = re.sub(r"(ipfs pin add) [a-zA-Z0-9]+", r"\1 %s" % new_hash, readme)
with open("README.md", "w") as f:
f.write(readme)
print("Released %s" % new_hash)
if eternum_key:
r = requests.post(
"https://www.eternum.io/api/pin/",
headers={"Authorization": "Token %s" % eternum_key},
data={
"hash": new_hash,
"name": "IPFEssay %s"
% datetime.datetime.now().strftime("%Y-%m-%d %H:%M"),
},
)
if 200 <= r.status_code < 300:
print("Pinned on Eternum.")
else:
errors = [x[0] for x in r.json().values()]
print("There was an error pinning on Eternum: %s" % ", ".join(errors))
if ipns:
child = subprocess.Popen(
["ipfs", "name", "publish", "--key=ipfessay", new_hash],
stdout=subprocess.PIPE,
)
ipns_out = child.stdout.read().decode("utf8").strip()
ipns_name = re.search("(\w+)+\:", ipns_out).groups(1)[0]
print("Linked IPNS name: %s" % ipns_name)
def main():
return cli(obj={})
if __name__ == "__main__":
main()