Skip to content

Commit

Permalink
fixes root folder creation
Browse files Browse the repository at this point in the history
cleanup, from failed checkout attempt

cleanup

more cleanup

cleanup

cleanup
  • Loading branch information
akotlar committed Apr 6, 2019
1 parent f229798 commit f1bdba0
Show file tree
Hide file tree
Showing 2 changed files with 444 additions and 455 deletions.
12 changes: 5 additions & 7 deletions jgscm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,13 @@ def get(self, path, content=True, type=None, format=None):

@debug_args
def save(self, model, path):
print("model, path", model, path)
if path.startswith("/"):
path = path[1:]
if "type" not in model:
raise web.HTTPError(400, u"No file type provided")
if "content" not in model and model["type"] != "directory":
raise web.HTTPError(400, u"No file content provided")
if "/" not in path and self.default_path:
print("DEFAULT PATH", self.default_path)
path = "%s/%s" % (self.default_path, path)
bucket_name, bucket_path = self._parse_path(path)
if bucket_path == "" and model["type"] != "directory":
Expand Down Expand Up @@ -522,6 +520,10 @@ def _get_bucket(self, name, throw=False):
if throw:
raise
return None
except Forbidden:
if throw or not self.default_path:
raise
return None
cache[name] = bucket
return bucket

Expand Down Expand Up @@ -824,20 +826,16 @@ def _save_file(self, path, content, format):

def _save_directory(self, path, model):
"""Creates a directory in GCS."""
print("PATH IS", path)
exists, obj = self._fetch(path)
print("exists", exists,)
if exists:
if isinstance(obj, Blob):
raise web.HTTPError(400, u"Not a directory: %s" % path)
else:
self.log.debug("Directory %r already exists", path)
return
bucket_name, bucket_path = self._parse_path(path)
print("bucket_name, bucket_path", bucket_name, bucket_path)
if bucket_path == "":
bucket_name = self.bucket

self.client.create_bucket(bucket_name)
else:
bucket = self._get_bucket(bucket_name, throw=True)
bucket.blob(bucket_path).upload_from_string(
Expand Down
Loading

0 comments on commit f1bdba0

Please sign in to comment.