Skip to content

Commit

Permalink
add option to export all sites to besapi and bescli
Browse files Browse the repository at this point in the history
  • Loading branch information
jgstew committed Feb 10, 2022
1 parent 6a67940 commit 36c1397
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/besapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

from . import besapi

__version__ = "1.1.1"
__version__ = "1.1.2"
18 changes: 18 additions & 0 deletions src/besapi/besapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ def export_site_contents(
print("export_site_contents()")
# Iterate Over All Site Content
content = self.get("site/" + site_path + "/content")
if verbose:
print(content)
if content.request.status_code == 200:
print(
"Archiving %d items from %s..." % (content().countchildren(), site_path)
Expand Down Expand Up @@ -251,6 +253,22 @@ def export_site_contents(
) as bes_file:
bes_file.write(content.text.encode("utf-8"))

def export_all_sites(
self, include_external=False, export_folder="./", name_trim=70, verbose=False
):
"""export all bigfix sites to a folder"""
results_sites = self.get("sites")
if verbose:
print(results_sites)
if results_sites.request.status_code == 200:
for item in results_sites().iterchildren():
site_path = item.attrib["Resource"].split("/api/site/", 1)[1]
if include_external or "external/" not in site_path:
print("Exporting Site:", site_path)
self.export_site_contents(
site_path, export_folder, name_trim, verbose
)

__call__ = login
# https://stackoverflow.com/q/40536821/861745
__enter__ = login
Expand Down
4 changes: 4 additions & 0 deletions src/bescli/bescli.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ def do_export_site(self, site_path):
"""export site contents to current folder"""
self.bes_conn.export_site_contents(site_path, verbose=True)

def do_export_all_sites(self, statement=None):
"""export site contents to current folder"""
self.bes_conn.export_all_sites(verbose=False)

complete_upload = Cmd.path_complete

def do_upload(self, file_path):
Expand Down
3 changes: 2 additions & 1 deletion tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
# set working directory to src folder in parent folder
os.chdir("../src")

# Test file upload: print(bigfix_cli.bes_conn.upload("./besapi/__init__.py", "test_file.txt"))
# Test file upload:
print(bigfix_cli.bes_conn.upload("./besapi/__init__.py", "test_besapi_upload.txt"))

if os.name == "nt":
subprocess.run(
Expand Down

0 comments on commit 36c1397

Please sign in to comment.