From 4db9dabdc8d812460120bcb1d9d0e2d73523545f Mon Sep 17 00:00:00 2001 From: aedi Date: Thu, 30 Dec 2021 17:00:29 +0100 Subject: [PATCH] update to IPFS-Toolkit V0.2.0 --- .gitignore | 1 + LoadUI.py | 2 +- ReadMe.html | 12 +++++++----- ReadMe.md | 38 +++++++++++++++++++------------------- Site.py | 6 +++--- TODO | 1 + 6 files changed, 32 insertions(+), 28 deletions(-) create mode 100644 TODO diff --git a/.gitignore b/.gitignore index 14871d5..39f5286 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ __pycache__ IPNS-Manager.spec WebPublish Website +WebSite build \ No newline at end of file diff --git a/LoadUI.py b/LoadUI.py index 3fe78d4..164f553 100755 --- a/LoadUI.py +++ b/LoadUI.py @@ -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 = "" diff --git a/ReadMe.html b/ReadMe.html index b6a2472..e3c82b3 100644 --- a/ReadMe.html +++ b/ReadMe.html @@ -57,22 +57,24 @@

Adding Sites

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  
+
source_path  
 old_ipfs_cid  
 new_ipfs_cid  
 ipns_key_id  
-ipns_key_name 

You also have access to the IPFS-Toolkit 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.

+ipns_key_name
+

You also have access to the IPFS-Toolkit 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.

Examples:

-
# Write to log file:
+
# 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.

+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.

Website: https://ipfs.io/ipns/k2k4r8m303h5pjaz7m3fckizzr6lne00ha6kcs97n20ivg9bpm1eu072
Source Code: https://ipfs.io/ipns/k2k4r8ksqdoku10pkm3ftt4d5c8svd9brfm22255uk3ho0sym169l8xi

diff --git a/ReadMe.md b/ReadMe.md index b885b3e..31f10af 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -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. diff --git a/Site.py b/Site.py index f9cbd3a..8085fa5 100755 --- a/Site.py +++ b/Site.py @@ -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 diff --git a/TODO b/TODO new file mode 100644 index 0000000..f5940fd --- /dev/null +++ b/TODO @@ -0,0 +1 @@ +Ouput for custom python code \ No newline at end of file