bam cli: add ability to checkout into a named location
This commit is contained in:
@@ -316,22 +316,27 @@ class bam_commands:
|
|||||||
|
|
||||||
print("Session %r created" % session_name)
|
print("Session %r created" % session_name)
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def checkout(paths):
|
def checkout(path, output_dir=None):
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
cfg = bam_config.load(abort=True)
|
cfg = bam_config.load(abort=True)
|
||||||
|
|
||||||
# TODO(cam) multiple paths
|
if output_dir is None:
|
||||||
path = paths[0]
|
# fallback to the basename
|
||||||
del paths
|
dst_dir = os.path.splitext(os.path.basename(path))[0]
|
||||||
|
else:
|
||||||
# TODO(cam) we may want to checkout a single file? how to handle this?
|
if os.sep in output_dir.rstrip(os.sep):
|
||||||
# we may want to checkout a dir too
|
# are we a subdirectory?
|
||||||
dst_dir = os.path.splitext(os.path.basename(path))[0]
|
# (we know this exists, since we have config already)
|
||||||
|
rootdir = bam_config.find_rootdir(abort=True)
|
||||||
|
if ".." in os.path.relpath(output_dir, rootdir).split(os.sep):
|
||||||
|
fatal("Output %r is outside the project path %r" % (output_dir, rootdir))
|
||||||
|
del rootdir
|
||||||
|
dst_dir = output_dir
|
||||||
|
del output_dir
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
"filepath": path,
|
"filepath": path,
|
||||||
@@ -409,8 +414,7 @@ class bam_commands:
|
|||||||
session_rootdir = paths[0]
|
session_rootdir = paths[0]
|
||||||
|
|
||||||
if not os.path.isdir(session_rootdir):
|
if not os.path.isdir(session_rootdir):
|
||||||
print("Expected a directory (%r)" % session_rootdir)
|
fatal("Expected a directory (%r)" % session_rootdir)
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
basedir = bam_config.find_basedir(
|
basedir = bam_config.find_basedir(
|
||||||
cwd=session_rootdir,
|
cwd=session_rootdir,
|
||||||
@@ -641,7 +645,7 @@ def subcommand_create_cb(args):
|
|||||||
|
|
||||||
|
|
||||||
def subcommand_checkout_cb(args):
|
def subcommand_checkout_cb(args):
|
||||||
bam_commands.checkout(args.paths)
|
bam_commands.checkout(args.path, args.output)
|
||||||
|
|
||||||
|
|
||||||
def subcommand_commit_cb(args):
|
def subcommand_commit_cb(args):
|
||||||
@@ -706,8 +710,12 @@ def create_argparse_checkout(subparsers):
|
|||||||
help="",
|
help="",
|
||||||
)
|
)
|
||||||
subparse.add_argument(
|
subparse.add_argument(
|
||||||
dest="paths", nargs="+",
|
dest="path", type=str, metavar='REMOTE_PATH',
|
||||||
help="Path(s) to operate on",
|
help="Path to checkout on the server",
|
||||||
|
)
|
||||||
|
subparse.add_argument(
|
||||||
|
"-o", "--output",dest="output", type=str, metavar='DIRNAME',
|
||||||
|
help="Local name to checkout the session into (optional, falls back to path name)",
|
||||||
)
|
)
|
||||||
subparse.set_defaults(func=subcommand_checkout_cb)
|
subparse.set_defaults(func=subcommand_checkout_cb)
|
||||||
|
|
||||||
|
@@ -39,7 +39,6 @@ def create_image_single(deps):
|
|||||||
image.save()
|
image.save()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import sys
|
import sys
|
||||||
blendfile, blendfile_deps_json, create_id, returncode = sys.argv[-4:]
|
blendfile, blendfile_deps_json, create_id, returncode = sys.argv[-4:]
|
||||||
|
@@ -574,6 +574,7 @@ class BamCommitTest(BamSessionTestCase):
|
|||||||
|
|
||||||
def test_commit(self):
|
def test_commit(self):
|
||||||
self.init_repo()
|
self.init_repo()
|
||||||
|
file_name = "testfile.txt"
|
||||||
file_data = b"hello world!\n"
|
file_data = b"hello world!\n"
|
||||||
|
|
||||||
proj_path = os.path.join(self.path_local_store, self.proj_name)
|
proj_path = os.path.join(self.path_local_store, self.proj_name)
|
||||||
@@ -589,13 +590,14 @@ class BamCommitTest(BamSessionTestCase):
|
|||||||
self.assertEqual("Nothing to commit!\n", stdout)
|
self.assertEqual("Nothing to commit!\n", stdout)
|
||||||
|
|
||||||
# now do a real commit
|
# now do a real commit
|
||||||
file_quick_write(session_path, "testfile.txt", file_data)
|
file_quick_write(session_path, file_name, file_data)
|
||||||
stdout, stderr = bam_run(["commit", "-m", "test message"], session_path)
|
stdout, stderr = bam_run(["commit", "-m", "test message"], session_path)
|
||||||
self.assertEqual("", stderr)
|
self.assertEqual("", stderr)
|
||||||
|
|
||||||
def test_checkout(self):
|
def test_checkout(self):
|
||||||
self.init_repo()
|
self.init_repo()
|
||||||
file_data = b"hello world!\n"
|
file_data = b"yo world!\n"
|
||||||
|
file_name = "other_file.txt"
|
||||||
|
|
||||||
proj_path = os.path.join(self.path_local_store, self.proj_name)
|
proj_path = os.path.join(self.path_local_store, self.proj_name)
|
||||||
co_id = "mysession"
|
co_id = "mysession"
|
||||||
@@ -605,7 +607,7 @@ class BamCommitTest(BamSessionTestCase):
|
|||||||
self.assertEqual("", stderr)
|
self.assertEqual("", stderr)
|
||||||
|
|
||||||
# now do a real commit
|
# now do a real commit
|
||||||
file_quick_write(session_path, "testfile.txt", file_data)
|
file_quick_write(session_path, file_name, file_data)
|
||||||
stdout, stderr = bam_run(["commit", "-m", "test message"], session_path)
|
stdout, stderr = bam_run(["commit", "-m", "test message"], session_path)
|
||||||
self.assertEqual("", stderr)
|
self.assertEqual("", stderr)
|
||||||
|
|
||||||
@@ -613,12 +615,12 @@ class BamCommitTest(BamSessionTestCase):
|
|||||||
shutil.rmtree(session_path)
|
shutil.rmtree(session_path)
|
||||||
|
|
||||||
# checkout the file again
|
# checkout the file again
|
||||||
stdout, stderr = bam_run(["checkout", "testfile.txt"], proj_path)
|
stdout, stderr = bam_run(["checkout", file_name, "--output", session_path], proj_path)
|
||||||
self.assertEqual("", stderr)
|
self.assertEqual("", stderr)
|
||||||
# wait_for_input()
|
# wait_for_input()
|
||||||
self.assertTrue(os.path.exists(os.path.join(proj_path, "testfile/testfile.txt")))
|
self.assertTrue(os.path.exists(os.path.join(session_path, file_name)))
|
||||||
|
|
||||||
file_data_test = file_quick_read(os.path.join(proj_path, "testfile/testfile.txt"))
|
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)
|
||||||
|
|
||||||
|
|
||||||
@@ -666,7 +668,8 @@ class BamBlendTest(BamSimpleTestCase):
|
|||||||
shutil.rmtree(TEMP_SESSION)
|
shutil.rmtree(TEMP_SESSION)
|
||||||
|
|
||||||
def test_empty(self):
|
def test_empty(self):
|
||||||
blendfile = os.path.join(TEMP, "test.blend")
|
file_name = "testfile.blend"
|
||||||
|
blendfile = os.path.join(TEMP, file_name)
|
||||||
if not blendfile_template_create(blendfile, "create_blank", []):
|
if not blendfile_template_create(blendfile, "create_blank", []):
|
||||||
self.fail("blend file couldn't be created")
|
self.fail("blend file couldn't be created")
|
||||||
return
|
return
|
||||||
@@ -674,7 +677,6 @@ class BamBlendTest(BamSimpleTestCase):
|
|||||||
self.assertTrue(os.path.exists(blendfile))
|
self.assertTrue(os.path.exists(blendfile))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BamDeleteTest(BamSessionTestCase):
|
class BamDeleteTest(BamSessionTestCase):
|
||||||
"""Test for the `bam commit` command when files are being deleted.
|
"""Test for the `bam commit` command when files are being deleted.
|
||||||
"""
|
"""
|
||||||
@@ -685,6 +687,7 @@ class BamDeleteTest(BamSessionTestCase):
|
|||||||
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
self.init_repo()
|
self.init_repo()
|
||||||
|
file_name = "testfile.blend"
|
||||||
file_data = b"hello world!\n"
|
file_data = b"hello world!\n"
|
||||||
|
|
||||||
proj_path = os.path.join(self.path_local_store, self.proj_name)
|
proj_path = os.path.join(self.path_local_store, self.proj_name)
|
||||||
@@ -695,8 +698,7 @@ class BamDeleteTest(BamSessionTestCase):
|
|||||||
self.assertEqual("", stderr)
|
self.assertEqual("", stderr)
|
||||||
|
|
||||||
# now do a real commit
|
# now do a real commit
|
||||||
returncode_test = 42
|
blendfile = os.path.join(session_path, file_name)
|
||||||
blendfile = os.path.join(session_path, "testfile.blend")
|
|
||||||
if not blendfile_template_create(blendfile, "create_blank", []):
|
if not blendfile_template_create(blendfile, "create_blank", []):
|
||||||
self.fail("blend file couldn't be created")
|
self.fail("blend file couldn't be created")
|
||||||
return
|
return
|
||||||
@@ -712,13 +714,13 @@ class BamDeleteTest(BamSessionTestCase):
|
|||||||
# New Session
|
# New Session
|
||||||
|
|
||||||
# checkout the file again
|
# checkout the file again
|
||||||
stdout, stderr = bam_run(["checkout", "testfile.blend"], proj_path)
|
stdout, stderr = bam_run(["checkout", file_name, "--output", "new_out"], proj_path)
|
||||||
self.assertEqual("", stderr)
|
self.assertEqual("", stderr)
|
||||||
|
|
||||||
|
|
||||||
# now delete the file we just checked out
|
# now delete the file we just checked out
|
||||||
session_path = os.path.join(proj_path, "testfile")
|
session_path = os.path.join(proj_path, "new_out")
|
||||||
os.remove(os.path.join(session_path, "testfile.blend"))
|
os.remove(os.path.join(session_path, file_name))
|
||||||
stdout, stderr = bam_run(["commit", "-m", "test deletion"], session_path)
|
stdout, stderr = bam_run(["commit", "-m", "test deletion"], session_path)
|
||||||
self.assertEqual("", stderr)
|
self.assertEqual("", stderr)
|
||||||
# check if deletion of the file has happened
|
# check if deletion of the file has happened
|
||||||
@@ -732,7 +734,7 @@ class BamDeleteTest(BamSessionTestCase):
|
|||||||
listing = json.loads(stdout)
|
listing = json.loads(stdout)
|
||||||
print(listing)
|
print(listing)
|
||||||
for e in listing:
|
for e in listing:
|
||||||
self.assertNotEqual(e[0], "testfile.txt")
|
self.assertNotEqual(e[0], file_name)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Reference in New Issue
Block a user