Skip to content

Commit

Permalink
update to IPFS-Toolkit V0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aedi committed Dec 30, 2021
1 parent 0a10340 commit 4db9dab
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ __pycache__
IPNS-Manager.spec
WebPublish
Website
WebSite
build
2 changes: 1 addition & 1 deletion LoadUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, ):
self.sitespage_lyt.addWidget(self.projectslist)

paths = self.LoadPaths() # load the paths of the IPNS sites from appdata
keys = IPFS_API.ipfs.key.list().get("Keys") # get this IPFS node's list of IPNS keys
keys = IPFS_API.http_client.key.list().get("Keys") # get this IPFS node's list of IPNS keys
# adding SiteWidget for each IPNS key
for key in keys:
path = ""
Expand Down
12 changes: 7 additions & 5 deletions ReadMe.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,24 @@ <h3 id="adding-sites">Adding Sites</h3>
<p><img src="Screenshots/NewSite.png" alt=""><img src="Screenshots/AddedSource.png" alt=""></p>
<h3 id="adding-custom-code">Adding Custom Code</h3>
<p>You can add your own Python code to be executed whenever you press a Site's "Update from Source". At the bottom of the IPNS-Manager window, press the "Code" tab. This will open a new view with a field in which you can paste a small python script. In this code, you can access the newly updated Site's data using the following variables:</p>
<pre><code>source_path
<pre><code class="language-python">source_path
old_ipfs_cid
new_ipfs_cid
ipns_key_id
ipns_key_name </code></pre><p>You also have access to the <a href="https://ipfs.io/ipns/k2k4r8m2dzqi5s8jm3shm77sr1728ex7bsds0fk6e9gkf2ld2f3mnhcy">IPFS-Toolkit</a> library (which contains the <code>IPFS_API</code>, <code>IPFS_DataTransmission</code> and <code>IPFS_LNS</code> modules), as well as all global variables in the LoadUI.py script from IPNS-Manager's source code.</p>
ipns_key_name </code></pre>
<p>You also have access to the <a href="https://ipfs.io/ipns/k2k4r8m2dzqi5s8jm3shm77sr1728ex7bsds0fk6e9gkf2ld2f3mnhcy">IPFS-Toolkit</a> library (which contains the <code>IPFS_API</code>, <code>IPFS_DataTransmission</code> and <code>IPFS_LNS</code> modules), as well as all global variables in the LoadUI.py script from IPNS-Manager's source code.</p>
<p><img src="Screenshots/Code.png" alt=""></p>
<p>Examples:</p>
<pre><code># Write to log file:
<pre><code class="language-python"># Write to log file:
from datetime import datetime
if new_ipfs_cid != old_ipfs_cid:
with open(os.path.join(appdata_dir, "log"), "a+") as log_file: # appdata_dir is a global varibale from LoadUI.py
log_file.write(f"{datetime.now()}: {ipns_key_name}: {new_ipfs_cid}\n")

# ssh into an always-online-computer with ipfs installed and pin the updated Site's CID
os.system(f"ssh -t -q admin@IP_ADDRESS 'ipfs pin rm {old_ipfs_cid}; ipfs pin add {new_ipfs_cid}; ipfs name resolve {ipns_key_id}'")</code></pre><p> The "Save" button saves your code to appdata. The "Update from Source" button however always executes the latest code you've written, regardless of whether it has been saved or not.
To debug your code, run IPNS-Manager from a terminal window. All <code>print</code> statements in your code will be printed on the terminal.</p>
os.system(f"ssh -t -q admin@IP_ADDRESS 'ipfs pin rm {old_ipfs_cid}; ipfs pin add {new_ipfs_cid}; ipfs name resolve {ipns_key_id}'")</code></pre>
<p>The "Save" button saves your code to appdata. The "Update from Source" button however always executes the latest code you've written, regardless of whether it has been saved or not.
To debug your code, run IPNS-Manager from a terminal window. All <code>print</code> statements in your code will be printed on the terminal.</p>
<h1 id="links-">Links:</h1>
<p>Naturally, this project is also hosted on IPFS.</p>
<p>Website: <a href="https://ipfs.io/ipns/k2k4r8m303h5pjaz7m3fckizzr6lne00ha6kcs97n20ivg9bpm1eu072">https://ipfs.io/ipns/k2k4r8m303h5pjaz7m3fckizzr6lne00ha6kcs97n20ivg9bpm1eu072</a><br>Source Code: <a href="https://ipfs.io/ipns/k2k4r8ksqdoku10pkm3ftt4d5c8svd9brfm22255uk3ho0sym169l8xi">https://ipfs.io/ipns/k2k4r8ksqdoku10pkm3ftt4d5c8svd9brfm22255uk3ho0sym169l8xi</a></p>
Expand Down
38 changes: 19 additions & 19 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,30 @@ Make sure IPFS is running on your computer before you run this program.

