githubtakeout 0.1.2__tar.gz → 0.1.3__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.2
3
+ Version: 0.1.3
4
4
  Summary: Archive public Git Repos and Gists from GitHub
5
5
  Author: Corey Goldberg
6
6
  Maintainer: Corey Goldberg
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: githubtakeout
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: Archive public Git Repos and Gists from GitHub
5
5
  Author: Corey Goldberg
6
6
  Maintainer: Corey Goldberg
@@ -56,37 +56,63 @@ def archive(local_repo_dir, archive_format='zip', is_gist=False):
56
56
  return archive_path
57
57
 
58
58
 
59
+ def clone(repo_url, local_repo_dir, include_history):
60
+ try:
61
+ if include_history:
62
+ # full clone
63
+ repo = git.Repo.clone_from(repo_url, local_repo_dir)
64
+ else:
65
+ # shallow clone (no commit history or branches)
66
+ repo = git.Repo.clone_from(repo_url, local_repo_dir, multi_options=['--depth=1'])
67
+ except git.GitCommandError as e:
68
+ logger.error(e)
69
+ sys.exit('Error: failed cloning repo')
70
+ finally:
71
+ try:
72
+ # release resources
73
+ repo.close()
74
+ except UnboundLocalError:
75
+ # this occurs if we catch a signal while cloning
76
+ pass
77
+
78
+
79
+
59
80
  def clone_and_archive_repo(repo_url, local_repo_dir, archive_format, include_history, is_gist=False):
60
81
  def remove_readonly(func, path, _):
61
- # clear the readonly bit and reattempt removal
82
+ # This is necessary so rmtree() doesn't fail if there are any readonly
83
+ # dirs/files when trying to delete. This seems to happen after cloning on
84
+ # Windows. When any error occurs during deletion, we change the permissions
85
+ # and and reattempt removal.
86
+ #
87
+ # give read permissions
88
+ os.chmod(path, stat.S_IREAD)
89
+ # give write permissions
62
90
  os.chmod(path, stat.S_IWRITE)
91
+ # try again
63
92
  func(path)
64
93
  try:
94
+ # delete repo if it already exists
65
95
  shutil.rmtree(local_repo_dir, onexc=remove_readonly)
66
96
  except FileNotFoundError:
67
97
  pass
68
- repo_path = urllib.parse.urlparse(repo_url).path
69
- logger.info(f'cloning repo: {repo_path} to {local_repo_dir}')
98
+ repo_name = urllib.parse.urlparse(repo_url).path.lstrip('/')
99
+ logger.info(f'cloning repo: {repo_name} to {local_repo_dir}')
70
100
  start = default_timer()
71
- try:
72
- if include_history:
73
- git.Repo.clone_from(repo_url, local_repo_dir)
74
- else:
75
- # shallow clone (no commit history or branches)
76
- git.Repo.clone_from(repo_url, local_repo_dir, multi_options=['--depth=1'])
77
- try:
78
- shutil.rmtree(os.path.join(local_repo_dir, '.git'), onexc=remove_readonly)
79
- except FileNotFoundError:
80
- pass
81
- except git.GitCommandError as e:
82
- logger.error(e)
83
- return
101
+ clone(repo_url, local_repo_dir, include_history)
102
+ if not include_history:
103
+ # delete the .git directory if we are not saving history
104
+ try:
105
+ git_dir = os.path.join(local_repo_dir, '.git')
106
+ shutil.rmtree(git_dir, onexc=remove_readonly)
107
+ except FileNotFoundError:
108
+ pass
84
109
  archive_path = archive(local_repo_dir, archive_format, is_gist)
85
110
  size_kb = os.path.getsize(archive_path) / 1024
86
111
  logger.info(f'archive size: {size_kb:.2f} KB')
87
112
  logger.info('deleting repo')
88
113
  try:
89
- shutil.rmtree(local_repo_dir)
114
+ # delete repo after archive is created
115
+ shutil.rmtree(local_repo_dir, onexc=remove_readonly)
90
116
  except FileNotFoundError:
91
117
  pass
92
118
  elapsed = default_timer() - start
@@ -215,15 +241,18 @@ def main():
215
241
  help='prompt for auth token'
216
242
  )
217
243
  args = parser.parse_args()
218
- run(
219
- username=args.username,
220
- base_dir=args.dir,
221
- archive_format=args.format,
222
- include_gists=args.gists,
223
- include_history=args.history,
224
- list_only=args.list,
225
- prompt_token=args.token
226
- )
244
+ try:
245
+ run(
246
+ username=args.username,
247
+ base_dir=args.dir,
248
+ archive_format=args.format,
249
+ include_gists=args.gists,
250
+ include_history=args.history,
251
+ list_only=args.list,
252
+ prompt_token=args.token
253
+ )
254
+ except KeyboardInterrupt:
255
+ sys.exit('\nexiting program ...')
227
256
 
228
257
 
229
258
  if __name__ == '__main__':
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "githubtakeout"
7
- version = "0.1.2"
7
+ version = "0.1.3"
8
8
  description = "Archive public Git Repos and Gists from GitHub"
9
9
  license = "MIT"
10
10
  license-files = ["LICENSE"]
File without changes
File without changes
File without changes