@@ -62,13 +62,40 @@ def run(self, options, args):
62
62
method = getattr (self , "action_%s" % args [0 ])
63
63
return method (options , args [1 :])
64
64
65
- def get_cache_location (self , cache_root , cache_type ):
65
+ @staticmethod
66
+ def get_cache_location (cache_root , cache_type ):
66
67
location = cache_root
67
68
suffix = {"wheel" : "wheels" , "http" : "http" }
68
69
if cache_type != "all" :
69
70
location = os .path .join (location , suffix [cache_type ])
70
71
return location
71
72
73
+ @staticmethod
74
+ def wheels_matching (cache_location , pattern ):
75
+ """Returns a list of absolute filenames of wheels with filenames
76
+ matching `pattern`. A pattern may be:
77
+ * the name of a package
78
+ * a shell glob expression matching the basename of the wheel
79
+ * an exact basename
80
+ """
81
+ shell_metachars = '*?'
82
+ if (any (m in pattern for m in shell_metachars ) or
83
+ pattern .endswith (".whl" )):
84
+ matches = find_files (cache_location , pattern )
85
+ matches = fnmatch .filter (matches , "*.whl" )
86
+ else :
87
+ wheels = find_files (cache_location , "*.whl" )
88
+ pkgname = safe_name (pattern ).lower ()
89
+ matches = []
90
+ for filename in wheels :
91
+ try :
92
+ wheel = Wheel (basename (filename ))
93
+ except InvalidWheelFilename :
94
+ continue
95
+ if wheel .name .lower () == pkgname :
96
+ matches .append (filename )
97
+ return matches
98
+
72
99
def action_info (self , options , args ):
73
100
caches = ["http" , "wheel" ] if options .type == "all" else [options .type ]
74
101
result = []
@@ -108,26 +135,10 @@ def action_rm(self, options, args):
108
135
"Must specify the filename of (a) wheel(s) to remove." )
109
136
cache_location = self .get_cache_location (options .cache_dir , "wheel" )
110
137
value = SUCCESS
111
- shell_metachars = '*?'
112
- for target in args :
113
- if (any (m in target for m in shell_metachars ) or
114
- target .endswith (".whl" )):
115
- matches = find_files (cache_location , target )
116
- matches = fnmatch .filter (matches , "*.whl" )
117
- else :
118
- wheels = find_files (cache_location , "*.whl" )
119
- pkgname = safe_name (target ).lower ()
120
- matches = []
121
- for filename in wheels :
122
- try :
123
- wheel = Wheel (basename (filename ))
124
- except InvalidWheelFilename :
125
- continue
126
- if wheel .name .lower () == pkgname :
127
- matches .append (filename )
128
-
138
+ for pattern in args :
139
+ matches = self .wheels_matching (cache_location , pattern )
129
140
if not matches :
130
- logger .info ("No match found for %s" % target )
141
+ logger .info ("No match found for %s" % pattern )
131
142
continue
132
143
for match in matches :
133
144
try :
0 commit comments