### Adding Custom Code
You can add your own Python code to be executed whenever you press a Site's "Update from Source". At the bottom of the IPNS-Manager window, press the "Code" tab. This will open a new view with a field in which you can paste a small python script. In this code, you can access the newly updated Site's data using the following variables:

source_path
old_ipfs_cid
new_ipfs_cid
ipns_key_id
ipns_key_name

```python
source_path
old_ipfs_cid
new_ipfs_cid
ipns_key_id
ipns_key_name
```
You also have access to the [IPFS-Toolkit](https://ipfs.io/ipns/k2k4r8m2dzqi5s8jm3shm77sr1728ex7bsds0fk6e9gkf2ld2f3mnhcy) library (which contains the `IPFS_API`, `IPFS_DataTransmission` and `IPFS_LNS` modules), as well as all global variables in the LoadUI.py script from IPNS-Manager's source code.

![](Screenshots/Code.png)

Examples:

# Write to log file:
from datetime import datetime
if new_ipfs_cid != old_ipfs_cid:
with open(os.path.join(appdata_dir, "log"), "a+") as log_file: # appdata_dir is a global varibale from LoadUI.py
log_file.write(f"{datetime.now()}: {ipns_key_name}: {new_ipfs_cid}\n")

# ssh into an always-online-computer with ipfs installed and pin the updated Site's CID
os.system(f"ssh -t -q admin@IP_ADDRESS 'ipfs pin rm {old_ipfs_cid}; ipfs pin add {new_ipfs_cid}; ipfs name resolve {ipns_key_id}'")
The "Save" button saves your code to appdata. The "Update from Source" button however always executes the latest code you've written, regardless of whether it has been saved or not.
To debug your code, run IPNS-Manager from a terminal window. All `print` statements in your code will be printed on the terminal.
```python
# Write to log file:
from datetime import datetime
if new_ipfs_cid != old_ipfs_cid:
with open(os.path.join(appdata_dir, "log"), "a+") as log_file: # appdata_dir is a global varibale from LoadUI.py
log_file.write(f"{datetime.now()}: {ipns_key_name}: {new_ipfs_cid}\n")

# ssh into an always-online-computer with ipfs installed and pin the updated Site's CID
os.system(f"ssh -t -q admin@IP_ADDRESS 'ipfs pin rm {old_ipfs_cid}; ipfs pin add {new_ipfs_cid}; ipfs name resolve {ipns_key_id}'")
```
The "Save" button saves your code to appdata. The "Update from Source" button however always executes the latest code you've written, regardless of whether it has been saved or not.
To debug your code, run IPNS-Manager from a terminal window. All `print` statements in your code will be printed on the terminal.

# Links:
Naturally, this project is also hosted on IPFS.
Expand Down
6 changes: 3 additions & 3 deletions Site.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ def ResolveKey():

def UpdateIPNS_Record(self):
"""Publish the new IPFS CID associated with this IPNS Record"""
self.ipfs_cid = IPFS_API.Upload(self.path)
self.ipfs_cid = IPFS_API.Publish(self.path)
_thread.start_new_thread(IPFS_API.UpdateIPNS_RecordFromHash,
(self.ipns_key_name, self.ipfs_cid, "1000h", "1000h"))

def DeleteIPNS_Record(self):
IPFS_API.ipfs.key.rm(self.ipns_key_name)
IPFS_API.http_client.key.rm(self.ipns_key_name)

def ChangeIPNS_Name(self, name):
IPFS_API.ipfs.key.rename(self.ipns_key_name, name)
IPFS_API.http_client.key.rename(self.ipns_key_name, name)
self.ipns_key_name = name
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ouput for custom python code

0 comments on commit 4db9dab

Please sign in to comment.