ar.py 2.68 KB
 Ximin Luo committed Jul 18, 2016 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 # -*- coding: utf-8 -*- # # diffoscope: in-depth comparison of files, archives, and directories # # Copyright © 2014-2015 Jérémy Bobbio # Copyright © 2016 Ximin Luo # # diffoscope is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # diffoscope is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License  Emanuel Bronshtein committed Dec 18, 2016 19 # along with diffoscope. If not, see .  Ximin Luo committed Jul 18, 2016 20 21  import re  Chris Lamb committed Jan 03, 2017 22 import logging  Chris Lamb committed Aug 15, 2016 23   Chris Lamb committed Dec 28, 2016 24 from diffoscope.tools import tool_required  Ximin Luo committed Jul 18, 2016 25 from diffoscope.difference import Difference  Chris Lamb committed Dec 27, 2016 26   Chris Lamb committed Dec 28, 2016 27 from .utils.file import File  Chris Lamb committed Dec 28, 2016 28 from .utils.command import Command  Chris Lamb committed Dec 27, 2016 29 from .utils.libarchive import LibarchiveContainer, list_libarchive  Ximin Luo committed Jul 18, 2016 30   Chris Lamb committed Jan 03, 2017 31 32 logger = logging.getLogger(__name__)  Ximin Luo committed Aug 13, 2016 33   Ximin Luo committed Jul 18, 2016 34 35 36 37 38 # TODO: this would also be useful for Go archives. Currently those are handled # by StaticLibFile, but then readelf complains with "Error: Not an ELF file". # ArFile gives slightly more reasonable output, e.g. a readable plain diff of # the __.PKGDEF member which is just a text file containing the Go interface.  Ximin Luo committed Jul 18, 2016 39 class ArContainer(LibarchiveContainer):  Ximin Luo committed May 26, 2017 40 41  def get_adjusted_members(self): members = list(super().get_adjusted_members())  Ximin Luo committed Aug 13, 2016 42  known_ignores = {  Mattia Rizzolo committed Sep 09, 2017 43 44  "/": "this is the symbol table, already accounted for in other output", "//": "this is the table for GNU long names, already accounted for in the archive filelist",  Ximin Luo committed Aug 13, 2016 45  }  Ximin Luo committed May 26, 2017 46  filtered_out = [p for p in members if p[0] in known_ignores]  Ximin Luo committed Jul 18, 2016 47  if filtered_out:  Ximin Luo committed May 26, 2017 48  for k, v in filtered_out:  Chris Lamb committed May 21, 2018 49 50  logger.debug("ignored ar member '%s' because %s", k, known_ignores[k])  Ximin Luo committed May 26, 2017 51  return [p for p in members if p[0] not in known_ignores]  Ximin Luo committed Jul 18, 2016 52   Mattia Rizzolo committed Sep 09, 2017 53   Ximin Luo committed Aug 13, 2016 54 55 56 57 class ArSymbolTableDumper(Command): @tool_required('nm') def cmdline(self): return ['nm', '-s', self.path]  Ximin Luo committed Jul 18, 2016 58   Mattia Rizzolo committed Sep 09, 2017 59   Ximin Luo committed Jul 18, 2016 60 class ArFile(File):  Chris Lamb committed Mar 18, 2018 61  DESCRIPTION = "ar(1) archives"  Ximin Luo committed Jul 18, 2016 62  CONTAINER_CLASS = ArContainer  Ximin Luo committed Jul 25, 2017 63  FILE_TYPE_RE = re.compile(r'\bar archive\b')  Ximin Luo committed Jul 18, 2016 64 65  def compare_details(self, other, source=None):  Ximin Luo committed Aug 13, 2016 66 67 68 69  return [Difference.from_command(ArSymbolTableDumper, self.path, other.path), Difference.from_text_readers(list_libarchive(self.path), list_libarchive(other.path), self.path, other.path, source="file list")]