diff --git a/setup.py b/setup.py index a5f1619..787df10 100644 --- a/setup.py +++ b/setup.py @@ -29,52 +29,28 @@ def install(): def update_package(): - import BeautifulSoup,re - - from waptpackage import PackageEntry - verify=True - pe = PackageEntry() - pe.load_control_from_wapt(os.getcwd()) - current_version = pe['version'].split('-',1)[0] - - url = 'https://github.com/fusioninventory/fusioninventory-agent/releases' - - page = wgets(url + '/latest') - bs = BeautifulSoup.BeautifulSoup(page) - - bs_raw_string = str(bs.find('span',{'class':'css-truncate-target'}).text) - - version = bs_raw_string - - url64 = url + "/download/" + version + "/fusioninventory-agent_windows-x64_%s.exe" % version - url86 = url + "/download/" + version + "/fusioninventory-agent_windows-x86_%s.exe" % version - - filenamex86 = "fusioninventory-agent_windows-x86_%s.exe" % version - filenamex64 = "fusioninventory-agent_windows-x64_%s.exe" % version - - if not isfile( filenamex64 ) : - wget( url64 ) - if not isfile( filenamex86 ) : - wget( url86 ) - - - for fileexe in glob.glob('fusioninventory-agent_windows-x64*.exe'): - if fileexe != filenamex64 : - print('Delete ' + fileexe) - remove_file(fileexe) - - for fileexe in glob.glob('fusioninventory-agent_windows-x86*.exe'): - if fileexe != filenamex86 : - print('Delete ' + fileexe) - remove_file(fileexe) - - if not isfile(filenamex64): - print('Download ' + url64) - wget(url64,filenamex64) - - if not isfile(filenamex86): - print('Download ' + url86) - wget(url86,filenamex86) + print('Updating FusionInventory Agent package') + import requests,json + + latest = json.loads(requests.get('https://api.github.com/repos/fusioninventory/fusioninventory-agent/releases/latest').text.encode('utf-8')) + version = latest['tag_name'] + pe = PackageEntry(); + control = pe.load_control_from_wapt('.') + for arch in ['86','64']: + for asset in latest['assets']: + if asset['name'] == 'fusioninventory-agent_windows-x%s_%s.exe' % (arch, version) and not isfile('fusioninventory-agent_windows-x%s_%s.exe' % (arch, version)): + url = asset['browser_download_url'] + print('Downloading FusionInventory Agent %s for x%s from %s' % (version,arch,url)) + wget(url,'fusioninventory-agent_windows-x%s_%s.exe' % (arch, version)) + for file in glob.glob('fusioninventory-agent_windows-%s_*.exe' % arch): + if file != 'fusioninventory-agent_windows-x%s_%s.exe' % (arch, version): + print('Removing %s' % file) + remove_file(file) + if Version(version) > Version(control['version'].split('-',1)[0]): + print('Updating control file with new version %s' % version) + pe.version = version + '-0' + pe.maturity = 'PREPROD' + pe.save_control_to_wapt('.') def audit():