- try to get product/version from system configuration at first attempt - if system configuration is missing obtain product/component from anaconda - closes #741647
Signed-off-by: Jakub Filak jfilak@redhat.com --- src/report-python/__init__.py | 67 +++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 25 deletions(-)
diff --git a/src/report-python/__init__.py b/src/report-python/__init__.py index 9c5e6b3..2c58736 100644 --- a/src/report-python/__init__.py +++ b/src/report-python/__init__.py @@ -42,10 +42,30 @@ def getProduct_fromRPM(): except: return ""
+def getVersion_fromRPM(): + try: + import rpm + ts = rpm.TransactionSet() + for each_dep in SYSTEM_RELEASE_DEPS: + mi = ts.dbMatch('provides', each_dep) + for h in mi: + if h['version']: + return str(h['version']) + + return "" + except: + return "" +""" + def getProduct_fromFILE(): for each_path in SYSTEM_RELEASE_PATHS: if os.path.exists(each_path): - file = open(each_path, "r") + file = None + try: + file = open(each_path, "r") + except IOError as e: + return "" + content = file.read() if content.startswith("Red Hat Enterprise Linux"): return "Red Hat Enterprise Linux" @@ -59,24 +79,15 @@ def getProduct_fromFILE():
return ""
-def getVersion_fromRPM(): - try: - import rpm - ts = rpm.TransactionSet() - for each_dep in SYSTEM_RELEASE_DEPS: - mi = ts.dbMatch('provides', each_dep) - for h in mi: - if h['version']: - return str(h['version']) - - return "" - except: - return "" - def getVersion_fromFILE(): for each_path in SYSTEM_RELEASE_PATHS: if os.path.exists(each_path): - file = open(each_path, "r") + file = None + try: + file = open(each_path, "r") + except IOError as e: + return "" + content = file.read() if content.find("Rawhide") > -1: return "rawhide" @@ -86,7 +97,6 @@ def getVersion_fromFILE(): return clist[i+1] else: return "" -"""
def getProduct_fromPRODUCT(): try: @@ -112,21 +122,28 @@ def getVersion_fromPRODUCT():
def getProduct(): - """Attempt to determine the product of the running system by asking anaconda + """Attempt to determine the product of the running system at first attempt + from the release configuration file or if the first attempt fails by + asking anaconda + Always return as a string. """ - product = getProduct_fromPRODUCT() - if product: - return product + for getter in (getProduct_fromFILE, getProduct_fromPRODUCT): + product = getter() + if product: + return product
return _hardcoded_default_product
def getVersion(): - """Attempt to determine the version of the running system by asking anaconda + """Attempt to determine the version of the running system at first attempt + from the release configuration file or if the first attempt fails by + asking anaconda Always return as a string. """ - version = getVersion_fromPRODUCT() - if version: - return version + for getter in (getVersion_fromFILE, getVersion_fromPRODUCT): + version = getter() + if version: + return version
return _hardcoded_default_version
ack. works, pushed.
On 10/15/2012 05:21 PM, Jakub Filak wrote:
- try to get product/version from system configuration at first attempt
- if system configuration is missing obtain product/component from anaconda
- closes #741647
Signed-off-by: Jakub Filak jfilak@redhat.com
src/report-python/__init__.py | 67 +++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 25 deletions(-)
diff --git a/src/report-python/__init__.py b/src/report-python/__init__.py index 9c5e6b3..2c58736 100644 --- a/src/report-python/__init__.py +++ b/src/report-python/__init__.py @@ -42,10 +42,30 @@ def getProduct_fromRPM(): except: return ""
+def getVersion_fromRPM():
- try:
import rpm
ts = rpm.TransactionSet()
for each_dep in SYSTEM_RELEASE_DEPS:
mi = ts.dbMatch('provides', each_dep)
for h in mi:
if h['version']:
return str(h['version'])
return ""
- except:
return ""
+"""
def getProduct_fromFILE(): for each_path in SYSTEM_RELEASE_PATHS: if os.path.exists(each_path):
file = open(each_path, "r")
file = None
try:
file = open(each_path, "r")
except IOError as e:
return ""
content = file.read() if content.startswith("Red Hat Enterprise Linux"): return "Red Hat Enterprise Linux"
@@ -59,24 +79,15 @@ def getProduct_fromFILE():
return ""
-def getVersion_fromRPM():
- try:
import rpm
ts = rpm.TransactionSet()
for each_dep in SYSTEM_RELEASE_DEPS:
mi = ts.dbMatch('provides', each_dep)
for h in mi:
if h['version']:
return str(h['version'])
return ""
- except:
return ""
def getVersion_fromFILE(): for each_path in SYSTEM_RELEASE_PATHS: if os.path.exists(each_path):
file = open(each_path, "r")
file = None
try:
file = open(each_path, "r")
except IOError as e:
return ""
content = file.read() if content.find("Rawhide") > -1: return "rawhide"
@@ -86,7 +97,6 @@ def getVersion_fromFILE(): return clist[i+1] else: return "" -"""
def getProduct_fromPRODUCT(): try: @@ -112,21 +122,28 @@ def getVersion_fromPRODUCT():
def getProduct():
- """Attempt to determine the product of the running system by asking anaconda
- """Attempt to determine the product of the running system at first attempt
from the release configuration file or if the first attempt fails by
asking anaconda
"""Always return as a string.
- product = getProduct_fromPRODUCT()
- if product:
return product
for getter in (getProduct_fromFILE, getProduct_fromPRODUCT):
product = getter()
if product:
return product
return _hardcoded_default_product
def getVersion():
- """Attempt to determine the version of the running system by asking anaconda
- """Attempt to determine the version of the running system at first attempt
from the release configuration file or if the first attempt fails by
"""asking anaconda Always return as a string.
- version = getVersion_fromPRODUCT()
- if version:
return version
for getter in (getVersion_fromFILE, getVersion_fromPRODUCT):
version = getter()
if version:
return version
return _hardcoded_default_version
crash-catcher@lists.fedorahosted.org