FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python/bin/githelp.py at patch-1 · ioload/python · GitHub
ioload
python
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python
/
bin
/
githelp.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
39 lines (30 loc) · 1.03 KB
Breadcrumbs
python
/
bin
/
githelp.py
Copy path
File metadata and controls
39 lines (30 loc) · 1.03 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
from
contextlib
import
contextmanager
from
enum
import
Enum
from
pathlib
import
Path
import
shutil
import
subprocess
from
typing
import
Iterator
,
Union
GITHUB_EXERCISM
=
f"https://github.com/exercism"
class
Repo
(
Enum
):
ProblemSpecifications
=
f"
{
GITHUB_EXERCISM
}
/problem-specifications.git"
def
clone
(
repo
:
Union
[
str
,
Repo
],
directory
:
Union
[
str
,
Path
,
None
]
=
None
)
->
bool
:
if
isinstance
(
repo
,
Repo
):
repo
=
repo
.
value
if
directory
is
None
:
directory
=
repo
.
split
(
"/"
)[
-
1
].
split
(
"."
)[
0
]
directory
=
Path
(
directory
)
if
not
directory
.
is_dir
():
try
:
subprocess
.
run
([
"git"
,
"clone"
,
repo
,
str
(
directory
)],
check
=
True
)
return
True
except
subprocess
.
CalledProcessError
:
pass
return
False
@
contextmanager
def
clone_if_missing
(
repo
:
Union
[
str
,
Repo
],
directory
:
Union
[
str
,
Path
,
None
]
=
None
)
->
Iterator
[
None
]:
temp_clone
=
clone
(
repo
,
directory
)
try
:
yield
directory
finally
:
if
temp_clone
:
shutil
.
rmtree
(
directory
)
Back
|
FazBrowse Home
|
New Git URL