|
1 | 1 | import os
|
2 | 2 | import sys
|
3 | 3 | import argparse
|
4 |
| -import utils |
| 4 | +import subprocess |
5 | 5 |
|
6 | 6 | #Functions
|
| 7 | + |
| 8 | +# Clear the terminal |
| 9 | +def clear_screen(): |
| 10 | + if os.name == 'nt': |
| 11 | + os.system('cls') |
| 12 | + else: |
| 13 | + os.system('clear') |
| 14 | +# end of clear_screen |
| 15 | + |
| 16 | +#install_dom function |
| 17 | +def install_dom(dpath): |
| 18 | + os.chdir(dpath) |
| 19 | + os.getcwd() |
| 20 | + #subprocess call to install libraries |
| 21 | + subprocess.call([sys.executable, "-m", "pip", "install", "-U", "-r", "requirements.txt"]) |
| 22 | +#End of install_dom |
| 23 | + |
7 | 24 | #Path to domains folder
|
8 | 25 | def domainPath():
|
9 |
| - |
10 | 26 | abs_path = os.path.abspath(__file__)
|
11 | 27 | fileDir = os.path.dirname(abs_path)
|
12 | 28 | path = os.path.join(fileDir, 'Domains')
|
13 | 29 | print(path)
|
14 | 30 | return path
|
15 | 31 | #end of domainPath
|
16 | 32 |
|
17 |
| -# check for command line arguments |
18 |
| -def check_args(args=None): |
19 |
| - if args == None: |
20 |
| - print("Please enter the required arguments!") |
21 |
| - |
22 |
| - parser = argparse.ArgumentParser( |
23 |
| - description="pipinstall: a library to download multiple libraries in different domains at once.") |
24 |
| - parser.add_argument("domain_name", |
25 |
| - help="Domain name", |
26 |
| - type=str) |
27 |
| - |
28 |
| - return parser.parse_args(args) |
29 |
| -# end of check_args |
30 |
| - |
31 |
| -# Main function |
32 |
| -def Main(): |
33 |
| - |
34 |
| - utils.clear_screen() |
35 |
| - print("Welcome to pipinstall! A humble try to make our lives easier :')") |
36 |
| - |
37 |
| - if check_args(sys.argv[1:]).domain_name: |
38 |
| - required_domain = check_args(sys.argv[1:]).domain_name |
| 33 | +#install function |
| 34 | +def install(domain_name=None): |
| 35 | + #clear_screen() |
| 36 | + print("Welcome to pipinstall! A humble try to make our lives easier :D") |
39 | 37 |
|
| 38 | + if domain_name is not None: |
40 | 39 | dpath = domainPath()
|
41 |
| - dpath = os.path.join(dpath, required_domain) |
| 40 | + dpath = os.path.join(dpath, domain_name) |
| 41 | + |
42 | 42 | if os.path.isdir(dpath):
|
43 |
| - utils.install_dom(dpath) |
| 43 | + install_dom(dpath) |
44 | 44 | else:
|
45 | 45 | while not os.path.isdir(dpath):
|
46 |
| - domain_name = str(input('Domain Name does not exist.\nPlease re-enter the domain name:')) |
47 |
| - dpath = os.path.join(dpath, domain_name) |
| 46 | + domain_name = str(input("Domain name does not exist. Please enter a valid domain name:\n")) |
| 47 | + dpath = os.path.join(dpath,domain_name) |
48 | 48 | if os.path.isdir(dpath):
|
49 |
| - utils.install_dom(dpath) |
50 |
| - |
51 |
| - |
52 |
| -# call Main |
53 |
| -if __name__ == '__main__': |
54 |
| - Main() |
| 49 | + install_dom(dpath) |
55 | 50 |
|
0 commit comments