reduceDoubles method

Future<List<String>> reduceDoubles(
  1. Iterable<String> packages
)

Reduces the amount of dependencies: If a packages A is part of the dependencies of another package B it is enough to remember B.

Implementation

Future<List<String>> reduceDoubles(Iterable<String> packages) async {
  final rc = packages.map((e) => e.split(':')[0]).toList();
  for (var package in excludedPackages) {
    rc.remove(package);
  }
  log('Packages: ${rc.length}');
  final count = rc.length;
  int ix = 0;
  for (var package in packages) {
    if (!excludedPackages.contains(package.split(':')[0])) {
      final lines = await executeResult('apt-cache', ['show', package]);
      for (var line in lines) {
        if (line.startsWith('Depends:')) {
          final items = line.substring(8).trim().split(',');
          for (var item in items) {
            final name2 = item.trim().split(' ')[0];
            rc.remove(name2);
          }
          break;
        }
      }
    }
    if (++ix % 10 == 0) {
      logStatus('$ix of ${packages.length} packages processed...');
    }
  }
  final count2 = rc.length;
  if (count2 < count) {
    log('Packages reduced from $count to $count2');
  }
  return rc;
}