-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuildGap.py
executable file
·83 lines (71 loc) · 2.14 KB
/
BuildGap.py
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
# ____ _ _ _ _____
# | _ \ (_) | | |/ ____|
# | |_) |_ _ _| | __| | | __ __ _ _ __
# | _ <| | | | | |/ _` | | |_ |/ _` | '_ \
# | |_) | |_| | | | (_| | |__| | (_| | |_) |
# |____/ \__,_|_|_|\__,_|\_____|\__,_| .__/
# | |
# |_|
import sys
import apt
from termcolor import colored, cprint
import subprocess
from pathlib import Path
#---------------------------------------------------------------------------------------------------------
pkgname = None
wanip= "9.9.9.9"
apt.apt_pkg.init()
cache=apt.Cache()
cache.open()
def wanchck():
try:
test=subprocess.call("ping -c 1 " + wanip, shell=True, stdout=subprocess.DEVNULL)
if test !=0:
raise ValueError('No internet')
except:
print(colored("=>!Internet connection unavailable<=","red"))
sys.exit()
#check if argument is provided and valid
def chckarg():
try:
global pkgname
pkgname = str(sys.argv[1])
print(colored(pkgname,"cyan",attrs=["underline"]), colored(" package is selected","green"))
except:
print(colored("=>!Missing package name!<=","red"))
sys.exit()
try:
cache[pkgname]
return pkgname
except:
print(colored("=>!This package does not exist!<=","red"))
sys.exit()
#Download the main package
def getpkg():
pkg=cache[pkgname]
Path("/tmp/BuildGap").mkdir(parents=True, exist_ok=True)
pkg.candidate.fetch_binary('/tmp/BuildGap/')
#Download dependencies
def getdep():
pkg=cache[pkgname]
dependencies= pkg.candidate.dependencies
for x in range(len(dependencies)):
for y in range(len(dependencies[x])):
depname=dependencies[x][y].name
print(depname)
Path("/tmp/BuildGap").mkdir(parents=True, exist_ok=True)
try:
Currentdep=cache[depname]
Currentdep.candidate.fetch_binary('/tmp/BuildGap/')
except:
print(colored(depname,"cyan",attrs=["underline"]), colored(" package could not be downloaded","red"))
#Print Banner
print(colored("""
==================================
===|| BuildGap|| by zamansoum||===
==================================
""", "yellow", attrs=["dark"]))
wanchck()
chckarg()
getdep()
getpkg()