-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecker.py
executable file
·50 lines (38 loc) · 1.66 KB
/
checker.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
#!/usr/bin/env python3
""" Little script that reads from a file packages that are requried for something (whatever) and compare the name to what's installed in the system [Slackware] """
import os
import sys
import subprocess
requiredPath = "./thing"
packagesPath = "/var/log/packages"
def get_file_content(filename):
if os.path.exists(filename):
with open(filename,'r') as f:
return f.read()
else:
print("There's been an error with the path to the file containing the requried packages")
sys.exit(1)
def get_packages(path):
#pkgs = subprocess.check_output(['ls',packages_path])
pkgs = subprocess.run(["ls", path],check=True,stdout=subprocess.PIPE)
pkgs = pkgs.stdout.splitlines()
return pkgs
#installed = subprocess.run(["ls",packages_path],check=True,stdout=subprocess.PIPE)
#installed = installed.stdout.splitlines()
def start_check(pathToPackages,pathToRequirements):
if (os.path.exists(pathToPackages)) and (os.path.exists(pathToRequirements)):
installed = get_packages(pathToPackages)
required = get_file_content(pathToRequirements).split()
for i in range(len(required)):
isit = False
for j in range(len(installed)):
if required[i] in installed[j].decode('utf8').strip():
isit = True
print("{} is installed, {}".format(required[i].ljust(20), installed[j].decode() ))
break
if not isit:
print("{} isn't isntalled".format(required[i]))
else:
print("Please check on the provided paths")
if __name__ == "__main__":
start_check(packagesPath,requiredPath)