lukhed-basic-utils 1.4.2__tar.gz → 1.4.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/PKG-INFO +1 -1
  2. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/lukhed_basic_utils/githubCommon.py +61 -0
  3. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/lukhed_basic_utils.egg-info/PKG-INFO +1 -1
  4. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/setup.py +1 -1
  5. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/LICENSE +0 -0
  6. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/README.md +0 -0
  7. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/lukhed_basic_utils/__init__.py +0 -0
  8. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/lukhed_basic_utils/chartJsCommon.py +0 -0
  9. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/lukhed_basic_utils/classCommon.py +0 -0
  10. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/lukhed_basic_utils/fileCommon.py +0 -0
  11. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/lukhed_basic_utils/listWorkCommon.py +0 -0
  12. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/lukhed_basic_utils/mathCommon.py +0 -0
  13. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/lukhed_basic_utils/osCommon.py +0 -0
  14. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/lukhed_basic_utils/requestsCommon.py +0 -0
  15. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/lukhed_basic_utils/stringCommon.py +0 -0
  16. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/lukhed_basic_utils/timeCommon.py +0 -0
  17. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/lukhed_basic_utils.egg-info/SOURCES.txt +0 -0
  18. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/lukhed_basic_utils.egg-info/dependency_links.txt +0 -0
  19. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/lukhed_basic_utils.egg-info/requires.txt +0 -0
  20. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/lukhed_basic_utils.egg-info/top_level.txt +0 -0
  21. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/setup.cfg +0 -0
  22. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/tests/test_osCommon.py +0 -0
  23. {lukhed_basic_utils-1.4.2 → lukhed_basic_utils-1.4.4}/tests/test_timeCommon.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lukhed_basic_utils
3
- Version: 1.4.2
3
+ Version: 1.4.4
4
4
  Summary: A collection of basic utility functions
5
5
  Home-page: https://github.com/lukhed/lukhed_basic_utils
6
6
  Author: lukhed
@@ -1,10 +1,14 @@
1
1
  from lukhed_basic_utils import osCommon as osC
2
2
  from lukhed_basic_utils import fileCommon as fC
3
+ from lukhed_basic_utils import requestsCommon as rC
4
+ from lukhed_basic_utils import timeCommon as tC
3
5
  from github import Github
4
6
  from github.Repository import Repository
5
7
  from github.GithubException import UnknownObjectException
6
8
  import json
7
9
  from typing import Optional
10
+ import zipfile
11
+ import shutil
8
12
 
9
13
 
10
14
  class GithubHelper:
@@ -469,6 +473,63 @@ class GithubHelper:
469
473
  return False
470
474
  else:
471
475
  return True
476
+
477
+ def download_repository(self, download_dir, extract=False, rename_internal_folder=True):
478
+ """
479
+ Downloads the repository archive as a ZIP file into the specified download directory.
480
+ If 'extract' is True, the archive will be extracted into a subdirectory of download_dir.
481
+
482
+ :param download_dir: The directory where the archive should be saved.
483
+ :param extract: Boolean flag to extract the archive after download.
484
+ :param rename_internal_folder: Bool to rename the internal folder to repo name
485
+ :return: Dl path if download (and extraction, if requested) succeeded, otherwise None.
486
+ """
487
+
488
+ # Choose archive format and ref (default branch in this example)
489
+ archive_format = "zipball"
490
+
491
+ # Get the temporary archive URL for the repo
492
+ dl_url = self.repo.get_archive_link(archive_format)
493
+
494
+ # Construct a filename for the archive, e.g., "username_reponame_defaultbranch.zip"
495
+ dl_ts = tC.create_timestamp('%Y%m%d')
496
+ safe_repo_name = self.repo.full_name.replace("/", "_")
497
+ archive_filename = f"{safe_repo_name}_{dl_ts}.zip"
498
+ download_path = osC.append_to_dir(download_dir, archive_filename)
499
+
500
+ # Make the HTTP request using your custom make_request() function
501
+ response = rC.make_request(dl_url)
502
+
503
+ if response.status_code == 200:
504
+ # Write the binary content to the download file
505
+ with open(download_path, "wb") as file:
506
+ file.write(response.content)
507
+
508
+ if extract:
509
+ # Define an extraction directory (same name as archive file without the .zip extension)
510
+ extraction_dir = osC.append_to_dir(download_dir, f"{safe_repo_name}_{dl_ts}")
511
+ osC.check_create_dir_structure(extraction_dir, full_path=True)
512
+ try:
513
+ with zipfile.ZipFile(download_path, "r") as zip_ref:
514
+ zip_ref.extractall(extraction_dir)
515
+ except zipfile.BadZipFile:
516
+ print("Error: The downloaded file is not a valid zip archive.")
517
+ return None
518
+
519
+ if rename_internal_folder:
520
+ new_name = osC.append_to_dir(extraction_dir, self.repo.name)
521
+ gh_dir = osC.return_immediate_child_dirs_given_dir(extraction_dir)[0]
522
+ shutil.move(gh_dir, new_name)
523
+
524
+ return extraction_dir
525
+
526
+ return download_path
527
+ else:
528
+ print(f"Failed to download repository. HTTP status code: {response.status_code}")
529
+ return None
530
+
531
+
532
+
472
533
 
473
534
 
474
535
  class KeyManager(GithubHelper):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lukhed-basic-utils
3
- Version: 1.4.2
3
+ Version: 1.4.4
4
4
  Summary: A collection of basic utility functions
5
5
  Home-page: https://github.com/lukhed/lukhed_basic_utils
6
6
  Author: lukhed
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="lukhed_basic_utils",
5
- version="1.4.2",
5
+ version="1.4.4",
6
6
  description="A collection of basic utility functions",
7
7
  long_description=open("README.md").read(),
8
8
  long_description_content_type="text/markdown",