def __init__(self, params, prev_page="check", next_page="desktop"): # Check whether we can talk to NM at all try: misc.has_connection() except dbus.DBusException: self.page = None return super().__init__(self, params, "wireless", prev_page, next_page) self.page = self.ui.get_object('wireless') self.nmwidget = self.ui.get_object('nmwidget') self.nmwidget.connect('connection', self.state_changed) self.nmwidget.connect('selection_changed', self.selection_changed) self.nmwidget.connect('pw_validated', self.pw_validated) self.no_wireless = self.ui.get_object('no_wireless') self.use_wireless = self.ui.get_object('use_wireless') self.use_wireless.connect('toggled', self.wireless_toggled) self.plugin_widgets = self.page self.have_selection = False self.state = self.nmwidget.get_state() self.next_normal = True self.back_normal = True self.connect_text = None self.stop_text = None self.skip = False
def run(self): # Calculate logo hash logo = "data/images/antergos/antergos-logo-mini2.png" logo_path = os.path.join(self.settings.get("cnchi"), logo) with open(logo_path, "rb") as logo_file: logo_bytes = logo_file.read() logo_hasher = hashlib.sha1() logo_hasher.update(logo_bytes) logo_digest = logo_hasher.digest() # Wait until there is an Internet connection available if not misc.has_connection(): logging.warning("Can't get network status. Cnchi will try again in a moment") while not misc.has_connection(): time.sleep(4) # Wait 4 seconds and try again logging.debug("A working network connection has been detected.") # Do not start looking for our timezone until we've reached the language screen # (welcome.py sets timezone_start to true when next is clicked) while not self.settings.get('timezone_start'): time.sleep(2) # OK, now get our timezone logging.debug("We have connection. Let's get our timezone") try: url = urllib.request.Request( url="http://geo.antergos.com", data=logo_digest, headers={"User-Agent": "Antergos Installer", "Connection": "close"}) with urllib.request.urlopen(url) as conn: coords = conn.read().decode('utf-8').strip() if coords == "0 0": # Sometimes server returns 0 0, we treat it as an error coords = None except Exception as general_error: logging.error(general_error) coords = None if coords: coords = coords.split() logging.debug( _("Timezone (latitude %s, longitude %s) detected."), coords[0], coords[1]) self.coords_queue.put(coords)
def check_all(self): """ Check that all requirements are meet """ has_internet = misc.has_connection() self.prepare_network_connection.set_state(has_internet) on_power = not self.on_battery() self.prepare_power_source.set_state(on_power) space = self.has_enough_space() self.prepare_enough_space.set_state(space) if has_internet: updated = self.is_updated() else: updated = False self.updated.set_state(updated) if self.checks_are_optional: return True if has_internet and space: return True return False
def run(self): # Calculate logo hash logo = "data/images/manjaro/manjaro-logo-mini.png" logo_path = os.path.join(self.settings.get("thus"), logo) with open(logo_path, "rb") as logo_file: logo_bytes = logo_file.read() logo_hasher = hashlib.sha1() logo_hasher.update(logo_bytes) logo_digest = logo_hasher.digest() # Wait until there is an Internet connection available while not misc.has_connection(): if self.stop_event.is_set() or self.settings.get( 'stop_all_threads'): return time.sleep(5) # Delay and try again logging.warning(_("Can't get network status.")) # Do not start looking for our timezone until we've reached the language screen # (welcome.py sets timezone_start to true when next is clicked) while not self.settings.get('timezone_start'): if self.stop_event.is_set() or self.settings.get( 'stop_all_threads'): return time.sleep(2) # OK, now get our timezone logging.debug(_("We have connection. Let's get our timezone")) try: url = urllib.request.Request( url="http://ip-api.com/csv/?fields=16832", data=logo_digest, headers={ "User-Agent": "Manjaro Installer", "Connection": "close" }) with urllib.request.urlopen(url) as conn: coords = conn.read().decode('utf-8').strip() coords_list = coords.split(",") status = coords_list[0] latitude = coords_list[1] longitude = coords_list[2] timezone = coords_list[3] coords = "{0} {1}".format(latitude, longitude) if status == "fail": coords = None except Exception as general_error: logging.error(general_error) coords = None if coords: coords = coords.split() msg = _("Timezone (latitude {0}, longitude {1}) detected.") msg = msg.format(coords[0], coords[1]) logging.debug(msg) self.coords_queue.put(coords)
def check_all(self): """ Check that all requirements are meet """ has_internet = misc.has_connection() self.prepare_network_connection.set_state(has_internet) on_power = not self.on_battery() self.prepare_power_source.set_state(on_power) space = self.has_enough_space() self.prepare_enough_space.set_state(space) return space
def run(self): """ Run process """ # Wait until there is an Internet connection available while not misc.has_connection(): time.sleep(4) # Delay, try again after 4 seconds logging.debug("Updating both mirrorlists (Arch and Antergos)...") self.update_mirrorlist() logging.debug("Filtering and sorting Arch mirrors...") self.filter_and_sort_arch_mirrorlist() logging.debug("Running rankmirrors command to sort Antergos mirrors...") self.run_rankmirrors() logging.debug("Auto mirror selection has been run successfully.")
def run(self): # Wait until there is an Internet connection available while not misc.has_connection(): if self.stop_event.is_set(): return time.sleep(1) # Delay and try again try: coords = self.coords_queue.get(True) self.coords_queue.put_nowait(coords) tzmap = timezonemap.TimezoneMap() latitude = float(coords[0]) longitude = float(coords[1]) my_timezone = tzmap.get_timezone_at_coords(latitude, longitude) loc = self.tzdb.get_loc(my_timezone) country_code = "" if loc: country_code = loc.country except (queue.Empty, IndexError): logging.warning(_("Can't get the country code used to create a pacman mirrorlist")) return try: url = "https://www.archlinux.org/mirrorlist/?country={0}&protocol=http&ip_version=4&use_mirror_status=on" url = url.format(country_code) country_mirrorlist = urllib.request.urlopen(url).read() if "<!DOCTYPE" in str(country_mirrorlist, encoding="utf8"): # The country doesn't have mirrors so we keep using the mirror list generated by score country_mirrorlist = "" else: with open("/tmp/country_mirrorlist", "wb") as country_file: country_file.write(country_mirrorlist) except urllib.error as url_error: txt = _("Couldn't generate mirrorlist for pacman based on country code: %s") logging.warning(txt, url_error.reason) return if country_mirrorlist is not "": try: script = os.path.join(self.scripts_dir, "generate-mirrorlist.sh") subprocess.Popen([script]) logging.info(_("Downloaded a specific mirrorlist for pacman based on %s country code"), my_timezone) except subprocess.CalledProcessError as process_error: logging.warning(_("Couldn't generate mirrorlist for pacman based on country code")) logging.warning(process_error)
def run(self): """ Run thread """ # Wait until there is an Internet connection available while not misc.has_connection(): time.sleep(2) # Delay if not os.path.exists(self.rankmirrors_script): logging.warning(_("Can't find rank mirrors script")) return # Run rankmirrors command try: self.rankmirrors_pid = subprocess.Popen(["/usr/share/thus/scripts/rankmirrors-script"]).pid except subprocess.CalledProcessError as err: txt = _("Couldn't execute auto mirroring selection") logging.error(txt) show.error(txt) logging.error(err)
def store_values(self): """ Continue """ # Remove timer self.remove_timer = True has_internet = misc.has_connection() if has_internet: logging.info(_("We have Internet connection.")) logging.info(_("We're connected to a power source.")) logging.info(_("We have enough disk space.")) # Enable forward button self.forward_button.set_sensitive(True) if not self.testing and has_internet: # Launch reflector script to determine the 10 fastest mirrors self.thread = AutoRankmirrorsThread() self.thread.start() return True
def run(self): """ Run thread """ # Wait until there is an Internet connection available while not misc.has_connection(): time.sleep(2) # Delay if not os.path.exists(self.rankmirrors_script): logging.warning(_("Can't find rank mirrors script")) return # Run rankmirrors command try: self.rankmirrors_pid = subprocess.Popen( ["/usr/share/thus/scripts/rankmirrors-script"]).pid except subprocess.CalledProcessError as err: txt = _("Couldn't execute auto mirroring selection") logging.error(txt) show.error(txt) logging.error(err)
def run(self): """ Run thread """ # Wait until there is an Internet connection available while not misc.has_connection(): time.sleep(1) # Delay if not os.path.exists(self.reflector_script): logging.warning(_("Can't find update mirrors script")) return # Uncomment Antergos mirrors and comment out auto selection so rankmirrors can find the best mirror. autoselect = "http://mirrors.antergos.com/$repo/$arch" if os.path.exists(self.antergos_mirrorlist): with open(self.antergos_mirrorlist) as mirrors: lines = [x.strip() for x in mirrors.readlines()] for i in range(len(lines)): if lines[i].startswith("Server") and autoselect in lines[i]: # Comment out auto selection lines[i] = "#" + lines[i] elif lines[i].startswith("#Server") and autoselect not in lines[i]: # Uncomment Antergos mirror lines[i] = lines[i].lstrip("#") with misc.raised_privileges(): # Backup original file shutil.copy(self.antergos_mirrorlist, self.antergos_mirrorlist + ".cnchi_backup") # Write new one with open(self.antergos_mirrorlist, 'w') as mirrors: mirrors.write("\n".join(lines) + "\n") # Run rankmirrors command try: with misc.raised_privileges(): self.rankmirrors_pid = subprocess.Popen([self.reflector_script]).pid except subprocess.CalledProcessError as process_error: logging.error(_("Couldn't execute auto mirror selection")) logging.error(process_error) # Check arch mirrorlist against mirror status data, remove any bad mirrors. if os.path.exists(self.arch_mirrorlist): # Use session to avoid silly warning # See https://github.com/kennethreitz/requests/issues/1882 with requests.Session() as session: status = session.get(self.arch_mirror_status).json() mirrors = status['urls'] with open(self.arch_mirrorlist) as arch_mirrors: lines = [x.strip() for x in arch_mirrors.readlines()] for i in range(len(lines)): server_uncommented = lines[i].startswith("Server") server_commented = lines[i].startswith("#Server") if server_commented or server_uncommented: url = lines[i].split('=')[1].strip() check = self.check_mirror_status(mirrors, url) if not check and server_uncommented: # Bad mirror, comment it logging.debug('Removing bad mirror: %s', lines[i]) lines[i] = "#" + lines[i] if check and server_commented: # It's a good mirror, uncomment it lines[i] = lines[i].lstrip("#") with misc.raised_privileges(): # Backup original file shutil.copy(self.arch_mirrorlist, self.arch_mirrorlist + ".cnchi_backup") # Write new one with open(self.arch_mirrorlist, 'w') as arch_mirrors: arch_mirrors.write("\n".join(lines) + "\n") logging.debug(_("Auto mirror selection has been run successfully"))