def main_exec(opts: Namespace, emerge_opts: List[str]) -> None: """ Main execution function. :param opts: cli arguments :param emerge_opts: list of arguments for emege """ if opts.world: emerge_opts = [ '--with-bdeps=y', '--keep-going=y', '--newuse', '--deep', '--update', '@world' ] if opts.pretend_world: emerge_opts = [ '--with-bdeps=y', '--pretend', '--verbose', '--newuse', '--deep', '--update', '@world' ] info(f'Pyerge version: {__version__}') opts.online = utils.is_internet_connected() if not tmerge.is_portage_running(): utils.set_portage_tmpdir() utils.handling_mounting(opts) tmerge.run_emerge(emerge_opts, opts) tmerge.run_check(opts) utils.unmounttmpfs(opts) else: info('emerge already running!')
def test_is_internet_connected(): with mock.patch('pyerge.utils.run_cmd') as run_cmd_mock: run_cmd_mock.return_value = b'PING 89.16.167.134 (89.16.167.134) 56(84) bytes of data.\n' \ b'64 bytes from 89.16.167.134: icmp_seq=1 ttl=47 time=52.2 ms\n\n' \ b'--- 89.16.167.134 ping statistics ---\n' \ b'1 packets transmitted, 1 received, 0% packet loss, time 0ms\n' \ b'rtt min/avg/max/mdev = 52.212/52.212/52.212/0.000 ms\n', b'' assert utils.is_internet_connected(verbose=True) is True
def run_parser(): """ Function to collect command line arguments. Construct main object with correct set of parameters. """ parser = ArgumentParser(description='Emerge in temporary RAM disk') parser.add_argument('-s', '--size', action='store', dest='size', default='4G', help='Size or RAM disk, default 4G') parser.add_argument('-l', '--check_local', action='store_true', dest='local', default=False, help='check locally') parser.add_argument('-d', '--deep_clean', action='store_true', dest='deep', default=False, help='run deep clean after emerge') parser.add_argument('-w', '--world', action='store_true', dest='world', default=False, help='run emerge -NDu @world') parser.add_argument('-r', '--pretend_world', action='store_true', dest='pretend_world', default=False, help='run emerge -pvNDu @world') parser.add_argument('-v', '--verbose', action='count', dest='verbose', default=0, help='Increase output verbosity') parser.add_argument('-e', '--elements', action='store', dest='elements', type=int, default='5', help='number of elements') parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + __version__) parser.add_argument('action', help='check, emerge, glsa_list or glsa_test') opts, emerge_opts = parser.parse_known_args() if opts.action not in ['check', 'emerge', 'glsa_list', 'glsa_test']: error(f'Wrong options: {opts} {emerge_opts}') exit() if opts.world: emerge_opts = ['-NDu', '@world'] if opts.pretend_world: emerge_opts = ['-pvNDu', '@world'] if opts.verbose: info(f'Pyerge version: {__version__}') opts.online = utils.is_internet_connected(opts.verbose) if opts.action in ('glsa_list', 'glsa_test'): run_glsa(opts) exit() if not tmerge.is_portage_running(): utils.set_portage_tmpdir() handling_mounting(opts) run_emerge(emerge_opts, opts) run_check(opts) utils.unmounttmpfs(opts.size, opts.verbose) else: if opts.verbose: info('emerge already running!')
def test_is_internet_not_connected(): from pyerge import utils with mock.patch('pyerge.utils.run_cmd') as run_cmd_mock: run_cmd_mock.return_value = b'', b'' assert utils.is_internet_connected() is False
def test_is_internet_not_connected(): with mock.patch('pyerge.utils.run_cmd') as run_cmd_mock: run_cmd_mock.return_value = b'', b'' assert utils.is_internet_connected(verbose=True) is False