Add b2 setup. Change repourl
This commit is contained in:
parent
acbe9a7751
commit
1920b9c9f0
21
src/pack.py
21
src/pack.py
|
@ -4,16 +4,24 @@ import shutil
|
||||||
import zipfile
|
import zipfile
|
||||||
import hashlib
|
import hashlib
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
from b2sdk.v1 import InMemoryAccountInfo
|
||||||
|
from b2sdk.v1 import B2Api
|
||||||
|
|
||||||
class Pack:
|
class Pack:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
self.repourl = os.environ.get("RESOURCE_PACK_URL")
|
self.repourl = os.environ.get("RESOURCE_PACK_URL")
|
||||||
command = "git clone git@github.com:" + self.repourl
|
command = "git clone " + self.repourl
|
||||||
self.dir = re.split("/|\.", self.repourl)[1]
|
self.dir = re.split("/|\.", self.repourl)[1]
|
||||||
status = os.system(command)
|
status = os.system(command)
|
||||||
print(status)
|
print(status)
|
||||||
|
|
||||||
|
info = InMemoryAccountInfo() # store credentials, tokens and cache in memory
|
||||||
|
b2_api = B2Api(info)
|
||||||
|
b2_api.authorize_account("production", os.environ.get("APPLICATION_KEY_ID"),
|
||||||
|
os.environ.get("APPLICATION_KEY"))
|
||||||
|
self.bucket = b2_api.get_bucket_by_name(os.environ.get("BUCKET"))
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
shutil.rmtree(self.dir)
|
shutil.rmtree(self.dir)
|
||||||
|
|
||||||
|
@ -47,6 +55,17 @@ class Pack:
|
||||||
with open("files/hash", 'w') as hashfile:
|
with open("files/hash", 'w') as hashfile:
|
||||||
hashfile.write(self.hash)
|
hashfile.write(self.hash)
|
||||||
|
|
||||||
|
def upload(self):
|
||||||
|
bucket.upload_local_file(
|
||||||
|
local_file="files/pack.zip",
|
||||||
|
file_name="pack.zip")
|
||||||
|
|
||||||
|
bucket.upload_local_file(
|
||||||
|
local_file="files/hash",
|
||||||
|
file_name="hash")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue