Skip to content

Commit

Permalink
CTX-6563: Saving changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdan Tintor committed Sep 3, 2024
1 parent 0f7696d commit 55a3509
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 118 deletions.
24 changes: 10 additions & 14 deletions coretex/cli/commands/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import webbrowser

from ..modules import ui
from ..modules import task as task_utils
from ..modules.project_utils import getProject
from ..modules.user import initializeUserSession
from ..modules.utils import onBeforeCommandExecute
Expand All @@ -31,6 +30,7 @@
from ..._task import TaskRunWorker, executeRunLocally, readTaskConfig, runLogger
from ...configuration import UserConfiguration
from ...entities import Task, TaskRun, TaskRunStatus
from ...entities.repository import CORETEX_METADATA_PATH
from ...resources import PYTHON_ENTRY_POINT_PATH


Expand Down Expand Up @@ -116,10 +116,7 @@ def run(path: str, name: Optional[str], description: Optional[str], snapshot: bo
@click.command()
@click.argument("id", type = int, default = None, required = False)
def pull(id: Optional[int]) -> None:
initialMetadataPath = Path(f"{id}/.metadata.json")
coretexMetadataPath = Path(f"{id}/.coretex.json")

if id is None and not coretexMetadataPath.exists():
if id is None and not CORETEX_METADATA_PATH.exists():
id = ui.clickPrompt(f"There is no existing Task repository. Please specify id of Task you want to pull:", type = int)

if id is not None:
Expand All @@ -129,30 +126,29 @@ def pull(id: Optional[int]) -> None:
ui.errorEcho(f"Failed to fetch Task id {id}. Reason: {ex.response}")
return

if not coretexMetadataPath.exists():
if not CORETEX_METADATA_PATH.exists():
task.pull()
task_utils.createMetadata(initialMetadataPath, coretexMetadataPath)
task_utils.fillTaskMetadata(task, initialMetadataPath, coretexMetadataPath)
task.createMetadata()
task.fillMetadata()
else:
remoteMetadata = task.getMetadata()
differences = task_utils.checkMetadataDifference(remoteMetadata, coretexMetadataPath)
differences = task.getDiff()
if len(differences) == 0:
ui.stdEcho("Your repository is already updated.")
return

ui.stdEcho("There are conflicts between your and remote repository.")
for diff in differences:
ui.stdEcho(f"File: {diff['path']} differs")
ui.stdEcho(f" Local checksum: {diff['local_checksum']}")
ui.stdEcho(f" Remote checksum: {diff['remote_checksum']}")
ui.stdEcho(f"\tLocal checksum: {diff['local_checksum']}")
ui.stdEcho(f"\tRemote checksum: {diff['remote_checksum']}")

if not ui.clickPrompt("Do you want to pull the changes and update your local repository? (Y/n):", type = bool, default = True):
ui.stdEcho("No changes were made to your local repository.")
return

task.pull()
task_utils.createMetadata(initialMetadataPath, coretexMetadataPath)
task_utils.fillTaskMetadata(task, initialMetadataPath, coretexMetadataPath)
task.createMetadata()
task.fillMetadata()
ui.stdEcho("Repository updated successfully.")


Expand Down
102 changes: 0 additions & 102 deletions coretex/cli/modules/task.py

This file was deleted.

7 changes: 5 additions & 2 deletions coretex/entities/repository/coretex_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def getRemoteMetadata(self) -> List:

response = networkManager.get(f"{self.endpoint}/metadata", params)
if response.hasFailed():
return NetworkRequestError(response, "Failed to fetch task metadata.")
raise NetworkRequestError(response, "Failed to fetch task metadata.")

return response.getJson(list, force = True)

Expand Down Expand Up @@ -123,7 +123,7 @@ def fillMetadata(self) -> None:

INITIAL_METADATA_PATH.unlink()

def checkDiff(self) -> List[Dict[str, Any]]:
def getDiff(self) -> List[Dict[str, Any]]:
with CORETEX_METADATA_PATH.open("r") as localMetadataFile:
localMetadata = json.load(localMetadataFile)

Expand All @@ -146,3 +146,6 @@ def checkDiff(self) -> List[Dict[str, Any]]:
})

return differences

# def updateRepository(self, differences: List[Dict[str, Any]]) -> None:
# pass

0 comments on commit 55a3509

Please sign in to comment.