我想知道哪些python软件包是通过pip安装的,哪些是通过rpm安装的.
我在任何virtualenv 外面运行,并想知道是否通过pip安装了一些软件包.
背景:我们的政策是在"根级"使用RPM.我想找到政策被打破的地方.
稍微扭转一下问题,检查一下哪些属于 rpm,哪些不属于。尝试:
import os, sys, subprocess, glob
def type_printed(pth, rpm_dirs=False):
if not os.path.exists(pth):
print(pth + ' -- does not exist')
return True
FNULL = open(os.devnull, 'w')
if rpm_dirs or not os.path.isdir(pth):
rc = subprocess.call(['rpm', '-qf', pth], stdout=FNULL, stderr=subprocess.STDOUT)
if rc == 0:
print(pth + ' -- IS RPM')
return True
print(pth + ' -- NOT an RPM')
return True
return False
for pth in sys.path:
if type_printed(pth):
continue
contents = glob.glob(pth + '/*')
for subpth in contents:
if type_printed(subpth, rpm_dirs=True):
continue
print(subpth + ' -- nothing could be determined for sure')
Run Code Online (Sandbox Code Playgroud)
并通过类似的管道输出
grep -e '-- NOT' -e '-- nothing could be determined'
Run Code Online (Sandbox Code Playgroud)