-
Notifications
You must be signed in to change notification settings - Fork 10
Added scripts to run a backup between tiled servers running different versions #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jmaruland
wants to merge
1
commit into
AI-multimodal:main
Choose a base branch
from
jmaruland:add-backup-scripts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,102 @@ | ||||||
| import json | ||||||
| import os | ||||||
| import pandas as pd | ||||||
|
|
||||||
| def download_aimmdd_data(c): | ||||||
| """ | ||||||
| Navigate through a tiled client and download all the entries that are found | ||||||
|
|
||||||
| Parameters | ||||||
| ---------- | ||||||
| c : tiled.client | ||||||
|
|
||||||
| Returns | ||||||
| ------- | ||||||
| None. | ||||||
|
|
||||||
| """ | ||||||
|
|
||||||
| if not os.path.exists("files/"): | ||||||
| os.mkdir("files/") | ||||||
|
|
||||||
| for key in c['dataset'].keys(): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is perfectly fine. It's useful to know that iterating through a dict-like object iterates through its keys, so you can just write:
Suggested change
|
||||||
| print(f"Downloading {key} dataset...") | ||||||
| if not os.path.exists(f"files/{key}/"): | ||||||
| os.mkdir(f"files/{key}/") | ||||||
|
|
||||||
| for node_value in c['dataset'][key]['uid'].values(): | ||||||
| uid = node_value.item['id'] | ||||||
| print(f"---- Saving node {uid}...") | ||||||
| metadata = dict(node_value.metadata) | ||||||
| del metadata['_tiled'] # it's not necessary to keep the uid generated by the server. The new server will generate a new uid | ||||||
| specs = list(node_value.specs) | ||||||
|
|
||||||
| data_dict = node_value.read().to_dict() | ||||||
|
|
||||||
| meta_content = {"metadata": metadata, "specs": specs, "data": data_dict} | ||||||
|
|
||||||
| with open(f"files/{key}/{uid}.json", 'w') as file: | ||||||
| json.dump(meta_content, file) | ||||||
|
|
||||||
| print("Download completed!") | ||||||
|
|
||||||
| def upload_aimmdb_data(c, folder_path): | ||||||
| """ | ||||||
| Walks through a path in the local machine and writes the data into a remote instance of tiled | ||||||
|
|
||||||
| Parameters | ||||||
| ---------- | ||||||
| c : tiled.client | ||||||
| folder_path : pathlib.Path | ||||||
| Path to folder contianing backup data. | ||||||
|
|
||||||
| Returns | ||||||
| ------- | ||||||
| None. | ||||||
|
|
||||||
| """ | ||||||
|
|
||||||
| filepaths = sorted(folder_path.iterdir()) | ||||||
|
|
||||||
| for i in range(len(filepaths)): | ||||||
| if filepaths[i].name.startswith("."): | ||||||
| # Skip hidden files. | ||||||
| continue | ||||||
| if not filepaths[i].is_file(): | ||||||
| # Explore subfolder for more labview files recursively | ||||||
| upload_aimmdb_data(c, filepaths[i]) | ||||||
| if filepaths[i].suffix == ".json": | ||||||
| if filepaths[i].stem not in c: | ||||||
| with open(filepaths[i]) as f: | ||||||
| sample = json.load(f) | ||||||
|
|
||||||
| metadata = sample["metadata"] | ||||||
| specs = sample["specs"] | ||||||
| data = pd.DataFrame(sample["data"]) | ||||||
|
|
||||||
| node = c.write_dataframe(data, key=filepaths[i].stem, metadata=metadata, specs=specs) | ||||||
| print(f"dataset: {folder_path.name} - node {node.item['id']} was created") | ||||||
| else: | ||||||
| print(f"dataset: {folder_path.name} - node {filepaths[i].stem} already exists") | ||||||
|
|
||||||
|
|
||||||
| def delete_dataset(c, dataset): | ||||||
| """ | ||||||
| Deletes all the entries of a given dataset | ||||||
|
|
||||||
| Parameters | ||||||
| ---------- | ||||||
| c : tiled.client | ||||||
| dataset : str | ||||||
| name of a data set in a remote tiled instance. | ||||||
|
|
||||||
| Returns | ||||||
| ------- | ||||||
| None. | ||||||
|
|
||||||
| """ | ||||||
|
|
||||||
| if dataset in c: | ||||||
| for key in c[dataset].keys(): | ||||||
| c[dataset].delete(key) | ||||||
| print(f"Node {key} has been deleted") | ||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an optional argument to say "Create the directory only if it doesn't already exist." https://docs.python.org/3/library/os.html#os.makedirs