2 # -*- coding: utf-8 -*-
6 # Copyright © 2013-2018 Antergos
8 # This file is part of Cnchi.
10 # Cnchi is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
15 # Cnchi is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # The following additional terms are in effect as per Section 7 of the license:
22 # The preservation of all legal notices and author attributions in
23 # the material or in the Appropriate Legal Notices displayed
24 # by works containing it is required.
26 # You should have received a copy of the GNU General Public License
27 # along with Cnchi; If not, see <http://www.gnu.org/licenses/>.
29 """ Updates mirrorlists and databases """
36 import misc.extra as misc
39 """ Synchronize cached writes to persistent storage """
41 subprocess.check_call(['/usr/bin/sync'])
42 except subprocess.CalledProcessError as why:
44 "Can't synchronize cached writes to persistent storage: %s",
47 def update_mirrorlists():
48 """ Make sure we have the latest mirrorlist files """
49 """ Remove antergos-mirrorlis, and add reborn-mirrorlist (Rafael) """
51 "/etc/pacman.d/mirrorlist",
52 "/etc/pacman.d/reborn-mirrorlist"]
61 with misc.raised_privileges():
63 with open(os.devnull, 'w') as fnull:
64 subprocess.call(cmd, stdout=fnull,
65 stderr=subprocess.STDOUT)
66 # Use the new downloaded mirrorlist (.pacnew) files (if any)
67 for mirrorlist in mirrorlists:
68 pacnew_path = mirrorlist + ".pacnew"
69 if os.path.exists(pacnew_path):
70 shutil.copy(pacnew_path, mirrorlist)
72 logging.debug("Mirrorlists updated successfully")
73 except subprocess.CalledProcessError as why:
75 'Cannot update mirrorlists files: %s', why)
76 except OSError as why:
77 logging.warning('Error copying new mirrorlist files: %s', why)
80 """ Tests this module """
82 with misc.raised_privileges():
86 if __name__ == '__main__':