Example #1
0
    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
Example #2
0
    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
Example #3
0
File: check.py Project: pahau/Cnchi
    def check_all(self):
        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 and space:
            return True

        return False
Example #4
0
    def check_all(self):
        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 and space:
            return True

        return False
Example #5
0
    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)
Example #6
0
    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)
Example #7
0
    def run(self):
        """ Run thread """

        # Wait until there is an Internet connection available
        while not misc.has_connection():
            if self.settings.get('stop_all_threads'):
                return
            time.sleep(1)  # Delay

        if not os.path.exists(self.reflector_script):
            logging.warning(_("Can't find reflector script"))
            return

        # Run rankmirrors command
        try:
            self.rankmirrors_pid = subprocess.Popen(["/usr/share/cnchi/scripts/reflector.sh"]).pid
        except subprocess.CalledProcessError as err:
            logging.error(_("Couldn't execute auto mirror selection"))
            logging.error(err)
        logging.debug(_("Auto mirror selection has been run successfully"))
Example #8
0
    def run(self):
        """ Run thread """

        # Wait until there is an Internet connection available
        while not misc.has_connection():
            if self.settings.get('stop_all_threads'):
                return
            time.sleep(1)  # Delay

        if not os.path.exists(self.reflector_script):
            logging.warning(_("Can't find reflector script"))
            return

        # Run rankmirrors command
        try:
            self.rankmirrors_pid = subprocess.Popen(
                ["/usr/share/cnchi/scripts/reflector.sh"]).pid
        except subprocess.CalledProcessError as err:
            logging.error(_("Couldn't execute auto mirror selection"))
            logging.error(err)
        logging.debug(_("Auto mirror selection has been run successfully"))
Example #9
0
    def run(self):
        """ Run thread """

        # Wait until there is an Internet connection available
        while not misc.has_connection():
            if self.settings.get('stop_all_threads'):
                return
            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 err:
            logging.error(_("Couldn't execute auto mirror selection"))

        # Check arch mirrorlist against mirror status data, remove any bad mirrors.
        if _use_requests and 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
                        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"))
Example #10
0
    def run(self):
        """ Run thread """

        # Wait until there is an Internet connection available
        while not misc.has_connection():
            if self.settings.get('stop_all_threads'):
                return
            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 err:
            logging.error(_("Couldn't execute auto mirror selection"))

        # Check arch mirrorlist against mirror status data, remove any bad mirrors.
        if _use_requests and 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
                        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"))