githubtakeout 0.1.17__tar.gz → 0.1.18__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: githubtakeout
3
- Version: 0.1.17
3
+ Version: 0.1.18
4
4
  Summary: Backup and archive Git Repos and Gists from GitHub
5
5
  Author: Corey Goldberg
6
6
  Maintainer: Corey Goldberg
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "githubtakeout"
7
- version = "0.1.17"
7
+ version = "0.1.18"
8
8
  description = "Backup and archive Git Repos and Gists from GitHub"
9
9
  license = "MIT"
10
10
  license-files = ["LICENSE"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: githubtakeout
3
- Version: 0.1.17
3
+ Version: 0.1.18
4
4
  Summary: Backup and archive Git Repos and Gists from GitHub
5
5
  Author: Corey Goldberg
6
6
  Maintainer: Corey Goldberg
@@ -51,27 +51,28 @@ def add_creds(url, username, token):
51
51
  return new_url
52
52
 
53
53
 
54
- def archive(local_repo_dir, archive_format="zip", is_gist=False):
54
+ def archive(local_repo_dir, archive_format="zip", archive_basename=None):
55
55
  if archive_format not in ARCHIVE_FORMATS:
56
56
  raise ValueError(f"{archive_format} is not a valid archive format")
57
57
  if archive_format == "none":
58
58
  return None
59
- base_name = os.path.basename(local_repo_dir)
59
+ basename = os.path.basename(local_repo_dir)
60
60
  extension = "tar.gz" if archive_format == "tar" else archive_format
61
- archive_name = f"{base_name}.{extension}"
62
- if is_gist:
63
- archive_name = f"gist-{archive_name}"
61
+ if archive_basename is None:
62
+ archive_name = f"{basename}.{extension}"
63
+ else:
64
+ archive_name = f"{archive_basename}.{extension}"
64
65
  parent_dir = os.path.dirname(local_repo_dir)
65
66
  archive_path = os.path.join(parent_dir, archive_name)
66
67
  logger.info(f"creating archive: {archive_path}")
67
68
  if archive_format == "tar":
68
69
  with tarfile.open(archive_path, "w:gz") as tar_archive:
69
- tar_archive.add(local_repo_dir, arcname=base_name)
70
+ tar_archive.add(local_repo_dir, arcname=basename)
70
71
  elif archive_format == "zip":
71
72
  with zipfile.ZipFile(archive_path, "w", zipfile.ZIP_DEFLATED) as zip_archive:
72
73
  repo_path = Path(local_repo_dir)
73
74
  for entry in repo_path.rglob("*"):
74
- path = os.path.join(base_name, entry.relative_to(repo_path))
75
+ path = os.path.join(basename, entry.relative_to(repo_path))
75
76
  zip_archive.write(entry, arcname=path)
76
77
  return archive_path
77
78
 
@@ -124,7 +125,7 @@ def pull(local_repo_dir):
124
125
 
125
126
 
126
127
  def get_and_archive_repo(
127
- repo_url, local_repo_dir, archive_format, include_history, keep, is_gist=False
128
+ repo_url, local_repo_dir, archive_format, include_history, keep, description=None
128
129
  ):
129
130
  def remove_readonly(func, path, _):
130
131
  # This is necessary so rmtree() doesn't fail if there are any readonly
@@ -163,7 +164,15 @@ def get_and_archive_repo(
163
164
  shutil.rmtree(git_dir, onexc=remove_readonly)
164
165
  except FileNotFoundError:
165
166
  pass
166
- archive_path = archive(local_repo_dir, archive_format, is_gist)
167
+ if description:
168
+ # clean unsafe chars and truncate description to create a useable file name
169
+ clean_name = re.sub(r"[/\\?%*:|\"<>\x7F\x00-\x1F]", "-", description)[:255]
170
+ archive_basename = f"gist - {clean_name}"
171
+ else:
172
+ archive_basename = None
173
+ archive_path = archive(
174
+ local_repo_dir, archive_format, archive_basename=archive_basename
175
+ )
167
176
  if archive_path:
168
177
  size = convert_size(os.path.getsize(archive_path))
169
178
  logger.info(f"archive size: {size}")
@@ -285,7 +294,7 @@ def run(
285
294
  archive_format,
286
295
  include_history,
287
296
  keep,
288
- is_gist=True,
297
+ description=gist.description,
289
298
  )
290
299
 
291
300
 
File without changes
File without changes
File without changes