<s> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> import six . moves . urllib . parse <EOL> import itertools <EOL> import re <EOL> import os <EOL> class ArtifactError ( Exception ) : <EOL> pass <EOL> class NameVerDetectionError ( ArtifactError ) : <EOL> pass <EOL> class Artifact ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , group , artifact = '<STR_LIT>' , version = '<STR_LIT>' , classifier = '<STR_LIT>' , extension = '<STR_LIT>' ) : <EOL> self . group = group <EOL> self . artifact = artifact <EOL> self . version = version <EOL> self . classifier = classifier <EOL> self . extension = extension <EOL> def get_coordinates_string ( self ) : <EOL> return '<STR_LIT>' . format ( group = self . group , artifact = self . artifact , <EOL> version = self . version , <EOL> classifier = self . classifier , <EOL> extension = self . extension ) <EOL> def __repr__ ( self ) : <EOL> return self . get_coordinates_string ( ) <EOL> class LocalArtifact ( Artifact ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , group , local_path , artifact = '<STR_LIT>' , version = '<STR_LIT>' , classifier = '<STR_LIT>' , extension = '<STR_LIT>' ) : <EOL> self . local_path = local_path <EOL> if not artifact and not version : <EOL> artifact , version = self . detect_name_and_version ( ) <EOL> super ( LocalArtifact , self ) . __init__ ( group = group , artifact = artifact , version = version , classifier = classifier , <EOL> extension = extension ) <EOL> def detect_name_and_version ( self ) : <EOL> base_name = os . path . basename ( self . local_path ) <EOL> result = re . match ( '<STR_LIT>' , base_name ) <EOL> if result is None : <EOL> raise NameVerDetectionError ( '<STR_LIT>' , self . local_path ) <EOL> return result . group ( <NUM_LIT:1> ) , result . group ( <NUM_LIT:2> ) <EOL> class LocalRpmArtifact ( LocalArtifact ) : <EOL> """<STR_LIT>""" <EOL> @ staticmethod <EOL> def get_artifact_group ( url ) : <EOL> if url is None : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> parts = six . moves . urllib . parse . urlsplit ( url ) . netloc . split ( "<STR_LIT:.>" ) <EOL> return "<STR_LIT:.>" . join ( itertools . ifilter ( lambda x : x != "<STR_LIT>" , reversed ( parts ) ) ) <EOL> def __init__ ( self , local_path , group = None ) : <EOL> try : <EOL> import rpm <EOL> except ImportError : <EOL> raise ArtifactError ( "<STR_LIT>" ) <EOL> ts = rpm . ts ( ) <EOL> fdno = os . open ( local_path , os . O_RDONLY ) <EOL> headers = ts . hdrFromFdno ( fdno ) <EOL> os . close ( fdno ) <EOL> if not group : <EOL> group = self . get_artifact_group ( headers [ '<STR_LIT:url>' ] ) <EOL> artifact = headers [ '<STR_LIT:name>' ] <EOL> version = '<STR_LIT>' . format ( v = headers [ '<STR_LIT:version>' ] , r = headers [ '<STR_LIT>' ] ) <EOL> super ( LocalRpmArtifact , self ) . __init__ ( group = group , artifact = artifact , version = version , local_path = local_path ) <EOL> class RemoteArtifact ( Artifact ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , group = None , artifact = '<STR_LIT>' , version = '<STR_LIT>' , classifier = '<STR_LIT>' , extension = '<STR_LIT>' , url = None , repo_id = None ) : <EOL> super ( RemoteArtifact , self ) . __init__ ( group = group , artifact = artifact , version = version , classifier = classifier , <EOL> extension = extension ) <EOL> self . repo_id = repo_id <EOL> self . url = url <EOL> @ classmethod <EOL> def from_repo_id_and_coordinates ( cls , repo_id , coordinates ) : <EOL> """<STR_LIT>""" <EOL> fields = coordinates . split ( '<STR_LIT::>' ) <EOL> if len ( fields ) < <NUM_LIT:3> : <EOL> raise ArtifactError ( '<STR_LIT>' ) <EOL> group , artifact , version = fields [ <NUM_LIT:0> ] , fields [ <NUM_LIT:1> ] , fields [ <NUM_LIT:2> ] <EOL> classifier = extension = '<STR_LIT>' <EOL> if len ( fields ) > <NUM_LIT:3> : <EOL> classifier = fields [ <NUM_LIT:3> ] <EOL> if len ( fields ) > <NUM_LIT:4> : <EOL> extension = fields [ <NUM_LIT:4> ] <EOL> return cls ( group = group , artifact = artifact , version = version , classifier = classifier , extension = extension , <EOL> repo_id = repo_id ) </s>
