SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hey everybody. I just finished my first parctical program in python. It's similar to swaret or slapt-get, but it only downloads packages, I haven't written the install section yet.
Anyways try it out and let me know what you think.
# getpkg.py
Code:
#! /usr/bin/python
import urllib,HTMLParser
import os,os.path
homedir = os.path.expanduser('~')
config_folder = homedir + "/.getpkg"
download_folder = config_folder + "/downloads"
installed_file = "installed"
available_file = "available"
country_file = "country"
version_file = "version"
try: fp = os.path.exists(config_folder)
except: fp =0
if not fp:
os.mkdir(config_folder)
try: fp = os.path.exists(download_folder)
except: fp =0
if not fp:
os.mkdir(download_folder)
packages_dir="/var/log/packages"
country_list = ["Australia","Austria","Belgium","Brasil","Bulgaria","Canada","Costa Rica","Czech Republic","Finland",\
"France","Germany","Greece","Hong Kong","Hungary","Ireland","Italy","Japan","Korea","Netherlands","Norway","Poland",\
"Portugal","Republic of Moldova","Romania","Russia","Serbia","South Africa","Spain","Sweden","Switzerland","Taiwan",\
"Thailand","UK","USA" ]
discsets = ["a","ap","d","e","f","gnome","k","kde","kdei","l","n","t","tcl","x","xap","extra","pasture","patches"]
slack_versions = ["8.1","9.0","9.1","10.0","current"]
menu = ["Choose Country","Choose Version","Update Installed List","Update Available List","Package Search","Exit"]
mirror_list_url="http://www.slackware.com/getslack/list.php?country="
mirrors = []
available = []
def get_installed_pkgs():
installed = []
packages = os.listdir(packages_dir)
num_packages = len(packages)
for package in packages:
parts = package.split("-")
revision = parts.pop()
arch = parts.pop()
version = parts.pop()
pkgname = '-'.join(parts)
this_package = {'package' : package,'name' : pkgname,'version' : version,'arch' : arch,'revision' : revision}
installed.append(this_package)
return installed
def choose_by_index(arr,heading):
print ""
print "Choose " + heading
print "Please enter the number of your choice"
for i in range(len(arr)):
print str(i) + " : " + arr[i]
print ""
while 1:
try:
returnval = raw_input("Enter Index: ")
intvalue = int(returnval)
if intvalue >= 0 and intvalue < len(arr): break
else:
print "Invalid input, please try again"
print "Please enter a value between 0 and " + str(len(arr) -1)
except ValueError:
print "Invalid input, please try again"
print "Please enter a value between 0 and " + str(len(arr) -1)
return returnval
class MyHTMLParser(HTMLParser.HTMLParser):
global mirrors
def handle_starttag(self, tag, attrs):
if tag == "a" or tag == "A":
for url in attrs:
theHREF = url[1]
if theHREF[0:4] == "http" or theHREF[0:4] == "ftp:":
if theHREF != "http://store.slackware.com" and theHREF != "http://store.slackware.com/" and theHREF != "http://slackware.com/trademark/trademark.php":
# make sure the mirro has trailing /
if theHREF[-1] != "/": theHREF += "/"
mirrors.append(theHREF)
class ParseDataForPackages(HTMLParser.HTMLParser):
packages = []
def handle_starttag(self, tag, attrs):
if tag == "a" or tag == "A":
for url in attrs:
theHREF = url[1]
if theHREF[-4:] == ".tgz" or theHREF[-4:] == ".TGZ":
parts = theHREF.split("-")
revision = parts.pop()
arch = parts.pop()
version = parts.pop()
pkgname = '-'.join(parts)
this_package = {'package' : package,'name' : pkgname,'version' : version,'arch' : arch,'revision' : revision}
packages.append(this_package)
def read_filelist(filelist):
pkgs = []
while 1:
line = filelist.readline()
if line[-4:-1] == "tgz":
this_pkg = {}
words = line[:-1].split(" ")
this_pkg["filesize"] = words[len(words)-4]
package = words[len(words)-1]
path = package[2:]
this_pkg["path"] = path
parts = path.split("/")
if parts[0] == "slackware": disc = parts[1]
elif parts[0] == "source": break
else: disc = parts[0]
pkg = parts[len(parts)-1]
this_pkg["discset"] = disc
this_pkg["package"] = pkg
pkg_parts = pkg[:-4].split("-")
if len(pkg_parts) >= 4:
this_pkg['revision'] = pkg_parts.pop()
this_pkg['arch'] = pkg_parts.pop()
this_pkg['version'] = pkg_parts.pop()
this_pkg['name'] = '-'.join(pkg_parts)
else:
this_pkg['revision'] = ""
this_pkg['arch'] = ""
this_pkg['version'] = ""
this_pkg['name'] = ""
pkgs.append(this_pkg)
if not line: break
return pkgs
inst_path = config_folder + "/" + installed_file
try: fp = os.path.exists(inst_path)
except: fp = 0
if not fp:
inst_pkglist = get_installed_pkgs()
output = open(inst_path,'w')
for pkg in inst_pkglist:
output.write(str(pkg) + "\n")
output.close()
else:
input = open(inst_path,'r')
inst_pkglist = []
EOF = False
while not EOF:
line = input.readline()
if line:
if line[-1] == "\n": line = line[:-1]
inst_pkglist.append(eval(line))
else: EOF = True
print str(len(inst_pkglist)) + " packages currently installed"
def choose_country():
global mirrors
global country_list
mirrors = []
while len(mirrors) == 0:
country_choice = choose_by_index(country_list,"country")
URL = mirror_list_url + country_list[int(country_choice)]
f = urllib.urlopen(URL)
page = f.read()
p = MyHTMLParser()
p.feed(page)
if len(mirrors) == 0: print "No mirrors found in " + country_list[int(country_choice)]
else:
print "Available Mirrors in " + country_list[int(country_choice)] + ":"
for m in mirrors:
print m
return country_list[int(country_choice)]
country_path = config_folder + "/" + country_file
try: fp = os.path.exists(country_path)
except: fp = 0
if fp:
input = open(country_path,'r')
country = input.readline()
#country = country[:-1]
input.close()
URL = mirror_list_url + country
while len(mirrors) == 0:
f = urllib.urlopen(URL)
page = f.read()
p = MyHTMLParser()
p.feed(page)
if len(mirrors) == 0: print "No mirrors found in " + country
print "Available Mirrors in " + country + ":"
for m in mirrors:
print m
else:
country = choose_country()
output = open(country_path,'w')
output.write(country)
output.close()
def choose_version():
global slack_versions
version_choice = choose_by_index(slack_versions,"Slackware Version")
v = "slackware-" + slack_versions[int(version_choice)] + "/"
return v
version_path = config_folder + "/" + version_file
try: fp = os.path.exists(version_path)
except: fp = 0
if fp:
input = open(version_path,'r')
version = input.readline()
#version = version[:-1]
input.close()
else:
version = choose_version()
output = open(version_path,'w')
output.write(version)
output.close()
def find_avail_packages():
global mirrors
global version
global available
available = []
max = len(mirrors)
target = version + "FILELIST.TXT"
ind = 0
data = 0;
while not data:
URL = mirrors[ind] + target
print "opening " + URL
try:
file = urllib.urlopen(URL)
available = read_filelist(filelist=file)
data = 1
except:
ind += 1
if ind == max: ind = 0
data = 0
available_path = config_folder + "/" + available_file
try: fp = os.path.exists(available_path)
except: fp = 0
if fp:
input = open(available_path,'r')
EOF = False
while not EOF:
line = input.readline()
if line:
if line[-1] == "\n": line = line[:-1]
available.append(eval(line))
else: EOF = True
else:
foo = find_avail_packages()
output = open(available_path,'w')
for pkg in available:
output.write(str(pkg) + "\n")
output.close()
print str(len(available)) + " packages available"
def package_search():
global available
global inst_pkglist
global version
global mirrors
global discsets
global download_folder
search = []
search_options = ["Search by Name","Search by Disk Set","Upgrade Installed Packages","Return to Main Menu"]
YN = ["No","Yes","No to All","Yes to All"]
search_choice = int(choose_by_index(search_options,"Search Method"))
if search_choice == 0:
term = raw_input("Enter Search Term: ")
for a_pkg in available:
found_term = a_pkg['name'].find(term,0,len(a_pkg['name']))
if not found_term:
a_vers = a_pkg['version']
a_disc = a_pkg['discset']
a_package = a_pkg['package']
a_rev = a_pkg['revision']
a_arch = a_pkg['arch']
i_vers = ''
i_rev = ''
i_package = ''
i_arch = ''
for i_pkg in inst_pkglist:
if i_pkg['name'] == a_pkg['name']:
i_vers = i_pkg['version']
i_rev = i_pkg['revision']
i_package = i_pkg['package']
i_arch = i_pkg['arch']
this_item = {}
this_item['name'] = a_pkg['name']
this_item['avail-vers'] = a_vers
this_item['avail-arch'] = a_arch
this_item['avail-rev'] = a_rev
this_item['avail-pkg'] = a_package
this_item['avail-disc'] = a_disc
this_item['avail-path'] = a_pkg['path']
this_item['inst-vers'] = i_vers
this_item['inst-arch'] = i_arch
this_item['inst-rev'] = i_rev
this_item['inst-pkg'] = i_package
search.append(this_item)
if len(search) == 0:
print "No results found for '" + term + "'"
elif search_choice == 1:
disc_choice = int(choose_by_index(discsets,"Disk Set"))
theDiskSet = discsets[disc_choice]
for a_pkg in available:
if a_pkg['discset'] == theDiskSet:
a_vers = a_pkg['version']
a_disc = a_pkg['discset']
a_package = a_pkg['package']
a_rev = a_pkg['revision']
a_arch = a_pkg['arch']
i_vers = ''
i_rev = ''
i_package = ''
i_arch = ''
for i_pkg in inst_pkglist:
if i_pkg['name'] == a_pkg['name']:
i_vers = i_pkg['version']
i_rev = i_pkg['revision']
i_package = i_pkg['package']
i_arch = i_pkg['arch']
this_item = {}
this_item['name'] = a_pkg['name']
this_item['avail-vers'] = a_vers
this_item['avail-arch'] = a_arch
this_item['avail-rev'] = a_rev
this_item['avail-pkg'] = a_package
this_item['avail-disc'] = a_disc
this_item['avail-path'] = a_pkg['path']
this_item['inst-vers'] = i_vers
this_item['inst-arch'] = i_arch
this_item['inst-rev'] = i_rev
this_item['inst-pkg'] = i_package
search.append(this_item)
if len(search) == 0:
print "No results found for '" + theDiskSet + "'"
elif search_choice == 2:
for i_pkg in inst_pkglist:
for a_pkg in available:
if i_pkg['name'] == a_pkg['name']:
if not (i_pkg['version'] == a_pkg['version'] and i_pkg['revision'] == a_pkg['revision']):
this_item = {}
this_item['name'] = a_pkg['name']
this_item['avail-vers'] = a_pkg['version']
this_item['avail-arch'] = a_pkg['arch']
this_item['avail-rev'] = a_pkg['revision']
this_item['avail-pkg'] = a_pkg['package']
this_item['avail-disc'] = a_pkg['discset']
this_item['avail-path'] = a_pkg['path']
this_item['inst-vers'] = i_pkg['version']
this_item['inst-arch'] = i_pkg['arch']
this_item['inst-rev'] = i_pkg['revision']
this_item['inst-pkg'] = i_pkg['package']
search.append(this_item)
if len(search) == 0:
print "No packages available for upgrade"
elif search_choice == 3:
main_menu()
if len(search) != 0:
download = []
skip_all = 0
dl_all = 0
print str(len(search)) + " package(s) found"
for found in search:
have_it = 0
print ""
if found['avail-vers'] == found['inst-vers'] and found['avail-rev'] == found['inst-rev']:
print "latest version of " + found['name'] + " is installed"
have_it = 1
elif found['inst-pkg'] == '':
print found['name'] + " is not installed"
if skip_all == 0 and dl_all == 0: dl = int(choose_by_index(YN,"to Download?"))
else: dl = 0
if dl == 1: download.append(found)
if dl == 2: skip_all = 1
if dl == 3: dl_all = 1
else:
print "a different version of " + found['name'] + " is installed"
print "Installed : " + found['inst-pkg']
print "Available : " + found['avail-pkg']
if skip_all == 0 and dl_all == 0: dl = int(choose_by_index(YN,"to Download?"))
else: dl = 0
if dl == 1: download.append(found)
if dl == 2: skip_all = 1
if dl == 3: dl_all = 1
if dl_all == 1 and have_it == 0: download.append(found)
if len(download) != 0:
print ""
print str(len(download)) + " package(s) to download"
for pkg in download:
ind = 0
max = len(mirrors)
data = 0
while not data:
try:
URL = mirrors[ind] + version + pkg['avail-path']
print "downloading " + pkg['avail-pkg'] + " from " + mirrors[ind]
wget_cmd = "wget -c " + URL
os.system(wget_cmd)
fp = os.path.exists(pkg['avail-pkg'])
if fp:
#file was downloaded
data = 1
# move file to downloads folder & delete wget_log
move_cmd = "mv " + pkg['avail-pkg'] + " " + download_folder
os.system(move_cmd)
fp2 = os.path.exists('wget-log')
if fp2: os.system('rm wget-log')
else:
#file was not downloaded
data = 0
ind += 1
if ind == max: ind = 0
except:
ind += 1
if ind == max: ind = 0
data = ""
def main_menu():
global menu
global inst_pkglist
global inst_path
global country_list
global country_path
global version
global version_path
menu_choice = int(choose_by_index(menu,"Options"))
if menu_choice == 0:
country = ""
country = choose_country()
os.unlink(country_path)
output = open(country_path,'w')
output.write(country)
output.close()
elif menu_choice == 1:
version = choose_version()
os.unlink(version_path)
output = open(version_path,'w')
output.write(version)
output.close()
elif menu_choice == 2:
inst_pkglist = get_installed_pkgs()
os.unlink(inst_path)
output = open(inst_path,'w')
for pkg in inst_pkglist:
output.write(str(pkg) + "\n")
output.close()
print str(len(inst_pkglist)) + " packages currently installed"
elif menu_choice == 3:
foo = find_avail_packages()
os.unlink(available_path)
output = open(available_path,'w')
for pkg in available:
output.write(str(pkg) + "\n")
output.close()
print str(len(available)) + " packages available"
elif menu_choice == 4:
package_search()
elif menu_choice == 5:
return
main_menu()
main_menu()
The same points as ALL of open source software. If you write something good you share with the community. Maybe if you tried it instead of just dumping on it you might even like it.
Given the large amount of open source software, I do not have the time to try them all unless I see a point. I can't see it here, and more importantly you are not willing to provide one.
Sorry, that's not going to work.
Fine, don't try it, but criticising someone for writing software isn't what this forum is all about.
The points.
1. because i had an itch to scratch
2. because I can't imagine a reason why you'd need to be root to download packages
3. because choosing from a menu is easier than editing config files
This revised version will install downloaded packages.
Code:
#! /usr/bin/python
import urllib,HTMLParser
import os,os.path
homedir = os.path.expanduser('~')
config_folder = homedir + "/.getpkg"
download_folder = config_folder + "/downloads"
installed_file = "installed"
available_file = "available"
country_file = "country"
version_file = "version"
try: fp = os.path.exists(config_folder)
except: fp =0
if not fp:
os.mkdir(config_folder)
try: fp = os.path.exists(download_folder)
except: fp =0
if not fp:
os.mkdir(download_folder)
packages_dir="/var/log/packages"
country_list = ["Australia","Austria","Belgium","Brasil","Bulgaria","Canada","Costa Rica","Czech Republic","Finland",\
"France","Germany","Greece","Hong Kong","Hungary","Ireland","Italy","Japan","Korea","Netherlands","Norway","Poland",\
"Portugal","Republic of Moldova","Romania","Russia","Serbia","South Africa","Spain","Sweden","Switzerland","Taiwan",\
"Thailand","UK","USA" ]
discsets = ["a","ap","d","e","f","gnome","k","kde","kdei","l","n","t","tcl","x","xap","extra","pasture","patches"]
slack_versions = ["8.1","9.0","9.1","10.0","current"]
menu = ["Choose Country","Choose Version","Update Installed List","Update Available List","Package Search",\
"List Downloaded Packages","Install Downloaded Packages","Empty Download Directory","Exit"]
mirror_list_url="http://www.slackware.com/getslack/list.php?country="
mirrors = []
available = []
def get_installed_pkgs():
installed = []
packages = os.listdir(packages_dir)
num_packages = len(packages)
for package in packages:
parts = package.split("-")
revision = parts.pop()
arch = parts.pop()
version = parts.pop()
pkgname = '-'.join(parts)
this_package = {'package' : package,'name' : pkgname,'version' : version,'arch' : arch,'revision' : revision}
installed.append(this_package)
return installed
def choose_by_index(arr,heading):
print ""
print "Choose " + heading
print "Please enter the number of your choice"
for i in range(len(arr)):
print str(i) + " : " + arr[i]
print ""
while 1:
try:
returnval = raw_input("Enter Index: ")
intvalue = int(returnval)
if intvalue >= 0 and intvalue < len(arr): break
else:
print "Invalid input, please try again"
print "Please enter a value between 0 and " + str(len(arr) -1)
except ValueError:
print "Invalid input, please try again"
print "Please enter a value between 0 and " + str(len(arr) -1)
return returnval
class MyHTMLParser(HTMLParser.HTMLParser):
global mirrors
def handle_starttag(self, tag, attrs):
if tag == "a" or tag == "A":
for url in attrs:
theHREF = url[1]
if theHREF[0:4] == "http" or theHREF[0:4] == "ftp:":
if theHREF != "http://store.slackware.com" and \
theHREF != "http://store.slackware.com/" and \
theHREF != "http://slackware.com/trademark/trademark.php":
# make sure the mirro has trailing /
if theHREF[-1] != "/": theHREF += "/"
mirrors.append(theHREF)
def read_filelist(filelist):
pkgs = []
while 1:
line = filelist.readline()
if line[-4:-1] == "tgz":
this_pkg = {}
words = line[:-1].split(" ")
this_pkg["filesize"] = words[len(words)-4]
package = words[len(words)-1]
path = package[2:]
this_pkg["path"] = path
parts = path.split("/")
if parts[0] == "slackware": disc = parts[1]
elif parts[0] == "source": break
else: disc = parts[0]
pkg = parts[len(parts)-1]
this_pkg["discset"] = disc
this_pkg["package"] = pkg
pkg_parts = pkg[:-4].split("-")
if len(pkg_parts) >= 4:
this_pkg['revision'] = pkg_parts.pop()
this_pkg['arch'] = pkg_parts.pop()
this_pkg['version'] = pkg_parts.pop()
this_pkg['name'] = '-'.join(pkg_parts)
else:
this_pkg['revision'] = ""
this_pkg['arch'] = ""
this_pkg['version'] = ""
this_pkg['name'] = ""
pkgs.append(this_pkg)
if not line: break
return pkgs
inst_path = config_folder + "/" + installed_file
try: fp = os.path.exists(inst_path)
except: fp = 0
if not fp:
inst_pkglist = get_installed_pkgs()
output = open(inst_path,'w')
for pkg in inst_pkglist:
output.write(str(pkg) + "\n")
output.close()
else:
input = open(inst_path,'r')
inst_pkglist = []
EOF = False
while not EOF:
line = input.readline()
if line:
if line[-1] == "\n": line = line[:-1]
inst_pkglist.append(eval(line))
else: EOF = True
print str(len(inst_pkglist)) + " packages currently installed"
def choose_country():
global mirrors
global country_list
mirrors = []
while len(mirrors) == 0:
country_choice = choose_by_index(country_list,"country")
URL = mirror_list_url + country_list[int(country_choice)]
f = urllib.urlopen(URL)
page = f.read()
p = MyHTMLParser()
p.feed(page)
if len(mirrors) == 0: print "No mirrors found in " + country_list[int(country_choice)]
else:
print "Available Mirrors in " + country_list[int(country_choice)] + ":"
for m in mirrors:
print m
return country_list[int(country_choice)]
country_path = config_folder + "/" + country_file
try: fp = os.path.exists(country_path)
except: fp = 0
if fp:
input = open(country_path,'r')
country = input.readline()
#country = country[:-1]
input.close()
URL = mirror_list_url + country
while len(mirrors) == 0:
f = urllib.urlopen(URL)
page = f.read()
p = MyHTMLParser()
p.feed(page)
if len(mirrors) == 0: print "No mirrors found in " + country
print "Available Mirrors in " + country + ":"
for m in mirrors:
print m
else:
country = choose_country()
output = open(country_path,'w')
output.write(country)
output.close()
def choose_version():
global slack_versions
version_choice = choose_by_index(slack_versions,"Slackware Version")
v = "slackware-" + slack_versions[int(version_choice)] + "/"
return v
version_path = config_folder + "/" + version_file
try: fp = os.path.exists(version_path)
except: fp = 0
if fp:
input = open(version_path,'r')
version = input.readline()
#version = version[:-1]
input.close()
else:
version = choose_version()
output = open(version_path,'w')
output.write(version)
output.close()
def find_avail_packages():
global mirrors
global version
global available
available = []
max = len(mirrors)
target = version + "FILELIST.TXT"
ind = 0
data = 0;
while not data:
URL = mirrors[ind] + target
print "opening " + URL
try:
file = urllib.urlopen(URL)
available = read_filelist(filelist=file)
data = 1
except:
ind += 1
if ind == max: ind = 0
data = 0
available_path = config_folder + "/" + available_file
try: fp = os.path.exists(available_path)
except: fp = 0
if fp:
input = open(available_path,'r')
EOF = False
while not EOF:
line = input.readline()
if line:
if line[-1] == "\n": line = line[:-1]
available.append(eval(line))
else: EOF = True
else:
foo = find_avail_packages()
output = open(available_path,'w')
for pkg in available:
output.write(str(pkg) + "\n")
output.close()
print str(len(available)) + " packages available"
def package_search():
global available
global inst_pkglist
global version
global mirrors
global discsets
global download_folder
search = []
search_options = ["Search by Name","Search by Disk Set","Upgrade Installed Packages","Return to Main Menu"]
YN = ["No","Yes","No to All","Yes to All"]
search_choice = int(choose_by_index(search_options,"Search Method"))
if search_choice == 0:
term = raw_input("Enter Search Term: ")
for a_pkg in available:
found_term = a_pkg['name'].find(term,0,len(a_pkg['name']))
if not found_term:
a_vers = a_pkg['version']
a_disc = a_pkg['discset']
a_package = a_pkg['package']
a_rev = a_pkg['revision']
a_arch = a_pkg['arch']
i_vers = ''
i_rev = ''
i_package = ''
i_arch = ''
for i_pkg in inst_pkglist:
if i_pkg['name'] == a_pkg['name']:
i_vers = i_pkg['version']
i_rev = i_pkg['revision']
i_package = i_pkg['package']
i_arch = i_pkg['arch']
this_item = {}
this_item['name'] = a_pkg['name']
this_item['avail-vers'] = a_vers
this_item['avail-arch'] = a_arch
this_item['avail-rev'] = a_rev
this_item['avail-pkg'] = a_package
this_item['avail-disc'] = a_disc
this_item['avail-path'] = a_pkg['path']
this_item['inst-vers'] = i_vers
this_item['inst-arch'] = i_arch
this_item['inst-rev'] = i_rev
this_item['inst-pkg'] = i_package
search.append(this_item)
if len(search) == 0:
print "No results found for '" + term + "'"
elif search_choice == 1:
disc_choice = int(choose_by_index(discsets,"Disk Set"))
theDiskSet = discsets[disc_choice]
for a_pkg in available:
if a_pkg['discset'] == theDiskSet:
a_vers = a_pkg['version']
a_disc = a_pkg['discset']
a_package = a_pkg['package']
a_rev = a_pkg['revision']
a_arch = a_pkg['arch']
i_vers = ''
i_rev = ''
i_package = ''
i_arch = ''
for i_pkg in inst_pkglist:
if i_pkg['name'] == a_pkg['name']:
i_vers = i_pkg['version']
i_rev = i_pkg['revision']
i_package = i_pkg['package']
i_arch = i_pkg['arch']
this_item = {}
this_item['name'] = a_pkg['name']
this_item['avail-vers'] = a_vers
this_item['avail-arch'] = a_arch
this_item['avail-rev'] = a_rev
this_item['avail-pkg'] = a_package
this_item['avail-disc'] = a_disc
this_item['avail-path'] = a_pkg['path']
this_item['inst-vers'] = i_vers
this_item['inst-arch'] = i_arch
this_item['inst-rev'] = i_rev
this_item['inst-pkg'] = i_package
search.append(this_item)
if len(search) == 0:
print "No results found for '" + theDiskSet + "'"
elif search_choice == 2:
for i_pkg in inst_pkglist:
for a_pkg in available:
if i_pkg['name'] == a_pkg['name']:
if not (i_pkg['version'] == a_pkg['version'] and i_pkg['revision'] == a_pkg['revision']):
this_item = {}
this_item['name'] = a_pkg['name']
this_item['avail-vers'] = a_pkg['version']
this_item['avail-arch'] = a_pkg['arch']
this_item['avail-rev'] = a_pkg['revision']
this_item['avail-pkg'] = a_pkg['package']
this_item['avail-disc'] = a_pkg['discset']
this_item['avail-path'] = a_pkg['path']
this_item['inst-vers'] = i_pkg['version']
this_item['inst-arch'] = i_pkg['arch']
this_item['inst-rev'] = i_pkg['revision']
this_item['inst-pkg'] = i_pkg['package']
search.append(this_item)
if len(search) == 0:
print "No packages available for upgrade"
elif search_choice == 3:
main_menu()
if len(search) != 0:
download = []
skip_all = 0
dl_all = 0
print str(len(search)) + " package(s) found"
for found in search:
have_it = 0
print ""
if found['avail-vers'] == found['inst-vers'] and found['avail-rev'] == found['inst-rev']:
print "latest version of " + found['name'] + " is installed"
have_it = 1
elif found['inst-pkg'] == '':
print found['name'] + " is not installed"
if skip_all == 0 and dl_all == 0: dl = int(choose_by_index(YN,"to Download?"))
else: dl = 0
if dl == 1: download.append(found)
if dl == 2: skip_all = 1
if dl == 3: dl_all = 1
else:
print "a different version of " + found['name'] + " is installed"
print "Installed : " + found['inst-pkg']
print "Available : " + found['avail-pkg']
if skip_all == 0 and dl_all == 0: dl = int(choose_by_index(YN,"to Download?"))
else: dl = 0
if dl == 1: download.append(found)
if dl == 2: skip_all = 1
if dl == 3: dl_all = 1
if dl_all == 1 and have_it == 0: download.append(found)
if len(download) != 0:
print ""
print str(len(download)) + " package(s) to download"
for pkg in download:
ind = 0
max = len(mirrors)
data = 0
while not data:
try:
URL = mirrors[ind] + version + pkg['avail-path']
print "downloading " + pkg['avail-pkg'] + " from " + mirrors[ind]
wget_cmd = "wget -c " + URL
os.system(wget_cmd)
fp = os.path.exists(pkg['avail-pkg'])
if fp:
#file was downloaded
data = 1
# move file to downloads folder & delete wget_log
move_cmd = "mv " + pkg['avail-pkg'] + " " + download_folder
os.system(move_cmd)
fp2 = os.path.exists('wget-log')
if fp2: os.system('rm wget-log')
else:
#file was not downloaded
data = 0
ind += 1
if ind == max: ind = 0
except:
ind += 1
if ind == max: ind = 0
data = ""
def list_downloaded_pkgs():
downloaded = os.listdir(download_folder)
if len(downloaded) == 0:
print "Download folder is empty"
return
for pkg in downloaded: print pkg
def install_downloaded_pkgs():
downloaded = os.listdir(download_folder)
if len(downloaded) == 0:
print "Download folder is empty"
return
for pkg in downloaded:
inst_cmd = "su -c 'upgradepkg --install-new " + download_folder + "/" + pkg + "'"
os.system(inst_cmd)
def rm_downloaded_pkgs():
downloaded = os.listdir(download_folder)
if len(downloaded) == 0:
print "Download folder is empty"
return
for pkg in downloaded:
rm_cmd = "rm " + download_folder + "/" + pkg
os.system(rm_cmd)
print str(len(downloaded)) + " packages removed"
def main_menu():
global menu
global inst_pkglist
global inst_path
global country_list
global country_path
global version
global version_path
menu_choice = int(choose_by_index(menu,"Options"))
if menu_choice == 0:
country = ""
country = choose_country()
os.unlink(country_path)
output = open(country_path,'w')
output.write(country)
output.close()
elif menu_choice == 1:
version = choose_version()
os.unlink(version_path)
output = open(version_path,'w')
output.write(version)
output.close()
elif menu_choice == 2:
inst_pkglist = get_installed_pkgs()
os.unlink(inst_path)
output = open(inst_path,'w')
for pkg in inst_pkglist:
output.write(str(pkg) + "\n")
output.close()
print str(len(inst_pkglist)) + " packages currently installed"
elif menu_choice == 3:
foo = find_avail_packages()
os.unlink(available_path)
output = open(available_path,'w')
for pkg in available:
output.write(str(pkg) + "\n")
output.close()
print str(len(available)) + " packages available"
elif menu_choice == 4:
package_search()
elif menu_choice == 5:
list_downloaded_pkgs()
elif menu_choice == 6:
install_downloaded_pkgs()
elif menu_choice == 7:
rm_downloaded_pkgs()
elif menu_choice == 8:
return
main_menu()
main_menu()
I do not know LQ's rules on posting masses of useless text, it is their traffic, but I know that I do not want to download hundreds of useless bytes just to follow this discussion. Could you maybe put the script somewhere on the internet and simply post the link?
Originally posted by uselpa Still, what's the point? Why should I use that instead of slackpkg for example, which is officially supported and can also install if requested?
that's totally beside the point... this was datadriven's first python program and he was just looking for people to give it a shot and perhaps even share some CONSTRUCTIVE feedback... this holier-than-though thing you have going on here is totally uncalled for... geez man, how can you be so insensitive???
Quote:
Given the large amount of open source software, I do not have the time to try them all unless I see a point. I can't see it here, and more importantly you are not willing to provide one.
Sorry, that's not going to work.
there you go again... dude, it's fairly OBVIOUS that the main point was the getting constructive feedback... and if you don't have the time or the desire to try his script then don't, but there's no need to be so anal-retentive about it by posting useless and unfounded critisism... don't you realize how ridiculous it is to ask for "reasons" to try someone's first python script???
don't worry datadriven, we're not all like this here at LQ...
anyways, it's true that posts as huge as your code can sometimes be inconvenient, so it's nice that you set-up an account at sf.net for your project and linked it here... i hope you keep hacking your script and continue on your python journey... don't let the negativity emanated by some folks bring you down...
i have no python knowledge, hence i can't contribute any actual code, but i'll try to give you some end-user feedback if i can, once i get around to trying your script... keep up the good work man!!! and keep coding!!!
BTW, I get this when I attempt to run your script (downloaded form SF)
Code:
Traceback (most recent call last):
File "./getpkg", line 124, in ?
inst_pkglist = get_installed_pkgs()
File "./getpkg", line 45, in get_installed_pkgs
version = parts.pop()
IndexError: pop from empty list
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.