FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-github-backup/github_backup/cli.py at 0.63.0 · josegonzalez/python-github-backup · GitHub
josegonzalez
/
python-github-backup
Public
Notifications
You must be signed in to change notification settings
Fork
264
Star
1.6k
Code
Issues
5
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
python-github-backup
/
github_backup
/
cli.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
92 lines (74 loc) · 2.83 KB
Breadcrumbs
python-github-backup
/
github_backup
/
cli.py
Copy path
File metadata and controls
92 lines (74 loc) · 2.83 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
"""Command-line interface for github-backup."""
import
logging
import
os
import
sys
from
github_backup
.
github_backup
import
(
backup_account
,
backup_repositories
,
check_git_lfs_install
,
filter_repositories
,
get_auth
,
get_authenticated_user
,
logger
,
mkdir_p
,
parse_args
,
retrieve_repositories
,
)
# INFO and DEBUG go to stdout, WARNING and above go to stderr
log_format
=
logging
.
Formatter
(
fmt
=
"%(asctime)s.%(msecs)03d: %(message)s"
,
datefmt
=
"%Y-%m-%dT%H:%M:%S"
,
)
stdout_handler
=
logging
.
StreamHandler
(
sys
.
stdout
)
stdout_handler
.
setLevel
(
logging
.
DEBUG
)
stdout_handler
.
addFilter
(
lambda
r
:
r
.
levelno
<
logging
.
WARNING
)
stdout_handler
.
setFormatter
(
log_format
)
stderr_handler
=
logging
.
StreamHandler
(
sys
.
stderr
)
stderr_handler
.
setLevel
(
logging
.
WARNING
)
stderr_handler
.
setFormatter
(
log_format
)
logging
.
basicConfig
(
level
=
logging
.
INFO
,
handlers
=
[
stdout_handler
,
stderr_handler
])
def
main
():
"""Main entry point for github-backup CLI."""
args
=
parse_args
()
if
args
.
private
and
not
get_auth
(
args
):
logger
.
warning
(
"The --private flag has no effect without authentication. "
"Use -t/--token or -f/--token-fine to authenticate."
)
# Issue #477: Fine-grained PATs cannot download all attachment types from
# private repos. Image attachments will be retried via Markdown API workaround.
if
args
.
include_attachments
and
args
.
token_fine
:
logger
.
warning
(
"Using --attachments with fine-grained token. Due to GitHub platform "
"limitations, file attachments (PDFs, etc.) from private repos may fail. "
"Image attachments will be retried via workaround. For full attachment "
"support, use --token-classic instead."
)
if
args
.
quiet
:
logger
.
setLevel
(
logging
.
WARNING
)
output_directory
=
os
.
path
.
realpath
(
args
.
output_directory
)
if
not
os
.
path
.
isdir
(
output_directory
):
logger
.
info
(
"Create output directory {0}"
.
format
(
output_directory
))
mkdir_p
(
output_directory
)
if
args
.
lfs_clone
:
check_git_lfs_install
()
if
args
.
log_level
:
log_level
=
logging
.
getLevelName
(
args
.
log_level
.
upper
())
if
isinstance
(
log_level
,
int
):
logger
.
root
.
setLevel
(
log_level
)
if
not
args
.
as_app
:
logger
.
info
(
"Backing up user {0} to {1}"
.
format
(
args
.
user
,
output_directory
))
authenticated_user
=
get_authenticated_user
(
args
)
else
:
authenticated_user
=
{
"login"
:
None
}
repositories
=
retrieve_repositories
(
args
,
authenticated_user
)
repositories
=
filter_repositories
(
args
,
repositories
)
backup_repositories
(
args
,
output_directory
,
repositories
)
backup_account
(
args
,
output_directory
)
if
__name__
==
"__main__"
:
try
:
main
()
except
Exception
as
e
:
logger
.
error
(
str
(
e
))
sys
.
exit
(
1
)
Back
|
FazBrowse Home
|
New Git URL