Root path parameter for cloning
This commit is contained in:
parent
64321043b7
commit
10772a704e
2 changed files with 14 additions and 5 deletions
|
@ -522,7 +522,7 @@ class Site(object):
|
||||||
return len(published)
|
return len(published)
|
||||||
|
|
||||||
# Copy this site
|
# Copy this site
|
||||||
def clone(self, address, privatekey=None, address_index=None, overwrite=False):
|
def clone(self, address, privatekey=None, address_index=None, root_inner_path="", overwrite=False):
|
||||||
import shutil
|
import shutil
|
||||||
new_site = SiteManager.site_manager.need(address, all_file=False)
|
new_site = SiteManager.site_manager.need(address, all_file=False)
|
||||||
default_dirs = [] # Dont copy these directories (has -default version)
|
default_dirs = [] # Dont copy these directories (has -default version)
|
||||||
|
@ -530,7 +530,7 @@ class Site(object):
|
||||||
if "-default" in dir_name:
|
if "-default" in dir_name:
|
||||||
default_dirs.append(dir_name.replace("-default", ""))
|
default_dirs.append(dir_name.replace("-default", ""))
|
||||||
|
|
||||||
self.log.debug("Cloning to %s, ignore dirs: %s" % (address, default_dirs))
|
self.log.debug("Cloning to %s, ignore dirs: %s, root: %s" % (address, default_dirs, root_inner_path))
|
||||||
|
|
||||||
# Copy root content.json
|
# Copy root content.json
|
||||||
if not new_site.storage.isFile("content.json") and not overwrite:
|
if not new_site.storage.isFile("content.json") and not overwrite:
|
||||||
|
@ -540,6 +540,7 @@ class Site(object):
|
||||||
del content_json["domain"]
|
del content_json["domain"]
|
||||||
content_json["title"] = "my" + content_json["title"]
|
content_json["title"] = "my" + content_json["title"]
|
||||||
content_json["cloned_from"] = self.address
|
content_json["cloned_from"] = self.address
|
||||||
|
content_json["clone_root"] = root_inner_path
|
||||||
content_json["files"] = {}
|
content_json["files"] = {}
|
||||||
if address_index:
|
if address_index:
|
||||||
content_json["address_index"] = address_index # Site owner's BIP32 index
|
content_json["address_index"] = address_index # Site owner's BIP32 index
|
||||||
|
@ -553,13 +554,21 @@ class Site(object):
|
||||||
for file_relative_path in sorted(content["files"].keys()):
|
for file_relative_path in sorted(content["files"].keys()):
|
||||||
file_inner_path = helper.getDirname(content_inner_path) + file_relative_path # Relative to content.json
|
file_inner_path = helper.getDirname(content_inner_path) + file_relative_path # Relative to content.json
|
||||||
file_inner_path = file_inner_path.strip("/") # Strip leading /
|
file_inner_path = file_inner_path.strip("/") # Strip leading /
|
||||||
|
if not file_inner_path.startswith(root_inner_path):
|
||||||
|
self.log.debug("[SKIP] %s (not in clone root)" % file_inner_path)
|
||||||
|
continue
|
||||||
if file_inner_path.split("/")[0] in default_dirs: # Dont copy directories that has -default postfixed alternative
|
if file_inner_path.split("/")[0] in default_dirs: # Dont copy directories that has -default postfixed alternative
|
||||||
self.log.debug("[SKIP] %s (has default alternative)" % file_inner_path)
|
self.log.debug("[SKIP] %s (has default alternative)" % file_inner_path)
|
||||||
continue
|
continue
|
||||||
file_path = self.storage.getPath(file_inner_path)
|
file_path = self.storage.getPath(file_inner_path)
|
||||||
|
|
||||||
# Copy the file normally to keep the -default postfixed dir and file to allow cloning later
|
# Copy the file normally to keep the -default postfixed dir and file to allow cloning later
|
||||||
|
if root_inner_path:
|
||||||
|
file_inner_path_dest = re.sub("^%s" % re.escape(root_inner_path), "", file_inner_path)
|
||||||
|
file_path_dest = new_site.storage.getPath(file_inner_path_dest)
|
||||||
|
else:
|
||||||
file_path_dest = new_site.storage.getPath(file_inner_path)
|
file_path_dest = new_site.storage.getPath(file_inner_path)
|
||||||
|
|
||||||
self.log.debug("[COPY] %s to %s..." % (file_inner_path, file_path_dest))
|
self.log.debug("[COPY] %s to %s..." % (file_inner_path, file_path_dest))
|
||||||
dest_dir = os.path.dirname(file_path_dest)
|
dest_dir = os.path.dirname(file_path_dest)
|
||||||
if not os.path.isdir(dest_dir):
|
if not os.path.isdir(dest_dir):
|
||||||
|
|
|
@ -681,12 +681,12 @@ class UiWebsocket(object):
|
||||||
else:
|
else:
|
||||||
self.response(to, {"error": "Unknown site: %s" % address})
|
self.response(to, {"error": "Unknown site: %s" % address})
|
||||||
|
|
||||||
def actionSiteClone(self, to, address):
|
def actionSiteClone(self, to, address, root_inner_path=""):
|
||||||
self.cmd("notification", ["info", "Cloning site..."])
|
self.cmd("notification", ["info", "Cloning site..."])
|
||||||
site = self.server.sites.get(address)
|
site = self.server.sites.get(address)
|
||||||
# Generate a new site from user's bip32 seed
|
# Generate a new site from user's bip32 seed
|
||||||
new_address, new_address_index, new_site_data = self.user.getNewSiteData()
|
new_address, new_address_index, new_site_data = self.user.getNewSiteData()
|
||||||
new_site = site.clone(new_address, new_site_data["privatekey"], address_index=new_address_index)
|
new_site = site.clone(new_address, new_site_data["privatekey"], address_index=new_address_index, root_inner_path=root_inner_path)
|
||||||
new_site.settings["own"] = True
|
new_site.settings["own"] = True
|
||||||
new_site.saveSettings()
|
new_site.saveSettings()
|
||||||
self.cmd("notification", ["done", _["Site cloned"] + "<script>window.top.location = '/%s'</script>" % new_address])
|
self.cmd("notification", ["done", _["Site cloned"] + "<script>window.top.location = '/%s'</script>" % new_address])
|
||||||
|
|
Loading…
Reference in a new issue