File size: 1,372 Bytes
c893d6c
 
 
76cb82a
c893d6c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76cb82a
c893d6c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76cb82a
 
 
 
 
 
 
 
 
 
 
 
c893d6c
76cb82a
 
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
import os
import shutil
import subprocess
import warnings
from pathlib import Path


COMMON_FILES = ['.git', 'README.md', __file__.split('/')[-1]]


def remove_old_files():
    filenames = os.listdir('./')
    filenames = [f for f in filenames if f not in COMMON_FILES]
    for file_path in filenames:
        p = Path(file_path)
        if p.exists():
            if p.is_file():
                p.unlink()
            elif p.is_dir():
                shutil.rmtree(p)


def clone_repository():
    repo_url = 'https://github.com/KonradSzafer/hugging-face-qa-bot.git'
    subprocess.run(['git', 'clone', '--depth', '1', repo_url])


def copy_files():
    src = './hugging-face-qa-bot'
    for item in COMMON_FILES:
        full_path = os.path.join(src, item)
        if os.path.isfile(full_path):
            os.remove(full_path)
        elif os.path.isdir(full_path):
            shutil.rmtree(full_path)
    for item in Path(src).iterdir():
        shutil.move(str(item), '.')
    shutil.rmtree(src)


def main():
    path = os.getcwd().lower()
    current_dir = path.split('/')[-1]
    if current_dir != 'hugging-face-qa-bot':
        print('Updating the HF space...')
        remove_old_files()
        clone_repository()
        copy_files()
    else:
        warnings.warn('You are in the hugging-face-qa-bot reposotory')


if __name__ == '__main__':
    main()