-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53fa4af
commit 024dda3
Showing
5 changed files
with
134 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
__title__ = 'crunch-cli' | ||
__description__ = 'crunch-cli - CLI of the CrunchDAO Platform' | ||
__version__ = '0.1.0' | ||
__version__ = '0.1.1' | ||
__author__ = 'Enzo CACERES' | ||
__author_email__ = '[email protected]' | ||
__url__ = 'https://github.com/crunchdao/crunch-cli' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .clone import clone | ||
from .push import push |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import click | ||
import os | ||
import tarfile | ||
import io | ||
import requests | ||
|
||
from .. import constants | ||
|
||
def clone( | ||
session: requests.Session, | ||
clone_token: str, | ||
version_number: str, | ||
project_name: str, | ||
directory: str, | ||
): | ||
directory = directory.replace("{projectName}", project_name) | ||
|
||
if os.path.exists(directory): | ||
print(f"{directory}: already exists") | ||
raise click.Abort() | ||
|
||
push_token = session.post(f"/v1/projects/{project_name}/tokens", json={ | ||
"type": "PERMANENT", | ||
"cloneToken": clone_token | ||
}).json() | ||
|
||
dot_crunchdao_path = os.path.join( | ||
directory, constants.DOT_CRUNCHDAO_DIRECTORY) | ||
os.makedirs(dot_crunchdao_path) | ||
|
||
project_file_path = os.path.join( | ||
dot_crunchdao_path, constants.PROJECT_FILE) | ||
with open(project_file_path, "w") as fd: | ||
fd.write(project_name) | ||
|
||
token_file_path = os.path.join(dot_crunchdao_path, constants.TOKEN_FILE) | ||
with open(token_file_path, "w") as fd: | ||
fd.write(push_token['plain']) | ||
|
||
code_tar = io.BytesIO( | ||
session.get(f"/v1/projects/{project_name}/clone", params={ | ||
"pushToken": push_token['plain'], | ||
"versionNumber": version_number, | ||
}).content | ||
) | ||
|
||
tar = tarfile.open(fileobj=code_tar) | ||
for member in tar.getmembers(): | ||
path = os.path.join(directory, member.name) | ||
print(f"extract {path}") | ||
|
||
fileobj = tar.extractfile(member) | ||
with open(path, "wb") as fd: | ||
fd.write(fileobj.read()) | ||
|
||
print("\n---") | ||
print(f"your project is available at: {directory}") | ||
print(f" - cd {directory}") | ||
print(f" - crunchdao-cli run") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import os | ||
import tarfile | ||
import tempfile | ||
import requests | ||
import gitignorefile | ||
|
||
from .. import utils | ||
from .. import constants | ||
|
||
session = None | ||
debug = False | ||
|
||
|
||
def push( | ||
session: requests.Session, | ||
message: str | ||
): | ||
utils.change_root() | ||
|
||
project_name = utils.read_project_name() | ||
push_token = utils.read_token() | ||
|
||
matches = gitignorefile.Cache() | ||
|
||
with tempfile.NamedTemporaryFile(prefix="version-", suffix=".tar") as tmp: | ||
with tarfile.open(fileobj=tmp, mode="w") as tar: | ||
for root, dirs, files in os.walk(".", topdown=False): | ||
if root.startswith("./"): | ||
root = root[2:] | ||
elif root == ".": | ||
root = "" | ||
|
||
for file in files: | ||
file = os.path.join(root, file) | ||
|
||
ignored = False | ||
for ignore in constants.IGNORED_FILES: | ||
if ignore in file: | ||
ignored = True | ||
break | ||
|
||
if ignored or matches(file): | ||
continue | ||
|
||
print(f"compress {file}") | ||
tar.add(file) | ||
|
||
with open(tmp.name, "rb") as fd: | ||
version = session.post( | ||
f"/v1/projects/{project_name}/versions", | ||
data={ | ||
"message": message, | ||
"pushToken": push_token, | ||
}, | ||
files={ | ||
"tarFile": ('code.tar', fd, "application/x-tar") | ||
} | ||
).json() | ||
|
||
print("\n---") | ||
print(f"version #{version['number']} uploaded!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters