Commit e492994e authored by Agustin Pane's avatar Agustin Pane
Browse files

(Feature) - Debian support

parent c4d68b82
...@@ -4,7 +4,7 @@ from setuptools import setup ...@@ -4,7 +4,7 @@ from setuptools import setup
setup( setup(
name='svmon-client', name='svmon-client',
version='2.3.3', version='2.4.0',
packages=['svmon_client'], packages=['svmon_client'],
scripts=['svmon'], scripts=['svmon'],
package_data={'' : ['*.json','*.pem']}, package_data={'' : ['*.json','*.pem']},
......
...@@ -72,7 +72,7 @@ def get_service_tag(service_type,configs=None): ...@@ -72,7 +72,7 @@ def get_service_tag(service_type,configs=None):
return tags return tags
elif service_type == "gitlab": elif service_type == "gitlab":
tmp = get_by_rpm_packages("gitlab", 0 , 1) tmp = get_package_version("gitlab", 0 , 1)
if(enableDebug): if(enableDebug):
print('get_service_tag for gitlab result: ', tmp) print('get_service_tag for gitlab result: ', tmp)
if tmp == None or tmp == '' or tmp.find('Failed') >-1: if tmp == None or tmp == '' or tmp.find('Failed') >-1:
...@@ -82,7 +82,7 @@ def get_service_tag(service_type,configs=None): ...@@ -82,7 +82,7 @@ def get_service_tag(service_type,configs=None):
return tags return tags
elif service_type == "b2safe": elif service_type == "b2safe":
tmp=get_by_rpm_packages("b2safe") tmp=get_package_version("b2safe")
if(enableDebug): if(enableDebug):
print('get_service_tag for b2safe result: ', tmp) print('get_service_tag for b2safe result: ', tmp)
if tmp == "": if tmp == "":
...@@ -90,13 +90,13 @@ def get_service_tag(service_type,configs=None): ...@@ -90,13 +90,13 @@ def get_service_tag(service_type,configs=None):
exit(1) exit(1)
tags.append(tmp) tags.append(tmp)
tmp=get_by_rpm_packages("irods-server") tmp=get_package_version("irods-server")
if(enableDebug): if(enableDebug):
print('get_service_tag for irods-server result: '+ tmp) print('get_service_tag for irods-server result: '+ tmp)
if tmp != None and tmp != '' and tmp.find('Failed') == -1: if tmp != None and tmp != '' and tmp.find('Failed') == -1:
tags.append(tmp) tags.append(tmp)
return tags return tags
tmp=get_by_rpm_packages("irods-icat") tmp=get_package_version("irods-icat")
if(enableDebug): if(enableDebug):
print('get_service_tag for irods-icat result: '+tmp) print('get_service_tag for irods-icat result: '+tmp)
if tmp != None and tmp != '' and tmp.find('Failed') == -1: if tmp != None and tmp != '' and tmp.find('Failed') == -1:
...@@ -108,6 +108,7 @@ def get_service_tag(service_type,configs=None): ...@@ -108,6 +108,7 @@ def get_service_tag(service_type,configs=None):
elif service_type == "svmon": elif service_type == "svmon":
if configs != None and 'svmon_app_path' in configs: if configs != None and 'svmon_app_path' in configs:
print('Getting svmon version from config file') print('Getting svmon version from config file')
tmp=get_package_version("b2safe")
tags={} tags={}
if configs.get('svmon_app_path') != None and configs.get('svmon_app_path') != '' : if configs.get('svmon_app_path') != None and configs.get('svmon_app_path') != '' :
svmonVersions = get_svmon_version(configs.get('svmon_app_path')) svmonVersions = get_svmon_version(configs.get('svmon_app_path'))
...@@ -128,40 +129,79 @@ def get_service_tag(service_type,configs=None): ...@@ -128,40 +129,79 @@ def get_service_tag(service_type,configs=None):
print("No b2handle configuration to get versions") print("No b2handle configuration to get versions")
exit(1) exit(1)
# for package version that can be accessed via rpm management def get_package_version(software,start=0,end=0):
def get_by_rpm_packages(software,start=0,end=0):
config = remoteConfig.RemoteConfig().getConfig() config = remoteConfig.RemoteConfig().getConfig()
enableDebug = config["DEBUG_MODE"] enableDebug = config["DEBUG_MODE"]
if(enableDebug): if(enableDebug):
print('Get_by_rpm_packages for software: '+software) print('Get_package_version for software: '+software)
if isinstance(software,str) == False or software == "" or software == None: if isinstance(software,str) == False or software == "" or software == None:
print("Software name should be a non-empty string") print("Software name should be a non-empty string")
exit(1) exit(1)
if isinstance(start,int) == False or isinstance(end, int) == False: if isinstance(start,int) == False or isinstance(end, int) == False:
print("The input of indices should be integers to fetch correct version,") print("The input of indices should be integers to fetch correct version,")
exit(1) exit(1)
tmp = subprocess.Popen("rpm -qa", shell=True, stdout=subprocess.PIPE)
tmp = subprocess.Popen('grep ' + software, shell=True, stdin=tmp.stdout, stdout=subprocess.PIPE) dpkgResult = subprocess.Popen("which dpkg", shell=True, stdout=subprocess.PIPE)
tmp = tmp.communicate() dpkgResult = dpkgResult.communicate()
if dpkgResult[0] == None or dpkgResult == "":
if(enableDebug):
print('No dpkg found, running with rpm...')
return get_by_rpm_packages(software, start,end)
return get_by_dpkg_packages(software,start,end)
# for package version that can be accessed via rpm management
def get_by_dpkg_packages(software,start=0,end=0):
config = remoteConfig.RemoteConfig().getConfig()
enableDebug = config["DEBUG_MODE"]
if(enableDebug): if(enableDebug):
print('Get_by_rpm_packages final rpm-qa before parse result: ', tmp) print('Get_by_dpkg_packages for software: '+software, start,end)
tmp = tmp[0]
if tmp == None or tmp == "": softwareListResult = subprocess.Popen("dpkg -l", shell=True, stdout=subprocess.PIPE)
print('Failed, no rpm packages can be found for ', software) softwareListResult = subprocess.Popen('grep ' + software, shell=True, stdin=softwareListResult.stdout, stdout=subprocess.PIPE)
softwareListResult = softwareListResult.communicate()
if(enableDebug):
print('Get_by_dpkg_packages final dpkg -l before parse result: ', softwareListResult)
if softwareListResult[0] == None or softwareListResult == "":
print('Failed, no dpkg packages can be found for ', software)
return '' return ''
ind=tmp.find(software)
ind=ind+len(software) return extractVersionFromCommandResult(software, softwareListResult[0], start,end)
ltmp=tmp[ind+1:len(tmp)].split('-')
# for package version that can be accessed via rpm management
def get_by_rpm_packages(software,start=0,end=0):
config = remoteConfig.RemoteConfig().getConfig()
enableDebug = config["DEBUG_MODE"]
if(enableDebug): if(enableDebug):
print('Get_by_rpm_packages final ltmp test result: ',ltmp) print('Get_by_rpm_packages for software: '+software, start,end)
softwareListResult = subprocess.Popen("rpm -qa", shell=True, stdout=subprocess.PIPE)
softwareListResult = subprocess.Popen('grep ' + software, shell=True, stdin=softwareListResult.stdout, stdout=subprocess.PIPE)
softwareListResult = softwareListResult.communicate()
if(enableDebug):
print('Get_by_rpm_packages final rpm-qa before parse result: ', softwareListResult)
if softwareListResult[0] == None or softwareListResult == "":
print('Failed, no rpm packages can be found for ', software)
return ''
return extractVersionFromCommandResult(software, softwareListResult[0], start,end)
def extractVersionFromCommandResult(software,unparsedVersion, start,end):
softwareIndex=unparsedVersion.find(software)
softwareIndex=softwareIndex+len(software)
parsedVersion=unparsedVersion[softwareIndex+1:len(unparsedVersion)].split('-')
if len(ltmp) > end: if len(parsedVersion) > end:
if start == end: if start == end:
return ltmp[start] return parsedVersion[start]
elif start < end: elif start < end:
res="" res=""
for i in range(start,end+1): for i in range(start,end+1):
res=res+ltmp[i] res=res+parsedVersion[i]
return res return res
else: else:
print('Failed, the start index should be smaller than end index for a correct rpm package resolver') print('Failed, the start index should be smaller than end index for a correct rpm package resolver')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment