Best Python code snippet using autotest_python
repack_rust.py
Source:repack_rust.py  
...51  from the given manifest.'''52  version = manifest['pkg'][pkg]['version']53  info = manifest['pkg'][pkg]['target'][target]54  return (version, info)55def fetch_package(manifest, pkg, host):56  version, info = package(manifest, pkg, host)57  print('%s %s\n  %s\n  %s' % (pkg, version, info['url'], info['hash']))58  if not info['available']:59    print('%s marked unavailable for %s' % (pkg, host))60    raise AssertionError61  fetch(info['url'])62  return info63def fetch_std(manifest, targets):64  stds = []65  for target in targets:66      info = fetch_package(manifest, 'rust-std', target)67      stds.append(info)68  return stds69def tar_for_host(host):70  if 'linux' in host:71      tar_options = 'cJf'72      tar_ext = '.tar.xz'73  else:74      tar_options = 'cjf'75      tar_ext = '.tar.bz2'76  return tar_options, tar_ext77def repack(host, targets, channel='stable', suffix=''):78  print("Repacking rust for %s..." % host)79  url = 'https://static.rust-lang.org/dist/channel-rust-' + channel + '.toml'80  req = requests.get(url)81  req.raise_for_status()82  manifest = toml.loads(req.content)83  if manifest['manifest-version'] != '2':84    print('ERROR: unrecognized manifest version %s.' % manifest['manifest-version'])85    return86  print('Using manifest for rust %s as of %s.' % (channel, manifest['date']))87  print('Fetching packages...')88  rustc = fetch_package(manifest, 'rustc', host)89  cargo = fetch_package(manifest, 'cargo', host)90  stds = fetch_std(manifest, targets)91  print('Installing packages...')92  tar_basename = 'rustc-' + host93  if suffix:94      tar_basename += '-' + suffix95  tar_basename += '-repack'96  install_dir = 'rustc'97  subprocess.check_call(['rm', '-rf', install_dir])98  install(os.path.basename(rustc['url']), install_dir)99  install(os.path.basename(cargo['url']), install_dir)100  for std in stds:101    install(os.path.basename(std['url']), install_dir)102    pass103  print('Tarring %s...' % tar_basename)104  tar_options, tar_ext = tar_for_host(host)105  subprocess.check_call(['tar', tar_options, tar_basename + tar_ext, install_dir])106  subprocess.check_call(['rm', '-rf', install_dir])107def repack_cargo(host, channel='nightly'):108  print("Repacking cargo for %s..." % host)109  # Cargo doesn't seem to have a .toml manifest.110  base_url = 'https://static.rust-lang.org/cargo-dist/'111  req = requests.get(os.path.join(base_url, 'channel-cargo-' + channel))112  req.raise_for_status()113  file = ''114  for line in req.iter_lines():115      if line.find(host) != -1:116          file = line.strip()117  if not file:118      print('No manifest entry for %s!' % host)119      return120  manifest = {121          'date': req.headers['Last-Modified'],122          'pkg': {123              'cargo': {124                  'version': channel,125                  'target': {126                      host: {127                          'url': os.path.join(base_url, file),128                          'hash': None,129                          'available': True,130                      },131                  },132              },133          },134  }135  print('Using manifest for cargo %s.' % channel)136  print('Fetching packages...')137  cargo = fetch_package(manifest, 'cargo', host)138  print('Installing packages...')139  install_dir = 'cargo'140  subprocess.check_call(['rm', '-rf', install_dir])141  install(os.path.basename(cargo['url']), install_dir)142  tar_basename = 'cargo-%s-repack' % host143  print('Tarring %s...' % tar_basename)144  tar_options, tar_ext = tar_for_host(host)145  subprocess.check_call(['tar', tar_options, tar_basename + tar_ext, install_dir])146  subprocess.check_call(['rm', '-rf', install_dir])147# rust platform triples148android="armv7-linux-androideabi"149linux64="x86_64-unknown-linux-gnu"150linux32="i686-unknown-linux-gnu"151mac64="x86_64-apple-darwin"...Fetch.py
Source:Fetch.py  
1from NikGappsPackages import NikGappsPackages2import Config3from NikGapps.Helper.Cmd import Cmd4from NikGapps.Helper.AppSet import AppSet5from NikGapps.Helper.Package import Package6class Fetch:7    @staticmethod8    def package(fetch_package, sent_message=None):9        cmd = Cmd()10        if fetch_package.lower() == "all":11            fetch_package = "full"12        if Config.ADB_ROOT_ENABLED:13            if cmd.established_device_connection_as_root():14                Config.ADB_ROOT_ENABLED = True15            else:16                print("Device not found! or failed to acquire Root permissions")17                return []18        return Fetch.fetch_packages(sent_message, fetch_package)19    @staticmethod20    def fetch_packages(sent_message, fetch_package):21        # Get the list of packages that we want to pull from connected device22        app_set_list = NikGappsPackages.get_packages(fetch_package)23        # Fetch all the packages from the device24        # We will check for errors here (need to make sure we pulled all the files we were looking for25        # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #26        if app_set_list is None or app_set_list[0] is None:27            return []28        updated_pkg_list = []29        failure_summary = ""30        for app_set in app_set_list:31            app_set: AppSet32            message = "--> Working on " + app_set.title33            if sent_message is not None:34                sent_message.edit_text(message)35            print(message)36            for pkg in app_set.package_list:37                pkg: Package38                pkg.validate()39                failure_summary += pkg.failure_logs40                message = pkg.package_title + " Ready to be fetched"41                if sent_message is not None:42                    sent_message.edit_text(message)43                print(message)44                if pkg.primary_app_location is not None or pkg.package_name is None \45                        or pkg.predefined_file_list.__len__() > 0:46                    pkg.pull_package_files(app_set.title)47                    failure_summary += pkg.failure_logs48                    message = pkg.package_title + " Successfully Fetched!"49                    if sent_message is not None:50                        sent_message.edit_text(message)51                    print(message)52                updated_pkg_list.append(pkg)53        if not str(failure_summary).__eq__(""):54            print("")55            print("Failure Summary:")56            print(failure_summary)...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
