<s> from __future__ import print_function , division , absolute_import <EOL> from conda . cli import common <EOL> from conda . misc import make_icon_url <EOL> from conda . resolve import NoPackagesFound , Package <EOL> from conda import config <EOL> descr = """<STR_LIT>""" <EOL> example = '''<STR_LIT>''' <EOL> class Platforms ( common . Completer ) : <EOL> """<STR_LIT>""" <EOL> def _get_items ( self ) : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def configure_parser ( sub_parsers ) : <EOL> p = sub_parsers . add_parser ( <EOL> '<STR_LIT>' , <EOL> description = descr , <EOL> help = descr , <EOL> epilog = example , <EOL> ) <EOL> common . add_parser_prefix ( p ) <EOL> p . add_argument ( <EOL> "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" , <EOL> ) <EOL> p . add_argument ( <EOL> '<STR_LIT>' , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" , <EOL> ) <EOL> p . add_argument ( <EOL> "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" , <EOL> ) <EOL> common . add_parser_known ( p ) <EOL> common . add_parser_use_index_cache ( p ) <EOL> p . add_argument ( <EOL> '<STR_LIT>' , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" , <EOL> ) <EOL> p . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store>' , <EOL> dest = '<STR_LIT>' , <EOL> help = """<STR_LIT>""" , <EOL> choices = Platforms ( ) , <EOL> default = None , <EOL> ) <EOL> p . add_argument ( <EOL> "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> help = """<STR_LIT>""" , <EOL> ) <EOL> p . add_argument ( <EOL> "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> help = """<STR_LIT>""" , <EOL> ) <EOL> p . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> action = "<STR_LIT:store>" , <EOL> nargs = "<STR_LIT:?>" , <EOL> help = """<STR_LIT>""" , <EOL> ) . completer = common . Packages <EOL> common . add_parser_offline ( p ) <EOL> common . add_parser_channels ( p ) <EOL> common . add_parser_json ( p ) <EOL> common . add_parser_use_local ( p ) <EOL> p . set_defaults ( func = execute ) <EOL> def execute ( args , parser ) : <EOL> try : <EOL> execute_search ( args , parser ) <EOL> except NoPackagesFound as e : <EOL> common . exception_and_exit ( e , json = args . json ) <EOL> def execute_search ( args , parser ) : <EOL> import re <EOL> from conda . resolve import Resolve <EOL> if args . reverse_dependency : <EOL> if not args . regex : <EOL> parser . error ( "<STR_LIT>" ) <EOL> if args . spec : <EOL> parser . error ( "<STR_LIT>" ) <EOL> pat = None <EOL> ms = None <EOL> if args . regex : <EOL> if args . spec : <EOL> ms = '<STR_LIT:U+0020>' . join ( args . regex . split ( '<STR_LIT:=>' ) ) <EOL> else : <EOL> regex = args . regex <EOL> if args . full_name : <EOL> regex = r'<STR_LIT>' % regex <EOL> try : <EOL> pat = re . compile ( regex , re . I ) <EOL> except re . error as e : <EOL> common . error_and_exit ( <EOL> "<STR_LIT>" % <EOL> ( regex , e ) , <EOL> json = args . json , <EOL> error_type = "<STR_LIT>" ) <EOL> prefix = common . get_prefix ( args ) <EOL> import conda . config <EOL> import conda . install <EOL> linked = conda . install . linked ( prefix ) <EOL> extracted = conda . install . extracted ( ) <EOL> platform = args . platform or '<STR_LIT>' <EOL> if platform and platform != config . subdir : <EOL> args . unknown = False <EOL> common . ensure_use_local ( args ) <EOL> common . ensure_override_channels_requires_channel ( args , dashc = False ) <EOL> channel_urls = args . channel or ( ) <EOL> index = common . get_index_trap ( channel_urls = channel_urls , prepend = not args . override_channels , <EOL> platform = args . platform , use_local = args . use_local , <EOL> use_cache = args . use_index_cache , prefix = prefix , <EOL> unknown = args . unknown , json = args . json , offline = args . offline ) <EOL> r = Resolve ( index ) <EOL> if args . canonical : <EOL> json = [ ] <EOL> else : <EOL> json = { } <EOL> names = [ ] <EOL> for name in sorted ( r . groups ) : <EOL> if '<STR_LIT:@>' in name : <EOL> continue <EOL> if args . reverse_dependency : <EOL> ms_name = ms <EOL> for pkg in r . groups [ name ] : <EOL> for dep in r . ms_depends ( pkg ) : <EOL> if pat . search ( dep . name ) : <EOL> names . append ( ( name , Package ( pkg , r . index [ pkg ] ) ) ) <EOL> else : <EOL> if pat and pat . search ( name ) is None : <EOL> continue <EOL> if ms and name != ms . split ( ) [ <NUM_LIT:0> ] : <EOL> continue <EOL> if ms : <EOL> ms_name = ms <EOL> else : <EOL> ms_name = name <EOL> pkgs = sorted ( r . get_pkgs ( ms_name ) ) <EOL> names . append ( ( name , pkgs ) ) <EOL> if args . reverse_dependency : <EOL> new_names = [ ] <EOL> old = None <EOL> for name , pkg in sorted ( names , key = lambda x : ( x [ <NUM_LIT:0> ] , x [ <NUM_LIT:1> ] . name , x [ <NUM_LIT:1> ] ) ) : <EOL> if name == old : <EOL> new_names [ - <NUM_LIT:1> ] [ <NUM_LIT:1> ] . append ( pkg ) <EOL> else : <EOL> new_names . append ( ( name , [ pkg ] ) ) <EOL> old = name <EOL> names = new_names <EOL> for name , pkgs in names : <EOL> if args . reverse_dependency : <EOL> disp_name = pkgs [ <NUM_LIT:0> ] . name <EOL> else : <EOL> disp_name = name <EOL> if args . names_only and not args . outdated : <EOL> print ( name ) <EOL> continue <EOL> if not args . canonical : <EOL> json [ name ] = [ ] <EOL> if args . outdated : <EOL> vers_inst = [ dist . rsplit ( '<STR_LIT:->' , <NUM_LIT:2> ) [ <NUM_LIT:1> ] for dist in linked <EOL> if dist . rsplit ( '<STR_LIT:->' , <NUM_LIT:2> ) [ <NUM_LIT:0> ] == name ] <EOL> if not vers_inst : <EOL> continue <EOL> assert len ( vers_inst ) == <NUM_LIT:1> , name <EOL> if not pkgs : <EOL> continue <EOL> latest = pkgs [ - <NUM_LIT:1> ] <EOL> if latest . version == vers_inst [ <NUM_LIT:0> ] : <EOL> continue <EOL> if args . names_only : <EOL> print ( name ) <EOL> continue <EOL> for pkg in pkgs : <EOL> dist = pkg . fn [ : - <NUM_LIT:8> ] <EOL> if args . canonical : <EOL> if not args . json : <EOL> print ( dist ) <EOL> else : <EOL> json . append ( dist ) <EOL> continue <EOL> if platform and platform != config . subdir : <EOL> inst = '<STR_LIT:U+0020>' <EOL> elif dist in linked : <EOL> inst = '<STR_LIT:*>' <EOL> elif dist in extracted : <EOL> inst = '<STR_LIT:.>' <EOL> else : <EOL> inst = '<STR_LIT:U+0020>' <EOL> if not args . json : <EOL> print ( '<STR_LIT>' % ( <EOL> disp_name , inst , <EOL> pkg . version , <EOL> pkg . build , <EOL> config . canonical_channel_name ( pkg . channel ) , <EOL> common . disp_features ( r . features ( pkg . fn ) ) , <EOL> ) ) <EOL> disp_name = '<STR_LIT>' <EOL> else : <EOL> data = { } <EOL> data . update ( pkg . info ) <EOL> data . update ( { <EOL> '<STR_LIT>' : pkg . fn , <EOL> '<STR_LIT>' : inst == '<STR_LIT:*>' , <EOL> '<STR_LIT>' : inst in '<STR_LIT>' , <EOL> '<STR_LIT:version>' : pkg . version , <EOL> '<STR_LIT>' : pkg . build , <EOL> '<STR_LIT>' : pkg . build_number , <EOL> '<STR_LIT>' : config . canonical_channel_name ( pkg . channel ) , <EOL> '<STR_LIT>' : pkg . channel , <EOL> '<STR_LIT>' : list ( r . features ( pkg . fn ) ) , <EOL> '<STR_LIT>' : pkg . info . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT:size>' : pkg . info . get ( '<STR_LIT:size>' ) , <EOL> '<STR_LIT>' : pkg . info . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT:type>' : pkg . info . get ( '<STR_LIT:type>' ) <EOL> } ) <EOL> if data [ '<STR_LIT:type>' ] == '<STR_LIT>' : <EOL> data [ '<STR_LIT>' ] = make_icon_url ( pkg . info ) <EOL> json [ name ] . append ( data ) <EOL> if args . json : <EOL> common . stdout_json ( json ) </s>
