Spaces:
Paused
Paused
Commit
·
c893d6c
1
Parent(s):
52393bf
update space based on github repo
Browse files- update_space.py +43 -0
update_space.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
+
import subprocess
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
COMMON_FILES = ['.git', 'README.md', __file__.split('/')[-1]]
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def remove_old_files():
|
| 11 |
+
filenames = os.listdir('./')
|
| 12 |
+
filenames = [f for f in filenames if f not in COMMON_FILES]
|
| 13 |
+
for file_path in filenames:
|
| 14 |
+
p = Path(file_path)
|
| 15 |
+
if p.exists():
|
| 16 |
+
if p.is_file():
|
| 17 |
+
p.unlink()
|
| 18 |
+
elif p.is_dir():
|
| 19 |
+
shutil.rmtree(p)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def clone_repository():
|
| 23 |
+
repo_url = 'https://github.com/KonradSzafer/hugging-face-qa-bot.git'
|
| 24 |
+
subprocess.run(['git', 'clone', repo_url])
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def copy_files():
|
| 28 |
+
src = './hugging-face-qa-bot'
|
| 29 |
+
for item in COMMON_FILES:
|
| 30 |
+
full_path = os.path.join(src, item)
|
| 31 |
+
if os.path.isfile(full_path):
|
| 32 |
+
os.remove(full_path)
|
| 33 |
+
elif os.path.isdir(full_path):
|
| 34 |
+
shutil.rmtree(full_path)
|
| 35 |
+
for item in Path(src).iterdir():
|
| 36 |
+
shutil.move(str(item), '.')
|
| 37 |
+
shutil.rmtree(src)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
if __name__ == '__main__':
|
| 41 |
+
remove_old_files()
|
| 42 |
+
clone_repository()
|
| 43 |
+
copy_files()
|