Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../usr/lib/rpm
File: pythondistdeps.py
#!/usr/libexec/platform-python
[0] Fix | Delete
# -*- coding: utf-8 -*-
[1] Fix | Delete
#
[2] Fix | Delete
# Copyright 2010 Per Øyvind Karlsen <proyvind@moondrake.org>
[3] Fix | Delete
# Copyright 2015 Neal Gompa <ngompa13@gmail.com>
[4] Fix | Delete
#
[5] Fix | Delete
# This program is free software. It may be redistributed and/or modified under
[6] Fix | Delete
# the terms of the LGPL version 2.1 (or later).
[7] Fix | Delete
#
[8] Fix | Delete
# RPM python dependency generator, using .egg-info/.egg-link/.dist-info data
[9] Fix | Delete
#
[10] Fix | Delete
[11] Fix | Delete
from __future__ import print_function
[12] Fix | Delete
from getopt import getopt
[13] Fix | Delete
from os.path import basename, dirname, isdir, sep
[14] Fix | Delete
from sys import argv, stdin, version
[15] Fix | Delete
from distutils.sysconfig import get_python_lib
[16] Fix | Delete
from warnings import warn
[17] Fix | Delete
[18] Fix | Delete
[19] Fix | Delete
opts, args = getopt(
[20] Fix | Delete
argv[1:], 'hPRrCEMmLl:',
[21] Fix | Delete
['help', 'provides', 'requires', 'recommends', 'conflicts', 'extras', 'majorver-provides', 'majorver-provides-versions=', 'majorver-only', 'legacy-provides' , 'legacy'])
[22] Fix | Delete
[23] Fix | Delete
Provides = False
[24] Fix | Delete
Requires = False
[25] Fix | Delete
Recommends = False
[26] Fix | Delete
Conflicts = False
[27] Fix | Delete
Extras = False
[28] Fix | Delete
Provides_PyMajorVer_Variant = False
[29] Fix | Delete
Provides_PyMajorVer_Versions = None
[30] Fix | Delete
PyMajorVer_Deps = False
[31] Fix | Delete
legacy_Provides = False
[32] Fix | Delete
legacy = False
[33] Fix | Delete
[34] Fix | Delete
for o, a in opts:
[35] Fix | Delete
if o in ('-h', '--help'):
[36] Fix | Delete
print('-h, --help\tPrint help')
[37] Fix | Delete
print('-P, --provides\tPrint Provides')
[38] Fix | Delete
print('-R, --requires\tPrint Requires')
[39] Fix | Delete
print('-r, --recommends\tPrint Recommends')
[40] Fix | Delete
print('-C, --conflicts\tPrint Conflicts')
[41] Fix | Delete
print('-E, --extras\tPrint Extras ')
[42] Fix | Delete
print('-M, --majorver-provides\tPrint extra Provides with Python major version only for all Python versions')
[43] Fix | Delete
print(' --majorver-provides-versions VERSIONS\n'
[44] Fix | Delete
' \tPrint extra Provides with Python major version only for listed Python VERSIONS (comma separated, no spaces, e.g. 2.7,3.6)')
[45] Fix | Delete
print('-m, --majorver-only\tPrint Provides/Requires with Python major version only')
[46] Fix | Delete
print('-L, --legacy-provides\tPrint extra legacy pythonegg Provides')
[47] Fix | Delete
print('-l, --legacy\tPrint legacy pythonegg Provides/Requires instead')
[48] Fix | Delete
exit(1)
[49] Fix | Delete
elif o in ('-P', '--provides'):
[50] Fix | Delete
Provides = True
[51] Fix | Delete
elif o in ('-R', '--requires'):
[52] Fix | Delete
Requires = True
[53] Fix | Delete
elif o in ('-r', '--recommends'):
[54] Fix | Delete
Recommends = True
[55] Fix | Delete
elif o in ('-C', '--conflicts'):
[56] Fix | Delete
Conflicts = True
[57] Fix | Delete
elif o in ('-E', '--extras'):
[58] Fix | Delete
Extras = True
[59] Fix | Delete
elif o in ('-M', '--majorver-provides'):
[60] Fix | Delete
Provides_PyMajorVer_Variant = True
[61] Fix | Delete
elif o in ('--majorver-provides-versions'):
[62] Fix | Delete
Provides_PyMajorVer_Versions = a.split(",")
[63] Fix | Delete
elif o in ('-m', '--majorver-only'):
[64] Fix | Delete
PyMajorVer_Deps = True
[65] Fix | Delete
elif o in ('-L', '--legacy-provides'):
[66] Fix | Delete
legacy_Provides = True
[67] Fix | Delete
elif o in ('-l', '--legacy'):
[68] Fix | Delete
legacy = True
[69] Fix | Delete
[70] Fix | Delete
if Provides_PyMajorVer_Variant and Provides_PyMajorVer_Versions:
[71] Fix | Delete
print("Error, options --majorver-provides and --majorver-provides-versions are mutually incompatible.")
[72] Fix | Delete
exit(2)
[73] Fix | Delete
[74] Fix | Delete
if Requires:
[75] Fix | Delete
py_abi = True
[76] Fix | Delete
else:
[77] Fix | Delete
py_abi = False
[78] Fix | Delete
py_deps = {}
[79] Fix | Delete
if args:
[80] Fix | Delete
files = args
[81] Fix | Delete
else:
[82] Fix | Delete
files = stdin.readlines()
[83] Fix | Delete
[84] Fix | Delete
for f in files:
[85] Fix | Delete
f = f.strip()
[86] Fix | Delete
lower = f.lower()
[87] Fix | Delete
name = 'python(abi)'
[88] Fix | Delete
# add dependency based on path, versioned if within versioned python directory
[89] Fix | Delete
if py_abi and (lower.endswith('.py') or lower.endswith('.pyc') or lower.endswith('.pyo')):
[90] Fix | Delete
if name not in py_deps:
[91] Fix | Delete
py_deps[name] = []
[92] Fix | Delete
purelib = get_python_lib(standard_lib=0, plat_specific=0).split(version[:3])[0]
[93] Fix | Delete
platlib = get_python_lib(standard_lib=0, plat_specific=1).split(version[:3])[0]
[94] Fix | Delete
for lib in (purelib, platlib):
[95] Fix | Delete
if lib in f:
[96] Fix | Delete
spec = ('==', f.split(lib)[1].split(sep)[0])
[97] Fix | Delete
if spec not in py_deps[name]:
[98] Fix | Delete
py_deps[name].append(spec)
[99] Fix | Delete
[100] Fix | Delete
# XXX: hack to workaround RPM internal dependency generator not passing directories
[101] Fix | Delete
lower_dir = dirname(lower)
[102] Fix | Delete
if lower_dir.endswith('.egg') or \
[103] Fix | Delete
lower_dir.endswith('.egg-info') or \
[104] Fix | Delete
lower_dir.endswith('.dist-info'):
[105] Fix | Delete
lower = lower_dir
[106] Fix | Delete
f = dirname(f)
[107] Fix | Delete
# Determine provide, requires, conflicts & recommends based on egg/dist metadata
[108] Fix | Delete
if lower.endswith('.egg') or \
[109] Fix | Delete
lower.endswith('.egg-info') or \
[110] Fix | Delete
lower.endswith('.dist-info'):
[111] Fix | Delete
# This import is very slow, so only do it if needed
[112] Fix | Delete
from pkg_resources import Distribution, FileMetadata, PathMetadata
[113] Fix | Delete
dist_name = basename(f)
[114] Fix | Delete
if isdir(f):
[115] Fix | Delete
path_item = dirname(f)
[116] Fix | Delete
metadata = PathMetadata(path_item, f)
[117] Fix | Delete
else:
[118] Fix | Delete
path_item = f
[119] Fix | Delete
metadata = FileMetadata(f)
[120] Fix | Delete
dist = Distribution.from_location(path_item, dist_name, metadata)
[121] Fix | Delete
# Check if py_version is defined in the metadata file/directory name
[122] Fix | Delete
if not dist.py_version:
[123] Fix | Delete
# Try to parse the Python version from the path the metadata
[124] Fix | Delete
# resides at (e.g. /usr/lib/pythonX.Y/site-packages/...)
[125] Fix | Delete
import re
[126] Fix | Delete
res = re.search(r"/python(?P<pyver>\d+\.\d+)/", path_item)
[127] Fix | Delete
if res:
[128] Fix | Delete
dist.py_version = res.group('pyver')
[129] Fix | Delete
else:
[130] Fix | Delete
warn("Version for {!r} has not been found".format(dist), RuntimeWarning)
[131] Fix | Delete
continue
[132] Fix | Delete
[133] Fix | Delete
# XXX: https://github.com/pypa/setuptools/pull/1275
[134] Fix | Delete
import platform
[135] Fix | Delete
platform.python_version = lambda: dist.py_version
[136] Fix | Delete
[137] Fix | Delete
if Provides_PyMajorVer_Variant or PyMajorVer_Deps or legacy_Provides or legacy or Provides_PyMajorVer_Versions:
[138] Fix | Delete
# Get the Python major version
[139] Fix | Delete
pyver_major = dist.py_version.split('.')[0]
[140] Fix | Delete
if Provides:
[141] Fix | Delete
# If egg/dist metadata says package name is python, we provide python(abi)
[142] Fix | Delete
if dist.key == 'python':
[143] Fix | Delete
name = 'python(abi)'
[144] Fix | Delete
if name not in py_deps:
[145] Fix | Delete
py_deps[name] = []
[146] Fix | Delete
py_deps[name].append(('==', dist.py_version))
[147] Fix | Delete
if not legacy or not PyMajorVer_Deps:
[148] Fix | Delete
name = 'python{}dist({})'.format(dist.py_version, dist.key)
[149] Fix | Delete
if name not in py_deps:
[150] Fix | Delete
py_deps[name] = []
[151] Fix | Delete
if Provides_PyMajorVer_Variant or PyMajorVer_Deps or \
[152] Fix | Delete
(Provides_PyMajorVer_Versions and dist.py_version in Provides_PyMajorVer_Versions):
[153] Fix | Delete
pymajor_name = 'python{}dist({})'.format(pyver_major, dist.key)
[154] Fix | Delete
if pymajor_name not in py_deps:
[155] Fix | Delete
py_deps[pymajor_name] = []
[156] Fix | Delete
if legacy or legacy_Provides:
[157] Fix | Delete
legacy_name = 'pythonegg({})({})'.format(pyver_major, dist.key)
[158] Fix | Delete
if legacy_name not in py_deps:
[159] Fix | Delete
py_deps[legacy_name] = []
[160] Fix | Delete
if dist.version:
[161] Fix | Delete
spec = ('==', dist.version)
[162] Fix | Delete
if spec not in py_deps[name]:
[163] Fix | Delete
if not legacy:
[164] Fix | Delete
py_deps[name].append(spec)
[165] Fix | Delete
if Provides_PyMajorVer_Variant or \
[166] Fix | Delete
(Provides_PyMajorVer_Versions and dist.py_version in Provides_PyMajorVer_Versions):
[167] Fix | Delete
py_deps[pymajor_name].append(spec)
[168] Fix | Delete
if legacy or legacy_Provides:
[169] Fix | Delete
py_deps[legacy_name].append(spec)
[170] Fix | Delete
if Requires or (Recommends and dist.extras):
[171] Fix | Delete
name = 'python(abi)'
[172] Fix | Delete
# If egg/dist metadata says package name is python, we don't add dependency on python(abi)
[173] Fix | Delete
if dist.key == 'python':
[174] Fix | Delete
py_abi = False
[175] Fix | Delete
if name in py_deps:
[176] Fix | Delete
py_deps.pop(name)
[177] Fix | Delete
elif py_abi and dist.py_version:
[178] Fix | Delete
if name not in py_deps:
[179] Fix | Delete
py_deps[name] = []
[180] Fix | Delete
spec = ('==', dist.py_version)
[181] Fix | Delete
if spec not in py_deps[name]:
[182] Fix | Delete
py_deps[name].append(spec)
[183] Fix | Delete
deps = dist.requires()
[184] Fix | Delete
if Recommends:
[185] Fix | Delete
depsextras = dist.requires(extras=dist.extras)
[186] Fix | Delete
if not Requires:
[187] Fix | Delete
for dep in reversed(depsextras):
[188] Fix | Delete
if dep in deps:
[189] Fix | Delete
depsextras.remove(dep)
[190] Fix | Delete
deps = depsextras
[191] Fix | Delete
# add requires/recommends based on egg/dist metadata
[192] Fix | Delete
for dep in deps:
[193] Fix | Delete
if legacy:
[194] Fix | Delete
name = 'pythonegg({})({})'.format(pyver_major, dep.key)
[195] Fix | Delete
else:
[196] Fix | Delete
if PyMajorVer_Deps:
[197] Fix | Delete
name = 'python{}dist({})'.format(pyver_major, dep.key)
[198] Fix | Delete
else:
[199] Fix | Delete
name = 'python{}dist({})'.format(dist.py_version, dep.key)
[200] Fix | Delete
for spec in dep.specs:
[201] Fix | Delete
if spec[0] != '!=':
[202] Fix | Delete
if name not in py_deps:
[203] Fix | Delete
py_deps[name] = []
[204] Fix | Delete
if spec not in py_deps[name]:
[205] Fix | Delete
py_deps[name].append(spec)
[206] Fix | Delete
if not dep.specs:
[207] Fix | Delete
py_deps[name] = []
[208] Fix | Delete
# Unused, for automatic sub-package generation based on 'extras' from egg/dist metadata
[209] Fix | Delete
# TODO: implement in rpm later, or...?
[210] Fix | Delete
if Extras:
[211] Fix | Delete
deps = dist.requires()
[212] Fix | Delete
extras = dist.extras
[213] Fix | Delete
print(extras)
[214] Fix | Delete
for extra in extras:
[215] Fix | Delete
print('%%package\textras-{}'.format(extra))
[216] Fix | Delete
print('Summary:\t{} extra for {} python package'.format(extra, dist.key))
[217] Fix | Delete
print('Group:\t\tDevelopment/Python')
[218] Fix | Delete
depsextras = dist.requires(extras=[extra])
[219] Fix | Delete
for dep in reversed(depsextras):
[220] Fix | Delete
if dep in deps:
[221] Fix | Delete
depsextras.remove(dep)
[222] Fix | Delete
deps = depsextras
[223] Fix | Delete
for dep in deps:
[224] Fix | Delete
for spec in dep.specs:
[225] Fix | Delete
if spec[0] == '!=':
[226] Fix | Delete
print('Conflicts:\t{} {} {}'.format(dep.key, '==', spec[1]))
[227] Fix | Delete
else:
[228] Fix | Delete
print('Requires:\t{} {} {}'.format(dep.key, spec[0], spec[1]))
[229] Fix | Delete
print('%%description\t{}'.format(extra))
[230] Fix | Delete
print('{} extra for {} python package'.format(extra, dist.key))
[231] Fix | Delete
print('%%files\t\textras-{}\n'.format(extra))
[232] Fix | Delete
if Conflicts:
[233] Fix | Delete
# Should we really add conflicts for extras?
[234] Fix | Delete
# Creating a meta package per extra with recommends on, which has
[235] Fix | Delete
# the requires/conflicts in stead might be a better solution...
[236] Fix | Delete
for dep in dist.requires(extras=dist.extras):
[237] Fix | Delete
name = dep.key
[238] Fix | Delete
for spec in dep.specs:
[239] Fix | Delete
if spec[0] == '!=':
[240] Fix | Delete
if name not in py_deps:
[241] Fix | Delete
py_deps[name] = []
[242] Fix | Delete
spec = ('==', spec[1])
[243] Fix | Delete
if spec not in py_deps[name]:
[244] Fix | Delete
py_deps[name].append(spec)
[245] Fix | Delete
names = list(py_deps.keys())
[246] Fix | Delete
names.sort()
[247] Fix | Delete
for name in names:
[248] Fix | Delete
if py_deps[name]:
[249] Fix | Delete
# Print out versioned provides, requires, recommends, conflicts
[250] Fix | Delete
for spec in py_deps[name]:
[251] Fix | Delete
print('{} {} {}'.format(name, spec[0], spec[1]))
[252] Fix | Delete
else:
[253] Fix | Delete
# Print out unversioned provides, requires, recommends, conflicts
[254] Fix | Delete
print(name)
[255] Fix | Delete
[256] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function