#! /usr/bin/env python ###################################################################################### # # GETPKG is used to download and install packages for Slackware # # It is menu driven allowing the user to choose program options by entering # number associated with menu choices. It creates the folder ~/.getpkg and # stores configuration options and downloaded packages within that folder. # # It requires Slackware and python # # Author: Jeff Rossi # # This program is released under the GPL # ###################################################################################### import urllib,HTMLParser import urlparse import os,os.path import sys,time,string,math GETPKG_VERSION="0.3.4" homedir = os.path.expanduser('~') config_folder = homedir + "/.getpkg" download_folder = config_folder + "/downloads" desc_folder = config_folder + "/descriptions" installed_file = "installed" available_file = "available" country_file = "country" version_file = "version" exclude_file = "exclude" mirror_file = "mirrors" mirror_path = config_folder + "/" + mirror_file available_path = config_folder + "/" + available_file inst_path = config_folder + "/" + installed_file exclude_path = config_folder + "/" + exclude_file version_path = config_folder + "/" + version_file country_path = config_folder + "/" + country_file log_path = config_folder + "/log" UO_path = config_folder + "/" + "unofficial" UO_mirror_path = config_folder + "/" + "unofficial_mirrors" rem_file = config_folder + "/remote_machines" rem_list = [] packages_dir="/var/log/packages" version = "" UO_version = "" minWidth = 80 minHeight = 25 windowWidth = 0 windowHeight = 0 mirror_index = 0 UO_mirror_index =0 country_folder = "/usr/share/getpkg/countries/" GP_URL = "http://sourceforge.net/project/showfiles.php?group_id=130711" gp_file_downloads = [] 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) try: fp = os.path.exists(desc_folder) except: fp =0 if not fp: os.mkdir(desc_folder) discsets = [("a","The base Slackware system."), ("ap","Linux applications."), ("d","Program development tools."), ("e","GNU Emacs."), ("f","Answers to Frequently Asked Questions about Linux."), ("gnome","The GNOME desktop environment and applications."), ("k","Linux kernel source."), ("kde","The K Desktop Environment, applications, and Qt."), ("kdei","Language support for the K Desktop Environment."), ("l","System libraries."), ("n","Networking applications and utilities."), ("t","TeX typesetting language."), ("tcl","Tcl/Tk/TclX scripting languages and tools."), ("x","X Window System graphical user interface."), ("xap","Applications for the X Window System."), ("y","Classic text-based BSD games."), ("extra",""), ("pasture",""), ("patches","")] slack_versions = [("8.1",""), ("9.0",""), ("9.1",""), ("10.0",""), ("10.1",""), ("10.2",""), ("11.0",""), ("current","")] menu = [("Setup Menu",""), ("View Slackware Changelog",""), ("Update Available List",""), ("Package Search",""), ("View Package Descriptions",""), ("List Downloaded Packages",""), ("Install Downloaded Packages",""), ("Empty Download Directory",""), ("Manage Excluded Packages",""), ("Manage Unofficial Packages",""), ("Manage Network Machines",""), ("Enter Mirrors from Text File",""), ("View Getpkg Log File",""), ("Exit","")] SF_MIRRORS = ["puzzle","kent","citkit", "switch","peterhost","internap", "ufpr","jaist","voxel","ovh", "mesh","easynews","unc","nchc", "umn","surfnet","keihanna"] mirrors = [] available = [] exclude_list = [] UO_mirrors = [] UO_pkgs = [] class Dialog: def _path_to_executable(): """Uses which to find program""" p = os.popen("which dialog") path = p.readline() return path[:-1] _dialog_exe = _path_to_executable() _persistant = [] _current_gauge = 0 def _call_prog(self): """Add persistant arguments to the function call""" if len(self._persistant) > 0: cmd = self._dialog_exe for arg in self._persistant: cmd += arg return cmd else: return self._dialog_exe # list of program options to pass to executable _options = {'aspect': ' --aspect ', 'backtitle': ' --backtitle ', 'beep': ' --beep ', 'beep_after': ' --beep-after ', 'begin': ' --begin ', 'cancel_label': ' --cancel-label ', 'clear': ' --clear ', 'colors': ' --colors ', 'cr_wrap': ' --cr-wrap ', 'create_rc': ' --create-rc ', 'defaultno': ' --defaultno ', 'default_item': ' --default-item ', 'exit_label': ' --exit-label ', 'extra_button': ' --extra-button ', 'extra_label': ' --extra-label ', 'help': ' --help ', 'help_button': ' --help-button ', 'item_help': ' --item-help ', 'help_label': ' --help-label ', 'help_status': ' --help-status ', 'ignore': ' --ignore ', 'input_fd': ' --input-fd ', 'insecure': ' --insecure ', 'item_help': ' --item-help ', 'keep_window': ' --keep-window ', 'max_input': ' --max-input ', 'no_cancel': ' --no-cancel ', 'nocancel': ' --nocancel ', 'no_collapse': ' --no-collapse ', 'no_kill': ' --no-kill ', 'no_label': ' --no-label ', 'no_shadow': ' --no-shadow ', 'ok_label': ' --ok-label ', 'output_fd': ' --output-fd ', 'print_maxsize': ' --print-maxsize ', 'print_size': ' --print-size ', 'print_version': ' --print-version ', 'separate_output': ' --separate-output ', 'separator': ' --separator ', 'separate_widget': ' --separate-widget ', 'shadow': ' --shadow ', 'size_err': ' --size-err ', 'sleep': ' --sleep ', 'stderr': ' --stderr ', 'stdout': ' --stdout ', 'tab_correct': ' --tab-correct ', 'tab_len': ' --tab-len ', 'timeout': ' --timeout ', 'title': ' --title ', 'trim': ' --trim ', 'version': ' --version ', 'yes_label': ' --yes-label ', 'calendar': ' --calendar ', 'checklist': ' --checklist ', 'form': ' --form ', 'fselect': ' --fselect ', 'gauge': ' --gauge ', 'infobox': ' --infobox ', 'inputbox': ' --inputbox ', 'inputmenu': ' --inputmenu ', 'menu': ' --menu ', 'msgbox': ' --msgbox ', 'passwordbox': ' --passwordbox ', 'radiolist': ' --radiolist ', 'tailbox': ' --tailbox ', 'tailboxbg': ' --tailboxbg ', 'textbox': ' --textbox ', 'timebox': ' --timebox ', 'yesno': ' --yesno '} def clear_screen(self): """Make the terminal sane again before exit""" dia = self._call_prog() opts = self._options["clear"] opts += self._options["cr_wrap"] cmd = dia + opts os.system(cmd) def qstr(self,s): """Return argument s quoted""" return "\"" + str(s) + "\"" def get_window_size(self): """return the widow dimensions""" dia = self._call_prog() opts = self._options["stdout"] opts += self._options["print_maxsize"] cmd = dia + opts p = os.popen(cmd) output = p.readline() output = output.replace("\n","").replace("MaxSize: ","") return output def fileselect(self,initial="",w=30,h=6): """The file-selection dialog displays a text-entry window in which you can type a filename (or directory), and above that two windows with directory names and filenames. Here filepath can be a filepath in which case the file and directory windows will display the contents of the path and the text-entry window will contain the preselected filename. Use tab or arrow keys to move between the windows. Within the directory or filename windows, use the up/down arrow keys to scroll the current selection. Use the space-bar to copy the current selection into the text-entry window. Typing any printable characters switches focus to the text-entry window, entering that character as well as scrolling the directory and filename windows to the closest match. Use a carriage return or the "OK" button to accept the current value in the text-entry window and exit. On exit, the contents of the text-entry window are written to dialog's output.""" dia = self._call_prog() opts = self._options["stdout"] opts += self._options["fselect"] cmd = dia + opts + "\"" + initial + "\" " + str(h) + " " + str(w) p = os.popen(cmd) output = p.readline() return output def infobox(self,text,w=30,h=6,wait=2): """An info box is basically a message box. However, in this case, dialog will exit immediately after displaying the message to the user. The screen is not cleared when dialog exits, so that the message will remain on the screen until the calling shell script clears it later. This is useful when you want to inform the user that some operations are carrying on that may require some time to finish. On exit, no text is written to dialog's output. Only an "Ok" button is provided for input, but an ESC exit status may be returned.""" dia = self._call_prog() opts = self._options["infobox"] cmd = dia + opts + "\"" + text + "\" " + str(h) + " " + str(w) os.system(cmd) if wait != 0: time.sleep(wait) def msgbox(self,text,w=30,h=6): """A message box is very similar to a yes/no box. The only difference between a message box and a yes/no box is that a message box has only a single OK button. You can use this dialog box to display any message you like. After reading the message, the user can press the ENTER key so that dialog will exit and the calling shell script can continue its operation. On exit, no text is written to dialog's output. Only an "Ok" button is provided for input, but an ESC exit status may be returned.""" dia = self._call_prog() opts = self._options["msgbox"] cmd = dia + opts + "\"" + text + "\" " + str(h) + " " + str(w) os.system(cmd) def textbox(self,file,title="",w=75,h=20): """A text box lets you display the contents of a text file in a dialog box. It is like a simple text file viewer. The user can move through the file by using the cursor, PGUP/PGDN and HOME/END keys available on most keyboards. If the lines are too long to be displayed in the box, the LEFT/RIGHT keys can be used to scroll the text region horizontally. You may also use vi-style keys h, j, k, l in place of the cursor keys, and B or N in place of the pageup/pagedown keys. Scroll up/down using vi- style 'k' and 'j', or arrow-keys. Scroll left/right using vi-style 'h' and 'l', or arrow- keys. A '0' resets the left/right scrolling. For more convenience, vi-style forward and backward searching functions are also provided. On exit, no text is written to dialog's output. Only an "EXIT" button is provided for input, but an ESC exit status may be returned.""" dia = self._call_prog() if title != "": opts = self._options["title"] + ' ' + self.qstr(title) opts += self._options["textbox"] cmd = dia + opts + file + " " + str(h) + " " + str(w) os.system(cmd) def yesno(self,text,w=30,h=6): """A yes/no dialog box of size height rows by width columns will be displayed. The string specified by text is displayed inside the dialog box. If this string is too long to fit in one line, it will be automatically divided into multiple lines at appropriate places. The text string can also contain the sub-string "\n" or newline characters `\n' to control line breaking explicitly. This dialog box is useful for asking questions that require the user to answer either yes or no. The dialog box has a Yes button and a No button, in which the user can switch between by pressing the TAB key. On exit, no text is written to dialog's output. In addition to the "Yes" and "No" exit codes (see DIAGNOSTICS) an ESC exit status may be returned.""" dia = self._call_prog() opts = self._options["yesno"] cmd = dia + opts + "\"" + text + "\" " + str(h) + " " + str(w) output = os.system(cmd) # escape = 65280 # yes = 0 # no = 256 if output == 0: return 1 # yes else: return 0 # no or escape def inputbox(self,text,w=35,h=8,init=""): """An input box is useful when you want to ask questions that require the user to input a string as the answer. If init is supplied it is used to initialize the input string. When entering the string, the backspace, delete and cursor keys can be used to correct typing errors. If the input string is longer than can fit in the dialog box, the input field will be scrolled. On exit, the input string will be printed on dialog's output.""" dia = self._call_prog() opts = self._options["stdout"] opts += self._options["inputbox"] cmd = dia + opts + "\"" + text + "\" " + str(h) + " " + str(w) if init != "": cmd += " " + str(init) p = os.popen(cmd) output = p.readline() return output def radiolist(self,text,choices=[],w=35,h=12,lh=6): """A radiolist box is similar to a menu box. The only difference is that you can indicate which entry is currently selected, by setting its status to on. On exit, the name of the selected item is written to dialog's output.""" dia = self._call_prog() opts = self._options["stdout"] #opts += self._options["separate_output"] opts += self._options["radiolist"] cmd = dia + opts + "\"" + text + "\" " + str(h) + " " + str(w) + " " + str(lh) for c in choices: cmd += ' ' + self.qstr(c[0]) + ' ' + self.qstr(c[1]) + ' ' + str(c[2]) p = os.popen(cmd) output = p.readline() if output == "" or output == None: return # remove " from output if output[-1] == '"': output = output[1:-1] return output def checklist(self,text,choices=[],w=35,h=12,lh=6): """A checklist box is similar to a menu box; there are multiple entries presented in the form of a menu. Instead of choosing one entry among the entries, each entry can be turned on or off by the user. The initial on/off state of each entry is specified by status. On exit, a list of the tag strings of those entries that are turned on will be printed on dialog's output. If the --separate-output option is not given, the strings will be quoted to make it simple for scripts to separate them. this function accepts esch choice as a tuple (tag,item,status)""" dia = self._call_prog() opts = self._options["stdout"] opts += self._options["separate_output"] opts += self._options["extra_button"] opts += self._options["extra_label"] + "\"Check All\" " opts += self._options["checklist"] cmd = dia + opts + "\"" + text + "\" " + str(h) + " " + str(w) + " " + str(lh) for c in choices: cmd += ' ' + self.qstr(c[0]) + ' ' + self.qstr(c[1]) + ' ' + str(c[2]) p = os.popen(cmd) output = p.read() err = p.close() # err will be None for ok # err will be 256 for cancel # err will be 768 for extra # err will be 65280 for esc if err == 768: all = [] for c in choices: all.append((c[0],c[1],"on")) dia = self._call_prog() opts = self._options["stdout"] opts += self._options["separate_output"] opts += self._options["extra_button"] opts += self._options["extra_label"] + "\"Check All\" " opts += self._options["checklist"] cmd = dia + opts + "\"" + text + "\" " + str(h) + " " + str(w) + " " + str(lh) for c in all: cmd += ' ' + self.qstr(c[0]) + ' ' + self.qstr(c[1]) + ' ' + str(c[2]) p2 = os.popen(cmd) output = p2.read() output_list = [] o_split = output.split("\n") for line in o_split: if line != "": output_list.append(line) return output_list def menu(self,text,choices=[],w=35,h=12,lh=6): """As its name suggests, a menu box is a dialog box that can be used to present a list of choices in the form of a menu for the user to choose. Choices are displayed in the order given. Each menu entry consists of a tag string and an item string. The tag gives the entry a name to distinguish it from the other entries in the menu. The item is a short description of the option that the entry represents. The user can move between the menu entries by pressing the cursor keys, the first letter of the tag as a hot-key, or the number keys 1-9. There are menu-height entries displayed in the menu at one time, but the menu will be scrolled if there are more entries than that. On exit the tag of the chosen menu entry will be printed on dialog's output. If the --help-button option is given, the corresponding help text will be printed if the user selects the help button.""" dia = self._call_prog() opts = self._options["stdout"] #opts += self._options["separate_output"] opts += self._options["menu"] cmd = dia + opts + "\"" + text + "\" " + str(h) + " " + str(w) + " " + str(lh) for c in choices: cmd += ' ' + self.qstr(c[0]) + ' ' + self.qstr(c[1]) p = os.popen(cmd) output = p.readline() if output == "" or output == None: return # remove " from output if output[-1] == '"': output = output[1:-1] return output def passwordbox(self,text,w=35,h=8,stars=0): """A password box is similar to an input box, except that the text the user enters is not displayed. This is useful when prompting for passwords or other sensitive information. Be aware that if anything is passed in "init", it will be visible in the system's process table to casual snoopers. Also, it is very confusing to the user to provide them with a default password they cannot see. For these reasons, using "init" is highly discouraged. See "--insecure" if you do not care about your password. On exit, the input string will be printed on dialog's output.""" dia = self._call_prog() opts = self._options["stdout"] if stars == 1: opts += self._options["insecure"] opts += self._options["passwordbox"] cmd = dia + opts + "\"" + text + "\" " + str(h) + " " + str(w) p = os.popen(cmd) output = p.readline() return output def gauge_start(self,text="",w=50,h=12,p=0): """A gauge box displays a meter along the bottom of the box. The meter indicates the percentage. New percentages are read from standard input, one integer per line. The meter is updated to reflect each new percentage. If the standard input reads the string "XXX", then subsequent lines up to another "XXX" are used for a new prompt. The gauge exits when EOF is reached on the standard input. The percent value denotes the initial percentage shown in the meter. If not specified, it is zero. On exit, no text is written to dialog's output. The widget accepts no input, so the exit status is always OK.""" dia = self._call_prog() opts = self._options["gauge"] cmd = dia + opts + "\"" + text + "\" " + str(h) + " " + str(w) + " " + str(p) self._current_gauge = os.popen(cmd,'w') def gauge_update(self,perc=0,text=""): """Update the current gauge""" if text: cmd = 'XXX\n%d\n%s\nXXX\n' % (perc, text) else: cmd = '%d\n' % perc self._current_gauge.write(cmd) self._current_gauge.flush() def gauge_stop(self): """Stop the current gauge""" self._current_gauge.close() def set_p_opt(self,opt,*args): """Set persistant program options""" if self._options.has_key(opt): cmd = self._options[opt] for arg in args: cmd += ' ' + self.qstr(arg) self._persistant.append(cmd) else: self.infobox(opt + " is not a valid option") return class version_html_parser(HTMLParser.HTMLParser): global gp_file_downloads def handle_starttag(self, tag, attrs): if tag == "a" or tag == "A": for url in attrs: if url[0] == "href" or url[0] == "HREF": files = string.find(url[1],"prdownloads") if files != -1: gp_file_downloads.append(url[1]) def write_to_log(msg=""): global log_path if os.path.exists(log_path): input = open(log_path,"r") current_log = input.read() input.close() else: current_log = "" output = open(log_path,"w") p = os.popen("date") ts = p.read() logstr = str(string.rstrip(ts)) + " - " + msg + "\n" output.write(logstr) output.write(current_log) output.close() p.close() return def check_program_version(d): global GP_URL global GETPKG_VERSION global download_folder write_to_log("Check Version") f = urllib.urlopen(GP_URL) page = f.read() # fix broken HTML on sourceforge that crashes parser page = string.replace(page,"\n<") p = version_html_parser() p.feed(page) if len(gp_file_downloads) == 0: d.infobox("No downloads found") else: latest_file = urlparse.urlparse(gp_file_downloads[0]) theFile = string.replace(latest_file[2],"/getpkg/","") file_parts = theFile.split("-") file_version = file_parts[1] if file_version != GETPKG_VERSION: if d.yesno(file_version + " is now available. Download?"): download_latest_version(d,latest_file[2]) os.system("mv " + theFile + " " + download_folder) if d.yesno("Downloading Complete, Install Package?"): install_downloaded_pkgs(d) else: return else: d.infobox(GETPKG_VERSION + " is the latest version") return def download_latest_version(d,filepath): global SF_MIRRORS max = len(SF_MIRRORS) m_index = 0 dl = 0 write_to_log("Download Latest Getpkg") while 1: URL = "http://" + SF_MIRRORS[m_index] + ".dl.sourceforge.net/sourceforge" + filepath try: dl = text_file_download(d,URL,1,1) except: m_index += 1 if m_index == max: m_index = 0 if dl != 0: break def upload_user_mirror_list(d): global homedir global config_folder global slack_versions global windowWidth global windowHeight global mirrors global mirror_path netlocs = [] errors = [] user_mirror_list = [] m_URL = "" write_to_log("Upload User Mirror List") if int(windowWidth) > 90: textBoxWidth = 85 else: textBoxWidth = int(windowWidth) - 5 if int(windowHeight) > 25: textBoxHeight = 20 else: textBoxHeight = int(windowHeight) - 5 d.textbox("/usr/share/getpkg/file-dialog-inst","File Dialog Instructions",textBoxWidth,textBoxHeight) list = d.fileselect(homedir,textBoxWidth,textBoxHeight) if list != "" and os.path.isfile(list): input = open(list,"r") user_mirrors = config_folder + "/" + "user_mirrors" output = open(user_mirrors,"w") while 1: line = input.readline() if not line: break if line[-1] == "\n": line = line[:-1] (scheme,netloc,path,params,query,fragment) = urlparse.urlparse(line) have_mirror = 0 for n in netlocs: if n == netloc: have_mirror = 1 if not have_mirror: if scheme == "ftp" or scheme == "http": # remove version section from URL for v in slack_versions: this_version = "slackware-" + v[0] + "/" offset = 0 - len(this_version) if line[int(offset):] == this_version: line = line[:int(offset)] # check if URL is .iso file if line[-5:] == ".iso/" or line[-4:] == ".iso" or line[-5:] == "-iso/" or line[-4:] == "-iso": errors.append(line) else: user_mirror_list.append(line) netlocs.append(netloc) else: errors.append(line) input.close() for m in user_mirror_list: output.write(m + "\n") output.close() # add current mirror list & remove dupes if len(mirrors) == 0: input = open(mirror_path,"r") while 1: line = input.readline() if not line: break mirrors.append(line) input.close() for m in mirrors: i = 0 for um in user_mirror_list: if m == um: del user_mirror_list[i] i += 1 if len(user_mirror_list) > 0: mirrors.extend(user_mirror_list) mirrors = tr_mirrors(d,mirrors) heading = "Available Mirrors:\n\n" msg = "" maxLen = len(heading) if os.path.exists(mirror_path): os.system("rm " + mirror_path) output = open(mirror_path,'w') for m in mirrors: output.write(m + "\n") msg += m + "\n" if len(m) > maxLen: maxLen = len(m) output.close() text = heading + msg d.infobox(text,maxLen+12,len(mirrors)+6) if len(errors) > 0: tmp = homedir + "/getpkg-errors" output = open(tmp,"w") output.write("Unable to process the following mirrors.\n\n") for e in errors: output.write(e + "\n") output.close() d.textbox(tmp,"Mirror Errors",textBoxWidth,textBoxHeight) os.unlink(tmp) else: d.infobox("Please choose a file") return def package_download(d,fPath,mName,pkgnum=0,pkgtotal=0,filesize=0): global version log_open = 0 file_complete = 0 filename = os.path.basename(fPath) URL = mName + fPath write_to_log("Download " + filename) msg = "Package " + str(pkgnum) + " out of " + str(pkgtotal) + "\n\n" msg += "downloading " + filename + " from " + mName p = os.popen("wget -t 2 -b -o getpkg-wget-log -c " + URL) if os.path.exists("getpkg-wget-log"): log = open("getpkg-wget-log","r") log_open = 1 if filesize != 0: d.gauge_start(msg) fp = 0 total = int(filesize) while 1: if fp == 0: try: fp = os.path.exists(filename) except: fp = 0 if fp: fs = int(os.path.getsize(filename)) else: fs = 0 percentage = float(fs) / float(total) gauge_level = int(percentage * 100) if gauge_level > 100: gauge_level = 100 d.gauge_update(gauge_level) if fs == int(filesize): file_complete = 1 break if log_open: line = log.readline() if line: finished = string.find(str(line),"saved") if finished != -1: file_complete = 1 break else : if os.path.exists("getpkg-wget-log"): log = open("getpkg-wget-log","r") log_open = 1 time.sleep(0.5) d.gauge_stop() else: # read log to find when package is done d.infobox(msg,50,6) while 1: if log_open: line = log.readline() if line: finished = string.find(str(line),"saved") if finished != -1: file_complete = 1 break else : if os.path.exists("getpkg-wget-log"): log = open("getpkg-wget-log","r") log_open = 1 if os.path.exists("getpkg-wget-log"): os.unlink("getpkg-wget-log") if os.path.exists("wget-log"): os.unlink("wget-log") return file_complete def text_file_download(d,url,pkgnum=0,pkgtotal=0): global windowWidth log_open = 0 filename = os.path.basename(url) write_to_log("Download " + filename) p = os.popen("wget -t 2 -o getpkg-wget-log -c " + url) if os.path.exists("getpkg-wget-log"): log = open("getpkg-wget-log","r") log_open = 1 file_complete = 0 msg = "Downloading File " + str(pkgnum) + " out of " + str(pkgtotal) + "\n\n" msg += url boxWidth = len(url) + 5 if boxWidth > int(windowWidth): boxWidth = int(windowWidth) - 5 d.infobox(msg,boxWidth,6) while 1: if log_open: line = log.readline() if line: finished = string.find(str(line),"saved") if finished != -1: file_complete = 1 break else : if os.path.exists("getpkg-wget-log"): log = open("getpkg-wget-log","r") log_open = 1 time.sleep(0.5) os.unlink("getpkg-wget-log") return file_complete def download_file(d,filepath,pkgnum=0,pkgtotal=0,filesize=0,checksum=""): global mirrors global version global download_folder global desc_folder global mirror_index filename = os.path.basename(filepath) pkg_counter = 1 max = len(mirrors) been_dl = 0 data = 0 while not data: downloaded = os.listdir(download_folder) for dl in downloaded: if dl == filename: d.infobox(dl + " found in " + download_folder) been_dl = 1 pkg_counter += 1 data = 1 if not been_dl: try: URL = mirrors[mirror_index] + version + filepath been_dl = package_download(d,version + filepath,mirrors[mirror_index],pkgnum,pkgtotal,filesize) if been_dl: data = 1 #file was downloaded #check filesize against value from filelist fs = int(os.path.getsize(filename)) if filesize != 0: if fs == int(filesize): data = 1 # move file to downloads folder move_cmd = "mv " + filename + " " + download_folder os.system(move_cmd) if checksum != "": p2 = os.popen("md5sum " + download_folder + "/" + filename) pkgsum = p2.readline() if pkgsum[:32] == checksum: d.infobox("Checksums " + checksum + " match for " + filename,50,9) else: d.infobox("Checksums " + pkgsum[:32] + " and " + checksum + " do not match for " + filename,50,12) data = 0 else: d.infobox("Filesize " + str(fs) + " does not match value of " + filesize,50,9) data = 0 been_dl = package_download(d,version + filepath,mirrors[mirror_index],pkgnum,pkgtotal,filesize) else: #file was not downloaded data = 0 mirror_index += 1 if mirror_index == max: mirror_index = 0 except: mirror_index += 1 if mirror_index == max: mirror_index = 0 data = 0 fp2 = os.path.exists('wget-log') if fp2: os.system('rm wget-log*') return download_folder + "/" + filename def download_UO_file(d,filepath,pkgnum=0,pkgtotal=0,filesize=0,checksum=""): global UO_mirrors global version global UO_version global download_folder global UO_mirror_index if version == "slackware-current/": UO_version = "Slackware-10.1/" else: UO_version = "S" + version[1:] filename = os.path.basename(filepath) pkg_counter = 1 max = len(UO_mirrors) been_dl = 0 data = 0 while not data: downloaded = os.listdir(download_folder) for dl in downloaded: if dl == filename: d.infobox(dl + " found in " + download_folder) been_dl = 1 pkg_counter += 1 data = 1 if not been_dl: try: been_dl = package_download(d,UO_version + filepath,UO_mirrors[UO_mirror_index],pkgnum,pkgtotal,filesize) if been_dl: data = 1 #file was downloaded #check filesize against value from filelist fs = int(os.path.getsize(filename)) if filesize != 0: if fs == int(filesize): data = 1 # move file to downloads folder move_cmd = "mv " + filename + " " + download_folder os.system(move_cmd) if checksum != "": p2 = os.popen("md5sum " + download_folder + "/" + filename) pkgsum = p2.readline() if pkgsum[:32] == checksum: d.infobox("Checksums " + checksum + " match for " + filename,50,9) else: d.infobox("Checksums " + pkgsum[:32] + " and " + checksum + " do not match for " + filename,50,12) data = 0 else: d.infobox("Filesize " + str(fs) + " does not match value of " + filesize,50,9) data = 0 been_dl = package_download(d,UO_version + filepath,UO_mirrors[UO_mirror_index],pkgnum,pkgtotal,filesize) else: #file was not downloaded data = 0 UO_mirror_index += 1 if UO_mirror_index == max: UO_mirror_index = 0 except: UO_mirror_index += 1 if UO_mirror_index == max: UO_mirror_index = 0 data = 0 fp2 = os.path.exists('wget-log') if fp2: os.system('rm wget-log*') return download_folder + "/" + filename def get_installed_pkgs(d): global packages_dir installed = [] write_to_log("Update Installed List") try: packages = os.listdir(packages_dir) except: packages = [] if len(packages) > 0: for package in packages: parts = package.split("-") if len(parts) > 3: revision = parts.pop() arch = parts.pop() version = parts.pop() pkgname = '-'.join(parts) this_package = {} this_package['package'] = package this_package['name'] = pkgname this_package['version'] = version this_package['arch'] = arch this_package['revision'] = revision installed.append(this_package) else: msg = package + " does not follow proper naming scheme. " msg += "It will not be counted as an installed package" d.infobox(msg,40,10) d.infobox(str(len(installed)) + " packages currently installed") return installed def read_filelist(filelist): fp = open(filelist,'r') pkgs = [] while 1: line = fp.readline() if line[-4:-1] == "tgz": this_pkg = {} words = [] line_parts = line[:-1].split(" ") for i in range(len(line_parts)): if line_parts[i] != "": words.append(line_parts[i]) this_pkg["filesize"] = 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 fp.close() os.unlink(filelist) return pkgs def read_UO_filelist(filelist): fp = open(filelist,'r') pkgs = [] while 1: line = fp.readline() if line[-4:-1] == "tgz": this_pkg = {} words = [] line_parts = line[:-1].split(" ") for i in range(len(line_parts)): if line_parts[i] != "": words.append(line_parts[i]) # package is last word, filesize is word 4 this_pkg["filesize"] = words[4] package = words[len(words)-1] path = package[2:] this_pkg["path"] = path parts = path.split("/") pkg = parts[len(parts)-1] 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 fp.close() os.unlink(filelist) return pkgs def read_checksums(checksums): fp = open(checksums,'r') pkgs = [] while 1: line = fp.readline() if line[-4:-1] == "tgz": this_pkg = {} words = line[:-1].split(" ") path = words[len(words)-1][2:] sum = words[0] this_pkg['checksum'] = sum this_pkg['path'] = path pkgs.append(this_pkg) if not line: break fp.close() os.unlink(checksums) return pkgs def tr_mirrors(d,mirror_list): sort_list = {} loss_list = [] final_list = [] m_list = [] max = len(mirror_list) counter = 1 write_to_log("Update Mirrors") for m in mirror_list: this_mirror = {} this_mirror['url'] = m (scheme,netloc,path,params,query,fragment) = urlparse.urlparse(m) p = os.popen("traceroute -n -w 2 -q 1 " + netloc + " 2> /dev/null") d.set_p_opt("title","GETPKG " + GETPKG_VERSION + " (" + str(counter) + " of " + str(max) + ")") msg = "Testing " + m d.infobox(msg,len(msg)+6,6) hops = 0 time = 0 while 1: line = p.readline() if not line: break if line[4:-1] == "*": time += 200 # add 200 ms for hops that return * words = line[4:-1].split(" ") if len(words) == 4: time += math.floor(float(words[2])) hops += 1 this_mirror['hops'] = hops this_mirror["time"] = int(time) m_list.append(this_mirror) counter += 1 for m in m_list: if m['time'] != 0: sort_list[m['url']] = m['time'] else: loss_list.append(m['url']) times = sort_list.values() times.sort() current_time = 0 for t in times: if t != current_time: current_time = t for url in sort_list.keys(): if sort_list[url] == current_time: final_list.append(url) if len(loss_list) > 0: for item in loss_list: final_list.append(item) d.set_p_opt("title","GETPKG " + GETPKG_VERSION) return final_list def choose_country(d): global mirrors global mirror_path global country_folder mirrors = [] heading = "Choose Country for Mirrors" maxLen = len(heading) country_list = os.listdir(country_folder) country_list.sort() country_menu = [] write_to_log(heading) for c in country_list: theLen = len(c) if theLen > maxLen: maxLen = theLen country_menu.append((c,"")) while len(mirrors) == 0: while 1: if len(country_list) > 12: scrollLen = 12 else: scrollLen = len(country_list) country = d.menu(heading,country_menu,maxLen+12,scrollLen+6,scrollLen) if country != "" and country != None: break input = open(country_folder + country,'r') EOF = False while not EOF: line = input.readline() if line: if line[-1] == "\n": line = line[:-1] mirrors.append(line) else: EOF = True input.close() if len(mirrors) == 0: d.infobox("No mirrors found in " + country) else: mirrors = tr_mirrors(d,mirrors) heading = "Available Mirrors in " + country + ":\n\n" msg = "" maxLen = len(heading) if os.path.exists(mirror_path): os.system("rm " + mirror_path) output = open(mirror_path,'w') for m in mirrors: output.write(m + "\n") msg += m + "\n" if len(m) > maxLen: maxLen = len(m) output.close() text = heading + msg d.infobox(text,maxLen+12,len(mirrors)+6) return country def choose_version(d): global slack_versions heading = "Choose Slackware Version" write_to_log(heading) maxLen = len(heading) for v in slack_versions: theLen = len(v[0]) + len(v[1]) if theLen > maxLen: maxLen = theLen while 1: version = d.menu(heading,slack_versions,maxLen+12,len(slack_versions)+6,len(slack_versions)) if version != "" and version != None: break v = "slackware-" + version + "/" return v def find_avail_packages(d): global mirrors global version global available global mirror_index max = len(mirrors) available = [] filelist_path = "FILELIST.TXT" write_to_log("Update Available List") while 1: url = mirrors[mirror_index] + version + filelist_path try: dl = text_file_download(d,url,1,2) except: dl = 0 if dl: break else: mirror_index += 1 if mirror_index == max: mirror_index = 0 d.infobox("Reading File List") available = read_filelist(filelist_path) checksum_path = "CHECKSUMS.md5" while 1: url = mirrors[mirror_index] + version + checksum_path try: dl = text_file_download(d,url,2,2) except: dl = 0 if dl: break else: mirror_index += 1 if mirror_index == max: mirror_index = 0 d.infobox("Reading Checksum List") checksums = read_checksums(checksum_path) for pkg in available: for csum in checksums: if pkg['path'] == csum['path']: pkg['checksum'] = csum['checksum'] d.infobox(str(len(available)) + " packages available") return available def update_UO_packages(d): global UO_path global UO_mirror_path global UO_mirrors global UO_mirror_index global version max = len(UO_mirrors) UO_pkgs = [] write_to_log("Update Unofficial List") d.infobox("Updating unofficial package list from linuxpackages.net mirrors",40,5) if version == "slackware-current/": UO_version = "Slackware-10.1/" else: UO_version = "S" + version[1:] mirror_list_path = "/usr/share/getpkg/unofficial" if not os.path.exists(UO_mirror_path): input = open(mirror_list_path,'r') if input: while 1: line = input.readline() if not line: break if line[-1] == "\n": line = line[:-1] UO_mirrors.append(line) UO_mirrors = tr_mirrors(d,UO_mirrors) heading = "Mirrors for Unofficial Packages:\n\n" msg = "" maxLen = len(heading) if os.path.exists(UO_mirror_path): os.system("rm " + UO_mirror_path) output = open(UO_mirror_path,'w') for m in UO_mirrors: output.write(m + "\n") msg += m + "\n" if len(m) > maxLen: maxLen = len(m) output.close() text = heading + msg d.infobox(text,maxLen+12,len(UO_mirrors)+6) else: d.infobox("Unofficial mirror list not found") return else: # read Unofficial mirror list input = open(UO_mirror_path,'r') while 1: line = input.readline() if not line: break if line[-1] == "\n": line = line[:-1] UO_mirrors.append(line) input.close() if os.path.exists(UO_path): os.system("rm " + UO_path) filelist_path = "FILELIST.TXT" while 1: url = UO_mirrors[UO_mirror_index] + UO_version + filelist_path try: dl = text_file_download(d,url,1,2) except: dl = 0 if dl: break else: UO_mirror_index += 1 if UO_mirror_index == max: UO_mirror_index = 0 d.infobox("Reading File List") UO_pkgs = read_UO_filelist(filelist_path) checksum_path = "CHECKSUMS.md5" while 1: url = UO_mirrors[UO_mirror_index] + UO_version + checksum_path try: dl = text_file_download(d,url,2,2) except: dl = 0 if dl: break else: UO_mirror_index += 1 if UO_mirror_index == max: UO_mirror_index = 0 d.infobox("Reading Checksum List") checksums = read_checksums(checksum_path) for pkg in UO_pkgs: for csum in checksums: if pkg['path'] == csum['path']: pkg['checksum'] = csum['checksum'] d.infobox(str(len(UO_pkgs)) + " packages available") if os.path.exists(filelist_path): os.system("rm " + filelist_path) if os.path.exists(checksum_path): os.system("rm " + checksum_path) if os.path.exists("getpkg-wget-log"): os.system("rm getpkg-wget-log*") output = open(UO_path,'w') for pkg in UO_pkgs: output.write(str(pkg) + "\n") return UO_pkgs def UO_package_search(d): global UO_pkgs global UO_path global UO_mirror_path global UO_mirrors global download_folder global inst_pkglist search = [] if len(UO_pkgs) == 0: UO_pkgs = update_UO_packages(d) while 1: term = d.inputbox("Enter Search Term: ") if term != "": break for a_pkg in UO_pkgs: needle = term.lower() haystack = a_pkg['name'].lower() found_term = string.find(haystack,needle) if found_term != -1: a_vers = a_pkg['version'] 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['filesize'] = a_pkg['filesize'] 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-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 this_item['checksum'] = a_pkg['checksum'] search.append(this_item) if len(search) == 0: d.infobox("No results found for '" + term + "'") if len(search) != 0: dl_choices = [] ex_list = [] download = [] download_choices = [] d.infobox(str(len(search)) + " package(s) found") maxLen = 0 lineCount = 0 for found in search: have_it = 0 excluded = 0 if len(exclude_list) > 0: for e_pkg in exclude_list: if e_pkg == found['name']: excluded = 1 if found['avail-vers'] == found['inst-vers'] and found['avail-rev'] == found['inst-rev']: # installed if not excluded: dl_choices.append((found['avail-pkg'],"Installed",0)) else: ex_list.append(found['avail-pkg']) elif found['inst-pkg'] == '': # not installed if not excluded: dl_choices.append((found['avail-pkg'],"Not Installed",0)) else: ex_list.append(found['avail-pkg']) else: # different version installed if not excluded: dl_choices.append((found['avail-pkg'],found['inst-pkg'] + " Installed",0)) else: ex_list.append(found['avail-pkg']) if len(ex_list) > 0: l_cnt = 6 msg = "The following packages have been excluded\n" for ex in ex_list: msg += ex + "\n" l_cnt += 1 d.msgbox(msg,50,l_cnt) if len(dl_choices) > 0: heading = "Choose packages to download" maxLen = len(heading) for dl in dl_choices: dlLen = len(dl[0]) + len(dl[1]) + 10 if dlLen > maxLen: maxLen = dlLen if len(dl_choices) < 12: scrollLen = len(dl_choices) else : scrollLen = 12 download_choices = d.checklist(heading,dl_choices,maxLen+12,scrollLen+6,scrollLen) if len(download_choices) > 0: for dl in download_choices: for found in search: if dl == found['avail-pkg']: download.append(found) if len(download) != 0: pkg_counter = 1 for pkg in download: download_UO_file(d,pkg['avail-path'],pkg_counter,len(download),pkg['filesize'],pkg['checksum']) pkg_counter += 1 if d.yesno("Downloading Complete, Install Packages?"): install_downloaded_pkgs(d) else: return else: return else: return def manage_exclude_list(d): global available global exclude_list global exclude_path global windowWidth global windowHeight if int(windowWidth) > 90: textBoxWidth = 85 else: textBoxWidth = int(windowWidth) - 5 if int(windowHeight) > 25: textBoxHeight = 20 else: textBoxHeight = int(windowHeight) - 5 exc_search = [] exclude_list = [] ex_choices = [] pkgs_to_add = [] try: fp = os.path.exists(exclude_path) except: fp = 0 if fp: input = open(exclude_path,'r') EOF = False while not EOF: line = input.readline() if line: if line[-1] == "\n": line = line[:-1] exclude_list.append(line) else: EOF = True else: d.infobox("No packages are currently excluded") exc_menu = [("List Excluded Packages",""), ("Add Package(s) By Name",""), ("Add Package(s) by Disk Set",""), ("Remove Packages From List",""), ("Delete Entire Exclude List",""), ("Return to Main Menu","")] heading = "Choose Exclude List Option" maxLen = len(heading) for e in exc_menu: theLen = len(e[0]) + len(e[1]) if theLen > maxLen: maxLen = theLen while 1: exc_choice = d.menu(heading,exc_menu,maxLen+12,len(exc_menu)+6,len(exc_menu)) if exc_choice != "": break if exc_choice == "Add Package(s) By Name": while 1: term = d.inputbox("Enter Package to exclude : ") if term != "": break else: d.infobox("Please enter term to search for packages") ex_count = 0 for pkg in available: needle = term.lower() haystack = pkg['name'].lower() found_term = string.find(haystack,needle) if found_term != -1: ex_choices.append((pkg['name'],"",0)) ex_count += 1 if ex_count == 0: d.infobox("No packages found matching '" + term + "'") else: pkgs_to_add = d.checklist("Choose packages to exclude",ex_choices,50,16,10) if len(pkgs_to_add) > 0: exclude_list.extend(pkgs_to_add) write_to_log("Added package(s) to exclude list") elif exc_choice == "Add Package(s) by Disk Set": heading = "Choose Disk Set" maxLen = len(heading) for disc in discsets: theLen = len(disc[0]) + len(disc[1]) if theLen > maxLen: maxLen = theLen while 1: if len(discsets) > 12: scrollLen = 12 else: scrollLen = len(discsets) theDiskSet = d.menu(heading,discsets,maxLen+18,scrollLen+6,scrollLen) if theDiskSet == None: main_menu(d) if theDiskSet != "": break ex_count = 0 for pkg in available: if pkg['discset'] == theDiskSet: ex_choices.append((pkg['name'],"",0)) ex_count += 1 if ex_count == 0: d.infobox("No packages found matching disk set '" + theDiskSet + "'") else: pkgs_to_add = d.checklist("Choose packages to exclude",ex_choices,50,16,10) if len(pkgs_to_add) > 0: exclude_list.extend(pkgs_to_add) write_to_log("Added package(s) to exclude list") elif exc_choice == "Remove Packages From List": if len(exclude_list) > 0: rm_menu = [] heading = "Choose Package(s) to Remove" maxLen = len(heading) for exc in exclude_list: rm_menu.append((exc,"",0)) if len(exc) > maxLen: maxLen = len(exc) if len(rm_menu) > 15: scrollHgt = 15 else: scrollHgt = len(rm_menu) winHgt = scrollHgt + 6 rm_choice = d.checklist(heading,rm_menu,maxLen+12,winHgt,scrollHgt) if len(rm_choice) > 0: write_to_log("Remove package(s) to exclude list") for rm in rm_choice: i = 0 for ex in exclude_list: if rm == ex: del exclude_list[i] i += 1 else: d.infobox("No packages are currently excluded") elif exc_choice == "Delete Entire Exclude List": write_to_log("Delete exclude list") try: fp = os.path.exists(exclude_path) except: fp = 0 if fp: os.system("rm " + exclude_path) exclude_list = [] elif exc_choice == "List Excluded Packages": if len(exclude_list) > 0: d.textbox(exclude_path,str(len(exclude_list)) + " Packages Excluded",textBoxWidth,int(windowHeight)-6) else: d.infobox("No packages are currently excluded") elif exc_choice == "Return to Main Menu" or exc_choice == None: return if len(exclude_list) > 0: try: fp = os.path.exists(exclude_path) except: fp = 0 if fp: os.system("rm " + exclude_path) output = open(exclude_path,'w') exclude_list.sort() for pkg in exclude_list: output.write(str(pkg) + "\n") output.close() manage_exclude_list(d) def package_search(d): global available global inst_pkglist global version global mirrors global discsets global download_folder global desc_folder search = [] search_options = [("Search by Package Name",""), ("Search by Disk Set",""), ("Upgrade Installed Packages",""), ("Return to Main Menu","")] heading = "Choose Search Option" maxLen = len(heading) for s in search_options: theLen = len(s[0]) + len(s[1]) if theLen > maxLen: maxLen = theLen while 1: search_choice = d.menu(heading,search_options,maxLen+12,len(search_options)+6,len(search_options)) if search_choice != "": break if search_choice == "Search by Package Name": while 1: term = d.inputbox("Enter Search Term: ") if term != "": break for a_pkg in available: needle = term.lower() haystack = a_pkg['name'].lower() found_term = string.find(haystack,needle) if found_term != -1: 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['filesize'] = a_pkg['filesize'] 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 this_item['checksum'] = a_pkg['checksum'] search.append(this_item) if len(search) == 0: d.infobox("No results found for '" + term + "'") elif search_choice == "Search by Disk Set": heading = "Choose Disk Set" maxLen = len(heading) for disc in discsets: theLen = len(disc[0]) + len(disc[1]) if theLen > maxLen: maxLen = theLen while 1: if len(discsets) > 12: scrollLen = 12 else: scrollLen = len(discsets) theDiskSet = d.menu(heading,discsets,maxLen+18,scrollLen+6,scrollLen) if theDiskSet == None: main_menu(d) if theDiskSet != "": break 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['filesize'] = a_pkg['filesize'] 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 this_item['checksum'] = a_pkg['checksum'] search.append(this_item) if len(search) == 0: d.infobox("No results found for '" + theDiskSet + "'") elif search_choice == "Upgrade Installed Packages": 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['filesize'] = a_pkg['filesize'] 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'] this_item['checksum'] = a_pkg['checksum'] search.append(this_item) if len(search) == 0: d.infobox("No packages available for upgrade") elif search_choice == "Return to Main Menu": return if len(search) != 0: dl_choices = [] ex_list = [] download = [] download_choices = [] d.infobox(str(len(search)) + " package(s) found") maxLen = 0 lineCount = 0 for found in search: have_it = 0 excluded = 0 if len(exclude_list) > 0: for e_pkg in exclude_list: if e_pkg == found['name']: excluded = 1 if found['avail-vers'] == found['inst-vers'] and found['avail-rev'] == found['inst-rev']: # installed if not excluded: dl_choices.append((found['avail-pkg'],"Installed",0)) else: ex_list.append(found['avail-pkg']) elif found['inst-pkg'] == '': # not installed if not excluded: dl_choices.append((found['avail-pkg'],"Not Installed",0)) else: ex_list.append(found['avail-pkg']) else: # different version installed if not excluded: dl_choices.append((found['avail-pkg'],found['inst-pkg'] + " Installed",0)) else: ex_list.append(found['avail-pkg']) if len(ex_list) > 0: l_cnt = 6 msg = "The following packages have been excluded\n" for ex in ex_list: msg += ex + "\n" l_cnt += 1 d.msgbox(msg,50,l_cnt) if len(dl_choices) > 0: heading = "Choose packages to download" maxLen = len(heading) for dl in dl_choices: dlLen = len(dl[0]) + len(dl[1]) + 10 if dlLen > maxLen: maxLen = dlLen if len(dl_choices) < 12: scrollLen = len(dl_choices) else : scrollLen = 12 download_choices = d.checklist(heading,dl_choices,maxLen+12,scrollLen+6,scrollLen) if len(download_choices) > 0: for dl in download_choices: for found in search: if dl == found['avail-pkg']: download.append(found) if len(download) != 0: pkg_counter = 1 for pkg in download: download_file(d,pkg['avail-path'],pkg_counter,len(download),pkg['filesize'],pkg['checksum']) pkg_counter += 1 if d.yesno("Downloading Complete, Install Packages?"): install_downloaded_pkgs(d) else: return else: return def list_downloaded_pkgs(d): downloaded = os.listdir(download_folder) if len(downloaded) == 0: d.infobox("Download folder is empty") return msg = str(len(downloaded)) + " packages downloaded\n\n" maxLen = len(msg) for pkg in downloaded: msg += pkg + "\n" if len(pkg) > maxLen: maxLen = len(pkg) d.infobox(msg,maxLen+6,len(downloaded)+6) return def install_downloaded_pkgs(d): global download_folder global desc_folder global inst_path downloaded = os.listdir(download_folder) if len(downloaded) == 0: d.infobox("Download folder is empty") return if len(downloaded) > 0: heading = "Choose Package(s) to Install" maxLen = len(heading) downloaded_list = [] for dl in downloaded: if len(dl) > maxLen: maxLen = len(dl) downloaded_list.append((dl,"",0)) if len(downloaded) > 12: scrollLen = 12 else: scrollLen = len(downloaded) inst_choice = d.checklist(heading,downloaded_list,maxLen+12,scrollLen+6,scrollLen) if len(inst_choice) > 0: os.system("clear") print "Installing packages requires root access." print "Please enter your password." #inst_cmd = "su -c '/usr/bin/getpkg-installer" # change because some packages ask questions during install inst_cmd = "su -c 'upgradepkg --install-new" for pkg in inst_choice: inst_cmd += " " + download_folder + "/" + pkg inst_cmd += "'" os.system(inst_cmd) write_to_log("Install package(s) : " + ", ".join(inst_choice)) inst_pkglist = get_installed_pkgs(d) os.unlink(inst_path) output = open(inst_path,'w') for pkg in inst_pkglist: output.write(str(pkg) + "\n") output.close() return def rm_downloaded_pkgs(d): downloaded = os.listdir(download_folder) if len(downloaded) == 0: d.infobox("Download folder is empty") return for pkg in downloaded: rm_cmd = "rm " + download_folder + "/" + pkg os.system(rm_cmd) descriptions = os.listdir(desc_folder) if len(descriptions) != 0: for desc in descriptions: rm_cmd = "rm " + desc_folder + "/" + desc os.system(rm_cmd) d.infobox(str(len(downloaded)) + " packages removed") write_to_log("Empty Download Folder") return def display_text(d): global available global mirrors global config_folder global version global windowWidth global windowHeight if int(windowWidth) > 90: textBoxWidth = 85 else: textBoxWidth = int(windowWidth) - 5 if int(windowHeight) > 25: textBoxHeight = 20 else: textBoxHeight = int(windowHeight) - 5 d_menu = [] heading = "Choose Package to View Description" maxLen = len(heading) for i in range(len(available)): pkgName = available[i]['package'] d_menu.append((i,pkgName,0)) if len(pkgName) > maxLen: maxLen = len(pkgName) while 1: if len(d_menu) > 12: scrollLen = 12 else: scrollLen = len(d_menu) choice = d.menu(heading,d_menu,maxLen+12,scrollLen+6,scrollLen) if choice == None: main_menu(d) if not (choice == "" or choice == 0): break theFile = available[int(choice)]['path'].replace(".tgz",".txt") tmpFile = os.path.basename(theFile) ind = 0 data = 0 fp = 0 counter = 0 max = len(mirrors) d.infobox("Downloading Package Description",38,4) while not data: URL = mirrors[ind] + version + theFile p = os.popen("wget -t 2 -o wget-log -b -c " + URL) if os.path.exists(tmpFile): data = 1 else: data = 0 ind += 1 if ind == max: ind = 0 time.sleep(2) p.close() if os.path.exists(tmpFile): d.textbox(tmpFile,available[int(choice)]['package'],textBoxWidth,textBoxHeight) else: d.infobox(tmpFile + " not found") os.system("rm " + tmpFile) os.system("rm wget-log*") if d.yesno("View More Descriptions?"): display_text(d) else: return def remove_installed_packages(d): global packages_dir inst = os.listdir(packages_dir) heading = "Choose Package(s) to Remove" maxLen = len(heading) rm_menu = [] inst.sort() for pkg in inst: rm_menu.append((pkg,"",0)) if len(pkg) > maxLen: maxLen = len(pkg) if len(rm_menu) > 12: scrollLen = 12 else: scrollLen = len(rm_menu) rm_choice = d.checklist(heading,rm_menu,maxLen+12,scrollLen+6,scrollLen) if len(rm_choice) > 0: os.system("clear") print "Removing packages requires root access." print "Please enter your password." rm_cmd = "removepkg" for pkg in rm_choice: rm_cmd += " " + pkg cmd = "su -c '" + rm_cmd + "'" os.system(cmd) write_to_log("Removed package(s) : " + ", ".join(rm_choice)) return def view_changelog(d): global windowWidth global windowHeight global mirrors global mirror_index v = choose_version(d) if int(windowWidth) > 90: textBoxWidth = 85 else: textBoxWidth = int(windowWidth) - 5 theFile = "ChangeLog.txt" if os.path.exists(theFile): os.unlink(theFile) while 1: url = mirrors[mirror_index] + v + theFile try: dl = text_file_download(d,url,1,1) except: dl = 0 if dl: break else: mirror_index += 1 if mirror_index == max: mirror_index = 0 d.textbox(theFile,string.capitalize(v[:-1]) + " Changelog",textBoxWidth,int(windowHeight)-6) os.system("rm " + theFile) return def manage_remote_machines(d): global windowWidth global windowHeight global rem_file global rem_list if int(windowWidth) > 90: textBoxWidth = 85 else: textBoxWidth = int(windowWidth) - 5 rem_menu = [("List Network Machines",""), ("Add Network Machines",""), ("Set SSH Keys",""), ("Copy Downloaded Files to Network Machines",""), ("Remove Network Machines",""), ("Connect to Remote Machine",""), ("Return to Main Menu","")] heading = "Choose Remote Machine Options" maxLen = len(heading) for r in rem_menu: theLen = len(r[0]) + len(r[1]) if theLen > maxLen: maxLen = theLen while 1: rem_choice = d.menu(heading,rem_menu,maxLen+12,13,7) if rem_choice != "": break if rem_choice == "List Network Machines": if len(rem_list) == 0: if os.path.exists(rem_file): input = open(rem_file,"r") EOF = False while not EOF: line = input.readline() if line: if line[-1] == "\n": line = line[:-1] rem_list.append(eval(line)) else: EOF = True input.close() if len(rem_list) == 0: d.infobox("No network machines have been added") else: tmpfile = download_folder + "/tmp" output = open(tmpfile,'w') for pkg in rem_list: output.write(" -p " + pkg['port'] + " " + pkg['user'] + "@" + pkg['host'] + "\n") output.close() d.textbox(tmpfile,str(len(rem_list)) + " Remote Hosts",textBoxWidth,int(windowHeight)-6) os.system("rm " + tmpfile) else: tmpfile = download_folder + "/tmp" output = open(tmpfile,'w') for pkg in rem_list: output.write(" -p " + pkg['port'] + " " + pkg['user'] + "@" + pkg['host'] + "\n") output.close() d.textbox(tmpfile,str(len(rem_list)) + " Remote Hosts",textBoxWidth,int(windowHeight)-6) os.system("rm " + tmpfile) if rem_choice == "Add Network Machines": set_remote_info(d) elif rem_choice == "Remove Network Machines": remove_remote_machines(d) elif rem_choice == "Set SSH Keys": if len(rem_list) == 0: if os.path.exists(rem_file): input = open(rem_file,"r") EOF = False while not EOF: line = input.readline() if line: if line[-1] == "\n": line = line[:-1] rem_list.append(eval(line)) else: EOF = True input.close() else: set_remote_info(d) for mach in rem_list: set_remote_keys(d,mach['user'],mach['host']) elif rem_choice == "Copy Downloaded Files to Network Machines": copy_downloaded_files(d) elif rem_choice == "Connect to Remote Machine": connect_remote(d) elif rem_choice == "Return to Main Menu" or rem_choice == "" or rem_choice == None: return manage_remote_machines(d) def set_remote_info(d): global rem_file global rem_list rem_list = [] this_machine = {} if os.path.exists(rem_file): input = open(rem_file,"r") EOF = False while not EOF: line = input.readline() if line: if line[-1] == "\n": line = line[:-1] rem_list.append(eval(line)) else: EOF = True input.close() while 1: while 1: REM_USER = d.inputbox("Remote Machine User Name: ") if REM_USER != "": break else: d.infobox("You must enter the remote machine user name to continue") while 1: REM_HOST = d.inputbox("Remote Machine Host Name: ") if REM_HOST != "": break else: d.infobox("You must enter the remote machine hostname to continue") while 1: REM_PORT = d.inputbox("Remote Machine Port Number: ",35,8,22) if REM_PORT != "": break else: d.infobox("You must enter the remote machine port to continue") this_machine['user'] = REM_USER this_machine['host'] = REM_HOST this_machine['port'] = REM_PORT rem_list.append(this_machine) if not d.yesno("Add Another Machine?"): break if os.path.exists(rem_file): os.system("rm " + rem_file) output = open(rem_file,'w') for mach in rem_list: output.write(str(mach) + "\n") output.close() write_to_log("Added remote machine") return def remove_remote_machines(d): global rem_file global rem_list if len(rem_list) == 0: if os.path.exists(rem_file): input = open(rem_file,"r") EOF = False while not EOF: line = input.readline() if line: if line[-1] == "\n": line = line[:-1] rem_list.append(eval(line)) else: EOF = True input.close() else: d.infobox("No Network Machines Have Been Configured") main_menu(d) heading = "Choose Machine(s) to Remove" maxLen = len(heading) rm_menu = [] for mach in rem_list: rm_menu.append((mach['user'] + "@" + mach['host'],"",0)) if len(rm_menu) > 12: scrollLen = 12 else: scrollLen = len(rm_menu) rm_choice = d.checklist(heading,rm_menu,maxLen+12,scrollLen+6,scrollLen) if len(rm_choice) > 0: i = 0 for mach in rem_list: theMach = mach['user'] + "@" + mach['host'] for rem in rm_choice: if rem == theMach: del rem_list[i] i += 1 if os.path.exists(rem_file): os.system("rm " + rem_file) output = open(rem_file,'w') for mach in rem_list: output.write(str(mach) + "\n") output.close() write_to_log("Removed remote machine") return def set_remote_keys(d,R_USER,R_HOST): REMOTE_MACHINE = R_USER + "@" + R_HOST global homedir os.system("clear") local_key = homedir + "/.ssh/id_rsa.pub" if not os.path.exists(local_key): os.system("ssh-keygen -t rsa") p = os.popen("ssh " + REMOTE_MACHINE + " \"ls -a;exit;\"") has_ssh_dir = 0 while 1: rem = p.readline() if not rem: break if rem[:-1] == ".ssh:": has_ssh_dir = 1 if not has_ssh_dir: os.system("ssh " + REMOTE_MACHINE + " \"mkdir .ssh;exit;\"") os.system("scp ~/.ssh/id_rsa.pub " + REMOTE_MACHINE + ":.ssh/extra_keys2") os.system("ssh " + REMOTE_MACHINE + " \"cat .ssh/extra_keys2 >> .ssh/authorized_keys2;rm .ssh/extra_keys2;exit;\"") os.system("ssh " + REMOTE_MACHINE + " \"chmod 700 .ssh;exit;\"") write_to_log("Set keys for remote machine") return def copy_downloaded_files(d): global rem_file global rem_list global download_folder downloaded = os.listdir(download_folder) if len(downloaded) == 0: d.infobox("Download folder is empty") return heading = "Choose Package(s) to Copy" maxLen = len(heading) cp_opts = [] for pkg in downloaded: cp_opts.append((pkg,"",0)) if len(pkg) > maxLen: maxLen = len(pkg) if len(cp_opts) > 12: scrollLen = 12 else: scrollLen = len(cp_opts) cp_choice = d.checklist(heading,cp_opts,maxLen+12,scrollLen+6,scrollLen) if len(cp_choice) > 0: if len(rem_list) == 0: if os.path.exists(rem_file): input = open(rem_file,"r") EOF = False while not EOF: line = input.readline() if line: if line[-1] == "\n": line = line[:-1] rem_list.append(eval(line)) else: EOF = True input.close() else: set_remote_info(d) for mach in rem_list: REMOTE_MACHINE = "" if int(mach['port']) != 22: REMOTE_MACHINE += " -p " + str(mach['port']) + " " REMOTE_MACHINE += str(mach['user']) + "@" + str(mach['host']) p = os.popen("ssh " + REMOTE_MACHINE + " \"ls -R .getpkg;exit;\"") has_getpkg_dir = 0 while 1: rem = p.readline() if not rem: break if rem[:-1] == "./.getpkg/downloads:" or rem[:-1] == ".getpkg/downloads:": has_getpkg_dir = 1 if not has_getpkg_dir: os.system("ssh " + REMOTE_MACHINE + " \"mkdir .getpkg;mkdir .getpkg/downloads;exit;\"") for file in cp_choice: copy_cmd = "scp " + download_folder + "/" + file + " " copy_cmd += REMOTE_MACHINE + ":.getpkg/downloads/" + file os.system(copy_cmd) write_to_log("Copy files to remote machines") return def connect_remote(d): global rem_file global rem_list if len(rem_list) == 0: if os.path.exists(rem_file): input = open(rem_file,"r") EOF = False while not EOF: line = input.readline() if line: if line[-1] == "\n": line = line[:-1] rem_list.append(eval(line)) else: EOF = True input.close() else: d.infobox("No Network Machines Have Been Configured") main_menu(d) heading = "Choose Machine to Connect to" maxLen = len(heading) rm_menu = [] for mach in rem_list: rm_menu.append((mach['user'] + "@" + mach['host'],"")) if len(rm_menu) > 12: scrollLen = 12 else: scrollLen = len(rm_menu) rm_choice = d.menu(heading,rm_menu,maxLen+12,scrollLen+6,scrollLen) if rm_choice != "" and rm_choice != None: i = 0 for mach in rem_list: theMach = mach['user'] + "@" + mach['host'] if rm_choice == theMach: REMOTE_MACHINE = "" if int(mach['port']) != 22: REMOTE_MACHINE += " -p " + str(mach['port']) + " " REMOTE_MACHINE += str(mach['user']) + "@" + str(mach['host']) write_to_log("Connect to " + REMOTE_MACHINE) os.system("ssh " + REMOTE_MACHINE) else: return def setup_menu(d): global inst_pkglist global inst_path global country_list global country_path global country global version global version_path global available_path global available global windowWidth global windowHeight if int(windowWidth) > 90: textBoxWidth = 85 else: textBoxWidth = int(windowWidth) - 5 s_menu = [("Choose Country",""), ("Choose Version",""), ("View Slackware Changelog",""), ("Update Installed List",""), ("List Installed Packages",""), ("Remove Installed Packages",""), ("Update Available List",""), ("List Available Packages",""), ("Check Getpkg Version",""), ("Return to Main Menu","")] heading = "Version : " + version + " | Country : " + country maxLen = len(heading) heading += "\nChoose Menu Option" for m in s_menu: theLen = len(m[0]) + len(m[1]) if theLen > maxLen: maxLen = theLen if len(s_menu) > 12: scrollLen = 12 else: scrollLen = len(s_menu) menu_choice = d.menu(heading,s_menu,maxLen+12,scrollLen+7,scrollLen) if menu_choice == "Choose Country": country = "" country = choose_country(d) os.unlink(country_path) output = open(country_path,'w') output.write(country) output.close() elif menu_choice == "Choose Version": version = choose_version(d) os.unlink(version_path) output = open(version_path,'w') output.write(version) output.close() available = find_avail_packages(d) os.unlink(available_path) output = open(available_path,'w') for pkg in available: output.write(str(pkg) + "\n") output.close() elif menu_choice == "Update Installed List": inst_pkglist = get_installed_pkgs(d) os.unlink(inst_path) output = open(inst_path,'w') for pkg in inst_pkglist: output.write(str(pkg) + "\n") output.close() elif menu_choice == "List Installed Packages": inst = os.listdir(packages_dir) inst.sort() tmpfile = download_folder + "/tmp" output = open(tmpfile,'w') for pkg in inst: output.write(pkg + "\n") output.close() d.textbox(tmpfile,str(len(inst)) + " Packages Installed",textBoxWidth,int(windowHeight)-6) os.system("rm " + tmpfile) elif menu_choice == "Remove Installed Packages": remove_installed_packages(d) elif menu_choice == "Update Available List": available = find_avail_packages(d) os.unlink(available_path) output = open(available_path,'w') for pkg in available: output.write(str(pkg) + "\n") output.close() elif menu_choice == "List Available Packages": tmpfile = download_folder + "/tmp" output = open(tmpfile,'w') available_list = [] for pkg in available: available_list.append(pkg['package']) available_list.sort() for pkg in available_list: output.write(pkg + "\n") output.close() d.textbox(tmpfile,str(len(available)) + " Packages Available",textBoxWidth,int(windowHeight)-6) os.system("rm " + tmpfile) elif menu_choice == "View Slackware Changelog": view_changelog(d) elif menu_choice == "Check Getpkg Version": check_program_version(d) elif menu_choice == "Return to Main Menu" or menu_choice == "" or menu_choice == None: return setup_menu(d) def unoff_menu(d): global UO_path global UO_pkgs global UO_mirror_path global UO_mirrors u_menu = [("Update Unofficial Packages",""), ("Search Unofficial Packages",""), ("List Unofficial Packages",""), ("Return to Main Menu","")] global windowWidth global windowHeight if int(windowWidth) > 90: textBoxWidth = 85 else: textBoxWidth = int(windowWidth) - 5 heading = "Version : " + version + " | Country : " + country maxLen = len(heading) heading += "\nChoose Menu Option" for m in u_menu: theLen = len(m[0]) + len(m[1]) if theLen > maxLen: maxLen = theLen if len(u_menu) > 12: scrollLen = 12 else: scrollLen = len(u_menu) menu_choice = d.menu(heading,u_menu,maxLen+12,scrollLen+7,scrollLen) if menu_choice == "Update Unofficial Packages": UO_pkgs = update_UO_packages(d) elif menu_choice == "Search Unofficial Packages": UO_package_search(d) elif menu_choice == "List Unofficial Packages": if len(UO_pkgs) == 0: UO_pkgs = update_UO_packages(d) tmpfile = download_folder + "/tmp" output = open(tmpfile,'w') UO_list = [] for pkg in UO_pkgs: UO_list.append(pkg['package'] ) UO_list.sort() for pkg in UO_list: output.write(pkg + "\n") output.close() d.textbox(tmpfile,str(len(UO_pkgs)) + " Packages Available",textBoxWidth,int(windowHeight)-6) os.system("rm " + tmpfile) elif menu_choice == "Return to Main Menu" or menu_choice == "" or menu_choice == None: return unoff_menu(d) def main_menu(d): global menu global inst_pkglist global inst_path global country_list global country_path global country global version global version_path global available_path global available global exclude_path global exclude_list global packages_dir global download_folder global UO_pkgs global windowWidth global windowHeight global rem_file global rem_list global log_path if int(windowWidth) > 90: textBoxWidth = 85 else: textBoxWidth = int(windowWidth) - 5 # clean up after package downloads if os.path.exists("FILELIST.TXT"): os.unlink("FILELIST.TXT") if os.path.exists("CHECKSUMS.md5"): os.unlink("CHECKSUMS.md5") if os.path.exists("wget-log"): os.unlink("wget-log") if os.path.exists("Changelog.txt"): os.unlink("Changelog.txt") heading = "Version : " + version + " | Country : " + country maxLen = len(heading) heading += "\nChoose Menu Option" for m in menu: theLen = len(m[0]) + len(m[1]) if theLen > maxLen: maxLen = theLen if len(menu) > 14: scrollLen = 14 else: scrollLen = len(menu) menu_choice = d.menu(heading,menu,maxLen+12,scrollLen+7,scrollLen) if menu_choice == "Setup Menu": setup_menu(d) elif menu_choice == "View Slackware Changelog": view_changelog(d) elif menu_choice == "Update Available List": available = find_avail_packages(d) os.unlink(available_path) output = open(available_path,'w') for pkg in available: output.write(str(pkg) + "\n") output.close() elif menu_choice == "Package Search": package_search(d) elif menu_choice == "List Downloaded Packages": list_downloaded_pkgs(d) elif menu_choice == "Install Downloaded Packages": install_downloaded_pkgs(d) elif menu_choice == "Empty Download Directory": rm_downloaded_pkgs(d) elif menu_choice == "Manage Excluded Packages": manage_exclude_list(d) elif menu_choice == "Manage Unofficial Packages": unoff_menu(d) elif menu_choice == "View Package Descriptions": display_text(d) elif menu_choice == "Manage Network Machines": manage_remote_machines(d) elif menu_choice == "Enter Mirrors from Text File": upload_user_mirror_list(d) elif menu_choice == "View Getpkg Log File": if os.path.exists(log_path): d.textbox(log_path,"Getpkg Log File",textBoxWidth,int(windowHeight)-6) else: d.infobox("Log not found") elif menu_choice == "Exit" or menu_choice == "" or menu_choice == None: os.system("clear") sys.exit(0) else: d.infobox("Please choose a menu option from the list to continue") main_menu(d) def main(): global country global country_path global inst_path global inst_pkglist global available_path global available global exclude_path global exclude_list global version global version_path global mirror_path global mirrors global UO_path global UO_pkgs global UO_mirror_path global UO_mirrors global minWidth global minHeight global windowWidth global windowHeight d = Dialog() d.set_p_opt("title","GETPKG " + GETPKG_VERSION) windowHeight,windowWidth = d.get_window_size().split(", ") if int(windowHeight) < minHeight or int(windowWidth) < minWidth: msg = "GETPG may not function in terminals smaller than " + str(minWidth) + " X " + str(minHeight) msg += "\nExit Program?" if d.yesno(msg,int(windowWidth)-5,int(windowHeight)-5):sys.exit(0) else: d.infobox("Current terminal is " + windowWidth + " X " + windowHeight,int(windowWidth)-5,int(windowHeight)-5) uid = os.getuid() if uid == 0: if d.yesno("This program is not designed to be run as root\n\nExit now?",45,8):sys.exit(0) d.set_p_opt("backtitle","GETPKG " + GETPKG_VERSION + " - Remote Package Management For Slackware Linux(R)") # check if you're using slackware if not (os.path.exists("/etc/slackware-version") and sys.platform[:5] == "linux"): if d.yesno("This program is designed for Slackware Linux\nExit Program?",30,10): os.system("clear") sys.exit(0) # choose version 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(d) output = open(version_path,'w') output.write(version) output.close() # choose country try: fp = os.path.exists(country_path) except: fp = 0 if fp: input = open(country_path,'r') country = input.readline() input.close() if os.path.exists(mirror_path): input = open(mirror_path,'r') mirrors = [] while 1: m = input.readline() if not m: break if m[-1] == "\n": m = m[:-1] mirrors.append(m) input.close() else: country = choose_country(d) output = open(country_path,'w') output.write(country) output.close() else: country = choose_country(d) output = open(country_path,'w') output.write(country) output.close() # count installed pkgs try: fp = os.path.exists(inst_path) except: fp = 0 if not fp: inst_pkglist = get_installed_pkgs(d) 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 input.close() # available packages try: fp = os.path.exists(available_path) except: fp = 0 if fp: input = open(available_path,'r') EOF = False available = [] while not EOF: line = input.readline() if line: if line[-1] == "\n": line = line[:-1] available.append(eval(line)) else: EOF = True input.close() else: available = find_avail_packages(d) output = open(available_path,'w') for pkg in available: output.write(str(pkg) + "\n") output.close() # excluded packages try: fp = os.path.exists(exclude_path) except: fp = 0 if fp: input = open(exclude_path,'r') EOF = False while not EOF: line = input.readline() if line: if line[-1] == "\n": line = line[:-1] exclude_list.append(line) else: EOF = True input.close() # Unofficial packages try: fp = os.path.exists(UO_path) except: fp = 0 if fp: UO_pkgs = [] input = open(UO_path,'r') EOF = False while not EOF: line = input.readline() if line: if line[-1] == "\n": line = line[:-1] UO_pkgs.append(eval(line)) else: EOF = True input.close() else: UO_pkgs = update_UO_packages(d) # unofficial mirrors if os.path.exists(UO_mirror_path): input = open(UO_mirror_path,'r') while 1: line = input.readline() if not line: break if line[-1] == "\n": line = line[:-1] UO_mirrors.append(line) input.close() else: UO_pkgs = update_UO_packages(d) # go to main menu main_menu(d) if __name__ == "__main__": main()