initial support for update
stubbed out mostly
This commit is contained in:
@@ -22,6 +22,8 @@
|
|||||||
Blender asset manager
|
Blender asset manager
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
# ------------------
|
# ------------------
|
||||||
# Ensure module path
|
# Ensure module path
|
||||||
@@ -121,7 +123,14 @@ class bam_config:
|
|||||||
abort=abort,
|
abort=abort,
|
||||||
descr="bam session"
|
descr="bam session"
|
||||||
)
|
)
|
||||||
return session_rootdir[:-len(bam_config.SESSION_FILE)]
|
|
||||||
|
if session_rootdir is not None:
|
||||||
|
return session_rootdir[:-len(bam_config.SESSION_FILE)]
|
||||||
|
else:
|
||||||
|
if abort:
|
||||||
|
if not os.path.isdir(session_rootdir):
|
||||||
|
fatal("Expected a directory (%r)" % session_rootdir)
|
||||||
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load(id_="config", cwd=None, abort=False):
|
def load(id_="config", cwd=None, abort=False):
|
||||||
@@ -223,10 +232,7 @@ class bam_session:
|
|||||||
os.path.join(session_rootdir, ".bam_tmp.zip"),
|
os.path.join(session_rootdir, ".bam_tmp.zip"),
|
||||||
}
|
}
|
||||||
|
|
||||||
with open(os.path.join(session_rootdir, ".bam_paths_uuid.json"), 'r') as f:
|
paths_uuid = bam_session.load_paths_uuid(session_rootdir)
|
||||||
import json
|
|
||||||
paths_uuid = json.load(f)
|
|
||||||
del json
|
|
||||||
|
|
||||||
for f_rel, sha1 in paths_uuid.items():
|
for f_rel, sha1 in paths_uuid.items():
|
||||||
f_abs = os.path.join(session_rootdir, f_rel)
|
f_abs = os.path.join(session_rootdir, f_rel)
|
||||||
@@ -268,6 +274,13 @@ class bam_session:
|
|||||||
if paths_uuid_update is not None:
|
if paths_uuid_update is not None:
|
||||||
paths_uuid_update[f_rel] = sha1_from_file(f_abs)
|
paths_uuid_update[f_rel] = sha1_from_file(f_abs)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def load_paths_uuid(session_rootdir):
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
with open(os.path.join(session_rootdir, ".bam_paths_uuid.json")) as f:
|
||||||
|
return json.load(f)
|
||||||
|
|
||||||
|
|
||||||
class bam_commands:
|
class bam_commands:
|
||||||
"""
|
"""
|
||||||
@@ -347,7 +360,7 @@ class bam_commands:
|
|||||||
print("Session %r created" % session_name)
|
print("Session %r created" % session_name)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def checkout(path, output_dir=None):
|
def checkout(path, output_dir=None, session_rootdir_partial=None):
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
@@ -369,6 +382,9 @@ class bam_commands:
|
|||||||
dst_dir = output_dir
|
dst_dir = output_dir
|
||||||
del output_dir
|
del output_dir
|
||||||
|
|
||||||
|
if session_rootdir_partial:
|
||||||
|
pass
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
"filepath": path,
|
"filepath": path,
|
||||||
"command": "checkout",
|
"command": "checkout",
|
||||||
@@ -430,6 +446,43 @@ class bam_commands:
|
|||||||
|
|
||||||
sys.stdout.write("\nwritten: %r\n" % dst_dir)
|
sys.stdout.write("\nwritten: %r\n" % dst_dir)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def update(paths):
|
||||||
|
# Load project configuration
|
||||||
|
cfg = bam_config.load(abort=True)
|
||||||
|
|
||||||
|
# TODO(cam) multiple paths
|
||||||
|
session_rootdir = bam_config.find_sessiondir(paths[0], abort=True)
|
||||||
|
paths_uuid = bam_session.load_paths_uuid(session_rootdir)
|
||||||
|
|
||||||
|
if not paths_uuid:
|
||||||
|
print("Nothing to update!")
|
||||||
|
return
|
||||||
|
# -------------------------------------------------------------------------------
|
||||||
|
# TODO(cam) don't guess this important info
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
files = os.listdir(session_rootdir)
|
||||||
|
files_blend = [f for f in files if f.endswith(".blend")]
|
||||||
|
if files_blend:
|
||||||
|
file = files_blend[0]
|
||||||
|
else:
|
||||||
|
file = files[0]
|
||||||
|
with open(os.path.join(session_rootdir, ".bam_paths_remap.json")) as f:
|
||||||
|
paths_remap = json.load(f)
|
||||||
|
paths_remap_relbase = paths_remap.get(".", "")
|
||||||
|
path = os.path.join(paths_remap_relbase, file)
|
||||||
|
# -------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Send to sever sha PUT
|
||||||
|
# retrieve zip GET
|
||||||
|
# merge sessions
|
||||||
|
bam_commands.checkout(
|
||||||
|
path,
|
||||||
|
output_dir=session_rootdir.rstrip(os.sep) + ".tmp",
|
||||||
|
session_rootdir_partial=session_rootdir,
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def commit(paths, message):
|
def commit(paths, message):
|
||||||
import os
|
import os
|
||||||
@@ -438,13 +491,7 @@ class bam_commands:
|
|||||||
# Load project configuration
|
# Load project configuration
|
||||||
cfg = bam_config.load(abort=True)
|
cfg = bam_config.load(abort=True)
|
||||||
|
|
||||||
# TODO(cam) ignore files
|
session_rootdir = bam_config.find_sessiondir(paths[0], abort=True)
|
||||||
|
|
||||||
# TODO(cam) multiple paths
|
|
||||||
session_rootdir = paths[0]
|
|
||||||
|
|
||||||
if not os.path.isdir(session_rootdir):
|
|
||||||
fatal("Expected a directory (%r)" % session_rootdir)
|
|
||||||
|
|
||||||
basedir = bam_config.find_basedir(
|
basedir = bam_config.find_basedir(
|
||||||
cwd=session_rootdir,
|
cwd=session_rootdir,
|
||||||
@@ -462,9 +509,7 @@ class bam_commands:
|
|||||||
session_rootdir)
|
session_rootdir)
|
||||||
|
|
||||||
# make a zipfile from session
|
# make a zipfile from session
|
||||||
import json
|
paths_uuid = bam_session.load_paths_uuid(session_rootdir)
|
||||||
with open(os.path.join(session_rootdir, ".bam_paths_uuid.json")) as f:
|
|
||||||
paths_uuid = json.load(f)
|
|
||||||
|
|
||||||
# No longer used
|
# No longer used
|
||||||
"""
|
"""
|
||||||
@@ -844,6 +889,21 @@ def create_argparse_checkout(subparsers):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def create_argparse_update(subparsers):
|
||||||
|
subparse = subparsers.add_parser(
|
||||||
|
"update", aliases=("up",),
|
||||||
|
help="Update a local session with changes from the remote project",
|
||||||
|
)
|
||||||
|
subparse.add_argument(
|
||||||
|
dest="paths", nargs="*",
|
||||||
|
help="Path(s) to operate on",
|
||||||
|
)
|
||||||
|
subparse.set_defaults(
|
||||||
|
func=lambda args:
|
||||||
|
bam_commands.update(args.paths or ["."]),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def create_argparse_commit(subparsers):
|
def create_argparse_commit(subparsers):
|
||||||
subparse = subparsers.add_parser(
|
subparse = subparsers.add_parser(
|
||||||
"commit", aliases=("ci",),
|
"commit", aliases=("ci",),
|
||||||
@@ -864,22 +924,6 @@ def create_argparse_commit(subparsers):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def create_argparse_update(subparsers):
|
|
||||||
subparse = subparsers.add_parser(
|
|
||||||
"update", aliases=("up",),
|
|
||||||
help="Update a local session with changes from the remote project",
|
|
||||||
)
|
|
||||||
subparse.add_argument(
|
|
||||||
dest="paths", nargs="+",
|
|
||||||
help="Path(s) to operate on",
|
|
||||||
)
|
|
||||||
subparse.set_defaults(
|
|
||||||
func=lambda args:
|
|
||||||
# TODO
|
|
||||||
print(args),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def create_argparse_revert(subparsers):
|
def create_argparse_revert(subparsers):
|
||||||
subparse = subparsers.add_parser(
|
subparse = subparsers.add_parser(
|
||||||
"revert", aliases=("rv",),
|
"revert", aliases=("rv",),
|
||||||
|
@@ -801,6 +801,14 @@ class BamCommitTest(BamSessionTestCase):
|
|||||||
["M", "d_dir/d_subdir/d_nested/d.data"],
|
["M", "d_dir/d_subdir/d_nested/d.data"],
|
||||||
], ret)
|
], ret)
|
||||||
|
|
||||||
|
class BamCheckoutTest(BamSessionTestCase):
|
||||||
|
"""Test for the `bam checkout` command.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, *args):
|
||||||
|
self.init_defaults()
|
||||||
|
super().__init__(*args)
|
||||||
|
|
||||||
def test_checkout(self):
|
def test_checkout(self):
|
||||||
session_name = "mysession"
|
session_name = "mysession"
|
||||||
file_name = "other_file.txt"
|
file_name = "other_file.txt"
|
||||||
@@ -825,6 +833,18 @@ class BamCommitTest(BamSessionTestCase):
|
|||||||
file_data_test = file_quick_read(os.path.join(session_path, file_name))
|
file_data_test = file_quick_read(os.path.join(session_path, file_name))
|
||||||
self.assertEqual(file_data, file_data_test)
|
self.assertEqual(file_data, file_data_test)
|
||||||
|
|
||||||
|
def test_update_blank(self):
|
||||||
|
session_name = "mysession"
|
||||||
|
proj_path, session_path = self.init_session(session_name)
|
||||||
|
stdout, stderr = bam_run(["update"], session_path)
|
||||||
|
# Empty and new session should not update at all
|
||||||
|
self.assertEqual("", stderr)
|
||||||
|
self.assertEqual("Nothing to update!\n", stdout)
|
||||||
|
|
||||||
|
#stdout, stderr = bam_run(["checkout"], session_path)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BamBlendTest(BamSimpleTestCase):
|
class BamBlendTest(BamSimpleTestCase):
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user