def init_proxy(gsettings=None): """ init proxy settings * first check for http_proxy environment (always wins), * then check the apt.conf http proxy, * then look into synaptics conffile * then into gconf (if gconfclient was supplied) """ SYNAPTIC_CONF_FILE = "/root/.synaptic/synaptic.conf" proxy = None # generic apt config wins if apt_pkg.config.find("Acquire::http::Proxy") != '': proxy = apt_pkg.config.find("Acquire::http::Proxy") # then synaptic elif os.path.exists(SYNAPTIC_CONF_FILE): cnf = apt_pkg.Configuration() apt_pkg.read_config_file(cnf, SYNAPTIC_CONF_FILE) use_proxy = cnf.find_b("Synaptic::useProxy", False) if use_proxy: proxy_host = cnf.find("Synaptic::httpProxy") proxy_port = str(cnf.find_i("Synaptic::httpProxyPort")) if proxy_host and proxy_port: proxy = "http://%s:%s/" % (proxy_host, proxy_port) # if we have a proxy, set it if proxy: # basic verification if not re.match("http://\w+", proxy): print("proxy '%s' looks invalid" % proxy, file=sys.stderr) return proxy_support = ProxyHandler({"http": proxy}) opener = build_opener(proxy_support) install_opener(opener) os.putenv("http_proxy", proxy) return proxy
def _readconf(self): apt_pkg.init() self.Cnf = apt_pkg.Configuration() apt_pkg.read_config_file_isc(self.Cnf, which_conf_file()) # Check whether our dak.conf was the real one or # just a pointer to our main one res = socket.gethostbyaddr(socket.gethostname()) conffile = self.Cnf.get("Config::" + res[0] + "::DakConfig") if conffile: apt_pkg.read_config_file_isc(self.Cnf, conffile) # Read group-specific options if 'ByGroup' in self.Cnf: bygroup = self.Cnf.subtree('ByGroup') groups = set([os.getgid()]) groups.update(os.getgroups()) for group in bygroup.list(): gid = grp.getgrnam(group).gr_gid if gid in groups: if bygroup.get(group): apt_pkg.read_config_file_isc(self.Cnf, bygroup[group]) break # Rebind some functions # TODO: Clean this up self.get = self.Cnf.get self.subtree = self.Cnf.subtree self.value_list = self.Cnf.value_list self.find = self.Cnf.find self.find_b = self.Cnf.find_b self.find_i = self.Cnf.find_i
def init_proxy(gsettings=None): """ init proxy settings * first check for http_proxy environment (always wins), * then check the apt.conf http proxy, * then look into synaptics conffile * then into gconf (if gconfclient was supplied) """ SYNAPTIC_CONF_FILE = "/root/.synaptic/synaptic.conf" proxy = None # generic apt config wins if apt_pkg.config.find("Acquire::http::Proxy") != '': proxy = apt_pkg.config.find("Acquire::http::Proxy") # then synaptic elif os.path.exists(SYNAPTIC_CONF_FILE): cnf = apt_pkg.Configuration() apt_pkg.read_config_file(cnf, SYNAPTIC_CONF_FILE) use_proxy = cnf.find_b("Synaptic::useProxy", False) if use_proxy: proxy_host = cnf.find("Synaptic::httpProxy") proxy_port = str(cnf.find_i("Synaptic::httpProxyPort")) if proxy_host and proxy_port: proxy = "http://%s:%s/" % (proxy_host, proxy_port) # gconf is no more # elif gconfclient: # try: # see LP: #281248 # if gconfclient.get_bool("/system/http_proxy/use_http_proxy"): # host = gconfclient.get_string("/system/http_proxy/host") # port = gconfclient.get_int("/system/http_proxy/port") # use_auth = gconfclient.get_bool("/system/http_proxy/use_authentication") # if host and port: # if use_auth: # auth_user = gconfclient.get_string("/system/http_proxy/authentication_user") # auth_pw = gconfclient.get_string("/system/http_proxy/authentication_password") # proxy = "http://%s:%s@%s:%s/" % (auth_user,auth_pw,host, port) # else: # proxy = "http://%s:%s/" % (host, port) # except Exception, e: # print "error from gconf: %s" % e # if we have a proxy, set it if proxy: # basic verification if not re.match("http://\w+", proxy): print >> sys.stderr, "proxy '%s' looks invalid" % proxy return proxy_support = urllib2.ProxyHandler({"http": proxy}) opener = urllib2.build_opener(proxy_support) urllib2.install_opener(opener) os.putenv("http_proxy", proxy) return proxy
def init_proxy(gsettings=None): """ init proxy settings * use apt.conf http proxy if present, * otherwise look into synaptics config file, * otherwise the default behavior will use http_proxy environment if present """ SYNAPTIC_CONF_FILE = "/root/.synaptic/synaptic.conf" proxies = {} # generic apt config wins if apt_pkg.config.find("Acquire::http::Proxy") != '': proxies["http"] = apt_pkg.config.find("Acquire::http::Proxy") # then synaptic elif os.path.exists(SYNAPTIC_CONF_FILE): cnf = apt_pkg.Configuration() apt_pkg.read_config_file(cnf, SYNAPTIC_CONF_FILE) use_proxy = cnf.find_b("Synaptic::useProxy", False) if use_proxy: proxy_host = cnf.find("Synaptic::httpProxy") proxy_port = str(cnf.find_i("Synaptic::httpProxyPort")) if proxy_host and proxy_port: proxies["http"] = "http://%s:%s/" % (proxy_host, proxy_port) if apt_pkg.config.find("Acquire::https::Proxy") != '': proxies["https"] = apt_pkg.config.find("Acquire::https::Proxy") elif "http" in proxies: proxies["https"] = proxies["http"] # if we have a proxy, set it if proxies: # basic verification for proxy in proxies.values(): if not re.match("https?://\\w+", proxy): print("proxy '%s' looks invalid" % proxy, file=sys.stderr) return proxy_support = ProxyHandler(proxies) opener = build_opener(proxy_support) install_opener(opener) if "http" in proxies: os.putenv("http_proxy", proxies["http"]) if "https" in proxies: os.putenv("https_proxy", proxies["https"]) return proxies
# config.py -o help=true ; Turn on help by giving a # ; config file string # config.py -no-h -- -help ; Turn off help, specify the file '-help' # -c and -o are standard APT-program options. # This shows how to use the system for configuration and option control. # The other varient is for ISC object config files. See configisc.py. import apt_pkg import sys import posixpath # Create a new empty Configuration object - there is also the system global # configuration object apt_pkg.config which is used interally by apt-pkg # routines to control unusual situations. I recommend using the sytem global # whenever possible.. Cnf = apt_pkg.Configuration() print("Command line is", sys.argv) # Load the default configuration file, init_config() does this better.. Cnf.set("config-file", "/etc/apt/apt.conf") # or Cnf["config-file"] = ".." if posixpath.exists(Cnf.find_file("config-file")): apt_pkg.read_config_file(Cnf, "/etc/apt/apt.conf") # Merge the command line arguments into the configuration space Arguments = [('h', "help", "help"), ('v', "version", "version"), ('q', "quiet", "quiet", "IntLevel"), ('c', "config-file", "", "ConfigFile"), ('o', "option", "", "ArbItem")] print("FileNames", apt_pkg.parse_commandline(Cnf, Arguments, sys.argv))
def __init__(self, datadir, options, file=""): GDebiCommon.__init__(self,datadir, options, file) SimpleGtkbuilderApp.__init__( self, path=os.path.join(datadir, "gdebi.ui"), domain="gdebi") # use a nicer default icon icons = Gtk.IconTheme.get_default() try: logo=icons.load_icon("gnome-mime-application-x-deb", 48, 0) if logo != "": Gtk.Window.set_default_icon_list([logo]) except Exception as e: logging.warning("Error loading logo %s" % e) # create terminal self.vte_terminal = Vte.Terminal() # FIXME: this sucks but without it the terminal window is only # 1 line height self.vte_terminal.set_size_request(80*10, 25*10) menu = Gtk.Menu() menu_items = Gtk.MenuItem(label=_("Copy selected text")) menu.append(menu_items) menu_items.connect("activate", self.menu_action, self.vte_terminal) menu_items.show() self.vte_terminal.connect_object("event", self.vte_event, menu) self.hbox_install_terminal.pack_start(self.vte_terminal, True, True, 0) scrollbar = Gtk.VScrollbar(adjustment=self.vte_terminal.get_vadjustment()) self.hbox_install_terminal.pack_start(scrollbar, False, False, 0) # setup status self.context=self.statusbar_main.get_context_id("context_main_window") self.statusbar_main.push(self.context,_("Loading...")) # show what we have self.window_main.realize() self.window_main.show() # setup drag'n'drop # FIXME: this seems to have no effect, droping in nautilus does nothing target_entry = Gtk.TargetEntry().new('text/uri-list',0,0) self.window_main.drag_dest_set(Gtk.DestDefaults.ALL, [target_entry], Gdk.DragAction.COPY) self.window_main.connect("drag_data_received", self.on_window_main_drag_data_received) # Check file with gio file = self.gio_copy_in_place(file) #self.vte_terminal.set_font_from_string("monospace 10") self.cprogress = self.CacheProgressAdapter(self.progressbar_cache) if not self.openCache(): self.show_alert(Gtk.MessageType.ERROR, self.error_header, self.error_body) sys.exit(1) self.statusbar_main.push(self.context, "") # setup the details treeview self.details_list = Gtk.ListStore(GObject.TYPE_STRING) column = Gtk.TreeViewColumn("") render = Gtk.CellRendererText() column.pack_start(render, True) column.add_attribute(render, "markup", 0) self.treeview_details.append_column(column) self.treeview_details.set_model(self.details_list) # setup the files treeview column = Gtk.TreeViewColumn("") render = Gtk.CellRendererText() column.pack_start(render, True) column.add_attribute(render, "text", 0) self.treeview_files.append_column(column) # empty config self.synaptic_config = apt_pkg.Configuration() if file != "" and os.path.exists(file): self.open(file) self.window_main.set_sensitive(True)
def dpkg_action(self, widget, install): if not install: self.openCache() if not self._deb.pkgname in self._cache: return self._cache[self._deb.pkgname].mark_delete() if self._cache.delete_count > 1: details = set() for package in self._cache.get_changes(): if package.shortname != self._deb.pkgname: if package.marked_delete: details.add(package.shortname) self.error_header = _("Dependency problems") self.error_body = _("One or more packages are required by %s, " "it cannot be removed.") % self._deb.pkgname self.show_alert(Gtk.MessageType.ERROR, self.error_header, self.error_body, "\n".join(details)) return self.action_completed=False # check if we actually have a deb, see #213725 if install and not self._deb: err_header = _("File not found") err_body = _("You tried to install a file that does not " "(or no longer) exist. ") dia = Gtk.MessageDialog(None, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, "") dia.set_markup("<b><big>%s</big></b>" % err_header) dia.format_secondary_text(err_body) dia.run() dia.destroy() return # do it if install: msgstring = _("Installing package file...") else: msgstring = _("Removing package...") self.statusbar_main.push(self.context, msgstring) if install and widget != None and len(self.unauthenticated) > 0: primary = _("Install unauthenticated software?") secondary = _("Malicious software can damage your data " "and take control of your system.\n\n" "The packages below are not authenticated and " "could therefore be of malicious nature.") msg = "<big><b>%s</b></big>\n\n%s" % (primary, secondary) dialog = Gtk.MessageDialog(parent=self.dialog_deb_install, flags=Gtk.DialogFlags.MODAL, type=Gtk.MessageType.WARNING, buttons=Gtk.ButtonsType.YES_NO) dialog.set_markup(msg) dialog.set_border_width(6) scrolled = Gtk.ScrolledWindow() textview = Gtk.TextView() textview.set_cursor_visible(False) textview.set_editable(False) buf = textview.get_buffer() buf.set_text("\n".join(self.unauthenticated)) scrolled.add(textview) scrolled.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) scrolled.show() dialog.get_content_area().pack_start(scrolled, True, True, 0) textview.show() res = dialog.run() dialog.destroy() if res != Gtk.ResponseType.YES: return if install: msg_hdr = _("You need to grant administrative rights to install software") msg_bdy = _(""" It is a possible security risk to install packages files manually. Install software from trustworthy software distributors only. """) else: msg_hdr = _("You need to grant administrative rights to remove software") msg_bdy = _("It is a possible risk to remove packages.") if os.getuid() != 0: # build command and argument lists gksu_cmd = "/usr/bin/gksu" gksu_args = ["gksu", "--desktop", "/usr/share/applications/gdebi.desktop", "--message", "<big><b>%s</b></big>\n\n%s" % (msg_hdr,msg_bdy)] gdebi_args = ["--", "gdebi-gtk", "--non-interactive", self._deb.filename] if not install: gdebi_args.append("--remove") # check if we run on ubuntu and always ask for the password # there - we would like to do that on debian too, but this # gksu patch is only available on ubuntu currently unfortunately if UBUNTU: gksu_args.append("--always-ask-pass") os.execv(gksu_cmd, gksu_args+gdebi_args) if not self.try_acquire_lock(): if install: msgstring = _("Failed to install package file") else: msgstring = _("Failed to remove package") self.statusbar_main.push(self.context, msgstring) self.show_alert(Gtk.MessageType.ERROR, self.error_header, self.error_body) return False # lock for install self.window_main.set_sensitive(False) self.button_deb_install_close.set_sensitive(False) # clear terminal #self.vte_terminal.feed(str(0x1b)+"[2J") # Get whether we auto close from synaptic's config file and # update the toggle button as neccessary config = apt_pkg.Configuration() if os.path.isfile("/root/.synaptic/synaptic.conf"): apt_pkg.read_config_file(config, "/root/.synaptic/synaptic.conf") else: config["Synaptic::closeZvt"] = "false" if not "Synaptic" in config.list(): config["Synaptic::closeZvt"] = "false" self.synaptic_config = config.subtree("Synaptic") self.checkbutton_autoclose.set_active(self.synaptic_config.find_b("closeZvt")) self.dialog_deb_install.set_transient_for(self.window_main) self.dialog_deb_install.show_all() if install and (len(self.install) > 0 or len(self.remove) > 0): # FIXME: use the new python-apt acquire interface here, # or rather use it in the apt module and raise exception # when stuff goes wrong! if not self.acquire_lock(): self.show_alert(Gtk.MessageType.ERROR, self.error_header, self.error_body) return False fprogress = self.FetchProgressAdapter(self.progressbar_install, self.label_action, self.dialog_deb_install) iprogress = self.InstallProgressAdapter(self.progressbar_install, self.vte_terminal, self.label_action, self.expander_install) try: res = self._cache.commit(fprogress,iprogress) except IOError as e: res = False msg = e header = _("Could not download all required files") body = _("Please check your internet connection or " "installation medium, and make sure your " "APT cache is up-to-date.") except SystemError as e: res = False msg = e header = _("Could not install all dependencies"), body = _("Usually this is related to an error of the " "software distributor. See the terminal window for " "more details.") if not res: self.show_alert(Gtk.MessageType.ERROR, header, body, msg, parent=self.dialog_deb_install) self.label_install_status.set_markup("<span foreground=\"red\" weight=\"bold\">%s</span>" % header) self.button_deb_install_close.set_sensitive(True) self.button_deb_install_close.grab_default() self.statusbar_main.push(self.context,_("Failed to install package file")) return # install the package itself self.dialog_deb_install.set_title(self.window_main.get_title()) if install: self.label_action.set_markup("<b><big>" + _("Installing %s") % self._deb.pkgname + "</big></b>") else: self.label_action.set_markup("<b><big>" + _("Removing %s") % self._deb.pkgname + "</big></b>") if install: debfilename = self._deb.filename else: debfilename = self._deb.pkgname dprogress = self.DpkgActionProgress(debfilename, self.label_install_status, self.progressbar_install, self.vte_terminal, self.expander_install, install) dprogress.commit() self.action_completed=True #self.label_action.set_markup("<b><big>"+_("Package installed")+"</big></b>") # show the button self.button_deb_install_close.set_sensitive(True) self.button_deb_install_close.grab_default() #Close if checkbox is selected if self.checkbutton_autoclose.get_active(): self.on_button_deb_install_close_clicked(None) if install: self.label_action.set_markup("<b><big>"+_("Installation finished")+"</big></b>") else: self.label_action.set_markup("<b><big>"+_("Removal finished")+"</big></b>") if dprogress.exitstatus == 0: if install: self.label_install_status.set_markup("<i>"+_("Package '%s' was installed") % os.path.basename(self._deb.filename)+"</i>") else: self.label_install_status.set_markup("<i>"+_("Package '%s' was removed") % os.path.basename(self._deb.pkgname)+"</i>") else: if install: self.label_install_status.set_markup("<b>"+_("Failed to install package '%s'") % os.path.basename(self._deb.filename)+"</b>") else: self.label_install_status.set_markup("<b>"+_("Failed to remove package '%s'") % os.path.basename(self._deb.pkgname)+"</b>") self.expander_install.set_expanded(True) if install: self.statusbar_main.push(self.context,_("Installation complete")) else: self.statusbar_main.push(self.context,_("Removal complete")) # FIXME: Doesn't stop notifying #self.window_main.set_property("urgency-hint", 1) # reopen the cache, reread the file self.openCache() if self._cache._depcache.broken_count > 0: if install: err_header = _("Failed to completely install all dependencies") else: err_header = _("Failed to completely remove package") err_body = _("To fix this run 'sudo apt-get install -f' in a " "terminal window.") self.show_alert(Gtk.MessageType.ERROR, err_header, err_body) self.open(self._deb.filename)