(self, contents)
Install a new ``/etc/apt/sources.list`` file.

        :param contents: The new contents of the sources list (a Unicode
                         string). You can generate a suitable value using
                         the :func:`generate_sources_list()` method.
Install a new ``/etc/apt/sources.list`` file.
Install a new / etc / apt / sources . list file .
def install_sources_list(self, contents):
        """
        Install a new ``/etc/apt/sources.list`` file.

        :param contents: The new contents of the sources list (a Unicode
                         string). You can generate a suitable value using
                         the :func:`generate_sources_list()` method.
        """
        if isinstance(contents, text_type):
            contents = contents.encode(SOURCES_LIST_ENCODING)
        logger.info("Installing new %s ..", self.main_sources_list)
        with self.context:
            # Write the sources.list contents to a temporary file. We make sure
            # the file always ends in a newline to adhere to UNIX conventions.
            temporary_file = '/tmp/apt-smart-sources-list-%i.txt' % os.getpid()
            contents_to_write = contents.rstrip() + b'\n'
            self.context.write_file(temporary_file, contents_to_write)
            # Make sure the temporary file is cleaned up when we're done with it.
            self.context.cleanup('rm', '--force', temporary_file)
            # Make a backup copy of /etc/apt/sources.list in case shit hits the fan?
            if self.context.exists(self.main_sources_list):
                dirname, basename = os.path.split(self.main_sources_list)
                if basename == 'official-package-repositories.list':
                    backup_dir = os.path.join(dirname, 'backup_by_apt-smart')  # Backup to dir for Linux Mint
                    if not self.context.exists(backup_dir):
                        self.context.execute('mkdir', backup_dir, sudo=True)
                    backup_copy = '%s.backup.%i' % (os.path.join(backup_dir, basename), time.time())
                else:
                    backup_copy = '%s.backup.%i' % (self.main_sources_list, time.time())
                logger.info("Backing up contents of %s to %s ..", self.main_sources_list, backup_copy)
                self.context.execute('cp', self.main_sources_list, backup_copy, sudo=True)
            # Move the temporary file into place without changing ownership and permissions.
            self.context.execute(
                'cp', '--no-preserve=mode,ownership',
                temporary_file, self.main_sources_list,
                sudo=True,
            )
def install_sources_list ( self , contents ) : if isinstance ( contents , text_type ) : contents = contents . encode ( SOURCES_LIST_ENCODING ) logger . info ( "Installing new %s .." , self . main_sources_list ) with self . context : # Write the sources.list contents to a temporary file. We make sure # the file always ends in a newline to adhere to UNIX conventions. temporary_file = '/tmp/apt-smart-sources-list-%i.txt' % os . getpid ( ) contents_to_write = contents . rstrip ( ) + b'\n' self . context . write_file ( temporary_file , contents_to_write ) # Make sure the temporary file is cleaned up when we're done with it. self . context . cleanup ( 'rm' , '--force' , temporary_file ) # Make a backup copy of /etc/apt/sources.list in case shit hits the fan? if self . context . exists ( self . main_sources_list ) : dirname , basename = os . path . split ( self . main_sources_list ) if basename == 'official-package-repositories.list' : backup_dir = os . path . join ( dirname , 'backup_by_apt-smart' ) # Backup to dir for Linux Mint if not self . context . exists ( backup_dir ) : self . context . execute ( 'mkdir' , backup_dir , sudo = True ) backup_copy = '%s.backup.%i' % ( os . path . join ( backup_dir , basename ) , time . time ( ) ) else : backup_copy = '%s.backup.%i' % ( self . main_sources_list , time . time ( ) ) logger . info ( "Backing up contents of %s to %s .." , self . main_sources_list , backup_copy ) self . context . execute ( 'cp' , self . main_sources_list , backup_copy , sudo = True ) # Move the temporary file into place without changing ownership and permissions. self . context . execute ( 'cp' , '--no-preserve=mode,ownership' , temporary_file , self . main_sources_list , sudo = True , )