
Nc        %  @   s$  d  Z  d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k	 l
 Z
 d d k l Z e Z e e i  d j o( e i d d/j o e Z e i d =n d	 e i j p d
 e i j p e i d o e  i   GHe i d  n e i i e  i d  o/ e i i d e i i e i i e    n e d d d d d d d d d d d d d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d: d; d< d= d> d? d@ dA dB dC dD dE dF dG dH dI dJ dK dL dM dN dO dP dQ dR dS dT dU dV dW dX dY dZ d[ d\ d] d^ d_ d` da db dc dd de df dg dh di dj dk dl dm dn do dp dq dr ds dt du dv dw dx dy dz d{ d| d} d~ d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d ddddddddd	d
dddddddddddddddddddddd d!d"d#d$d%g Z d&  Z d'  Z d(  Z e  i d) d GHHe d*d+ GHHe o e d,d+ GHHn e Z d-e i j o e e   OZ n e i i  d- e   Z! x e i d D] Z e i i" e  p e# d.e   n e i i$ e  o e! i% e  q\xY e i& e  D]H \ Z' Z( Z) x6 e) D]. Z* e! i% e i i+ e i i, e' e*    qWqWq\We e e- e!   d S(0  s  migrate-0.8.py - Find all occurences of funcs./attrs. deprecated in 0.8.

Usage: python2.6 migrate-0.8.py [options] <file/directory>...

This reads the list of all functions and attributes available only in
COMPAT_0_7 builds and checks for occurences in the given Python modules. Has
to be run from the python-apt source code directory.

Requires python2.6 to be installed.

Parameters:
    -h  Display this help
    -c  Colorize the matching parts in the output.
iN(   t   defaultdict(   t   filli   s   -cs   --colors   --colours   -hs   --helpi    t   utilss   .Adds   .AllTargetss   .Archs   .Architectures   .Archives   .ArchiveURIs   .Autos   .Base64Encodes	   .Binariess   .BrokenCounts   .BuildDependss   .Bytess	   .CheckDeps   .CheckDomainLists   .Clears   .Closes   .Commits	   .CompTypes	   .Completes
   .Components   .Configs   .CurStateConfigFiless   .CurStateHalfConfigureds   .CurStateHalfInstalleds   .CurStateInstalleds   .CurStateNotInstalleds   .CurStateUnPackeds   .CurrentStates   .CurrentVers   .Dates   .DeQuoteStrings   .DebSizes	   .DelCounts   .DepTypes   .DependsCounts   .DependsLists   .DependsListStrs   .DescURIs	   .Describes	   .DestFiles   .Dists
   .DoInstalls   .Downloadables
   .ErrorTexts
   .Essentials   .Existss   .FetchNeededs	   .FileLists	   .FileNames	   .FileSizes   .Filess   .Finds   .FindBs   .FindDirs	   .FindFiles	   .FindFlags   .FindIs
   .FindIndexs   .FindRaws
   .FixBrokens   .FixMissings   .GetAcquires   .GetArchivess	   .GetCaches   .GetCandidateVers	   .GetCdroms   .GetDepCaches   .GetIndexess   .GetLocks   .GetPackageManagers   .GetPkgAcqFiles   .GetPkgActionGroups   .GetPkgProblemResolvers   .GetPkgRecordss   .GetPkgSourceLists   .GetPkgSrcRecordss   .HasPackagess   .Hashs	   .Homepages   .IDs   .Idents
   .Importants   .Indexs   .IndexFiless
   .IndexTypes   .Inits   .InitConfigs   .InitSystems
   .InstCounts
   .InstStates   .InstStateHolds   .InstStateHoldReInstReqs   .InstStateOks   .InstStateReInstReqs   .InstallProtects   .InstalledSizes   .IsAutoInstalleds
   .IsGarbages   .IsInstBrokens   .IsNowBrokens
   .IsTrusteds   .IsUpgradables   .Itemss   .Jumps
   .KeepCounts   .Labels   .LanguageCodes   .LibVersions   .Lists   .Locals	   .LongDescs   .Lookups   .MD5Hashs   .Maintainers   .MarkDeletes   .MarkInstalls	   .MarkKeeps   .MarkedDeletes   .MarkedDowngrades   .MarkedInstalls   .MarkedKeeps   .MarkedReinstalls   .MarkedUpgrades   .MinimizeUpgrades   .MyTags   .Names   .NotAutomatics
   .NotSources   .Offsets   .Opens   .Origins   .Packages   .PackageCounts   .PackageFileCounts	   .Packagess
   .ParentPkgs
   .ParentVers   .ParseCommandLines   .ParseDependss   .ParseSections   .ParseSrcDependss   .ParseTagFiles   .PartialPresents   .PkgSystemLocks   .PkgSystemUnLocks	   .PriExtras   .PriImportants   .PriOptionals   .PriRequireds   .PriStandards	   .Prioritys   .PriorityStrs   .Protects   .ProvidesCounts   .ProvidesLists   .QuoteStrings   .ReadConfigDirs   .ReadConfigFiles   .ReadConfigFileISCs   .ReadMainLists   .ReadPinFiles   .Records   .Removes   .Resolves   .ResolveByKeeps   .Restarts   .RevDependsLists   .RewriteSections   .RewriteSourceOrders   .Runs	   .SHA1Hashs   .SHA256Hashs   .Sections   .SelStateDeInstalls   .SelStateHolds   .SelStateInstalls   .SelStatePurges   .SelStateUnknowns   .SelectedStates   .Sets   .SetCandidateVers   .SetReInstalls
   .ShortDescs	   .Shutdowns   .Sites   .Sizes
   .SizeToStrs   .SmartTargetPkgs
   .SourcePkgs
   .SourceVers   .Statuss   .Steps
   .StrToTimes   .StringToBools   .SubTrees
   .TargetPkgs
   .TargetVers   .Times   .TimeRFC1123s
   .TimeToStrs   .TotalNeededs   .TranslationDescriptions   .URIs   .URItoFileNames   .Updates   .Upgrades   .UpstreamVersions   .UsrSizes
   .ValueLists   .VerFileCounts   .VerStrs   .Versions   .VersionCompares   .VersionCounts   .VersionLists   .newConfigurationt   Base64Encodet   CheckDept   CheckDomainListt   Configt   CurStateConfigFilest   CurStateHalfConfiguredt   CurStateHalfInstalledt   CurStateInstalledt   CurStateNotInstalledt   CurStateUnPackedt   Datet   DeQuoteStringt
   GetAcquiret   GetCachet   GetCdromt   GetDepCachet   GetLockt   GetPackageManagert   GetPkgAcqFilet   GetPkgActionGroupt   GetPkgProblemResolvert   GetPkgRecordst   GetPkgSourceListt   GetPkgSrcRecordst
   InitConfigt
   InitSystemt   InstStateHoldt   InstStateHoldReInstReqt   InstStateOkt   InstStateReInstReqt
   LibVersiont   ParseCommandLinet   ParseDependst   ParseSectiont   ParseSrcDependst   ParseTagFilet   PkgSystemLockt   PkgSystemUnLockt   PriExtrat   PriImportantt   PriOptionalt   PriRequiredt   PriStandardt   QuoteStringt   ReadConfigDirt   ReadConfigFilet   ReadConfigFileISCt   RewriteSectiont   RewriteSourceOrdert   SelStateDeInstallt   SelStateHoldt   SelStateInstallt   SelStatePurget   SelStateUnknownt	   SizeToStrt	   StrToTimet   StringToBoolt   Timet   TimeRFC1123t	   TimeToStrt   URItoFileNamet   UpstreamVersiont   VersionComparet   newConfigurations   .has_keyc         C   sI   t  p |  Sx6 | D]. } t i |  } t i d | d |   }  q W|  S(   s3   Colorize (red) the given words in the given string.s   ([^_]*)(%s)([^_]*)s   \1[31m[1ms   \2s   [0m\3s   \1[31m[1m\2s   \1[31m[1m\2[0m\3(   t   colort   ret   escapet   sub(   t   stringt   wordst   word(    (    s$   /usr/share/python-apt/migrate-0.8.pyt   do_color   s     c    	         s  d }  d d k  } d | _ t t i  } t   t   } } x t |   D] } t | d d g } xm t |  D]_   t |    } t	 | t
 i  p | i    qr n | i   f d   t |  D  qr WqJ Wx2 t i i   D]! } | | j o t i | =q q Wd | _ x t |   D] } t | d d g } x t |  D]}   t |    } t	 | t
 i  p | i    qLn x> t |  D]0 }   d | | j o | i d |  qqWqLWq$Wx2 t i i   D]! } | | j o t i | =qqW| i |  S(   s   Find all the deprecated functions and attributes.

    Import apt_pkg, set _COMPAT_0_7 to 0, import apt and aptsources and
    create a list of all attributes. Then remove the imported modules,
    reimport them (with _COMPAT_0_7=1), and see which functions do not
    exist anymore.
    t   apts   apt.packages	   apt.cdroms	   apt.caches   apt.debfiles   apt.progresss   apt.progress.olds   aptsources.distinfos   aptsources.distros   aptsources.sourceslistiNi    t   fromlistt   *c         3   s!   x |  ] }   d  | Vq Wd S(   t   .N(    (   t   .0t   name(   t   clsname(    s$   /usr/share/python-apt/migrate-0.8.pys	   <genexpr>   s   	 i   RN   (
   RK   s   apt.packages	   apt.cdroms	   apt.caches   apt.debfiles   apt.progresss   apt.progress.olds   aptsources.distinfos   aptsources.distros   aptsources.sourceslist(   t   apt_pkgt   _COMPAT_0_7t   sett   syst   modulest   sortedt
   __import__t   dirt   getattrt
   isinstancet   typest   TypeTypet   addt   updatet   keyst
   difference(	   RV   RR   t   emptyt   newt
   deprecatedt   mnamet   modulet   clsRP   (    (   RQ   s$   /usr/share/python-apt/migrate-0.8.pyt   find_deprecated_py   sP    	  	  + 	   ! c   
      C   s  x| D]} t  i i |  p q n | t i j p, | i d  p t i d t |  i	    p q n t
 d    } y% t i t | d  i   |  } Wn/ t j
 o# } t i d | | f IJq n Xx t i |  D] } t | t i  oC x@ | i D]1 } | i |  j o | | i i | i  qqWn t | t i  o+ | i |  j o | | i i | i  n t | t i  o/ d | i |  j o | | i i | i  q q WxN t |  D]@ } t t i | |  i  d  | |  }	 d | | |	 f GHqWq Wd	 S(
   s.   Find all ocurrences in the given Python files.s   .pys   ^#.*python.*c           S   s   t    S(    (   RT   (    (    (    s$   /usr/share/python-apt/migrate-0.8.pyt   <lambda>   s    t   rUs   Ignoring %s: %sRN   s   
s   %s:%s:%sN(!   t   ost   patht   existsRU   t   argvt   endswithRD   t   matcht   opent   readlineR    t   astt   parset   readt	   Exceptiont   stderrt   walkR[   t   _astt
   ImportFromt   namesRP   t   linenoR^   t   Namet   idt	   Attributet   attrRW   RJ   t	   linecachet   getlinet   rstrip(
   t   all_oldt   filest   fnameRH   t   nodet   et   it   aliasR|   t   line(    (    s$   /usr/share/python-apt/migrate-0.8.pyt   find_occurences   s:      % 
 ##' s   
sy   Information: Please verify that the results are correct before you modify any code, because there may be false positives.iO   sh   Information: The color is not always correct, because we simply highlight the matched words (like grep).s   -Ps   Path does not exist: %s(   s   -cs   --colors   --colour(.   t   __doc__Ry   Rs   t   globR   Rk   RD   RU   R\   t   collectionsR    t   textwrapR   t   FalseRC   t   lenRn   t   Truet   stript   exitRl   t   dirnamet   __file__Ro   t   insertRT   t   deprecated_cpp_stuffRJ   Rh   R   t   splitR   t   removeR   Rm   t
   ValueErrort   isfileR^   Rx   t   roott   dirst   files_R   t   normpatht   joinRW   (    (    (    s$   /usr/share/python-apt/migrate-0.8.pyt   <module>"   s   *//															
	7	!	   4