def date_get_latest_stored(folder, pattern): """Given the folder to look in and the URL pattern, return the latest stored strip's date.""" # Determine the pattern the files will be named with name_pattern = get_filename(pattern) # Build the matcher regex name_re = '^'+name_pattern+'$' for rep in [('%y', '([0-9]{4})'), ('%4y', '([0-9]{4})'), ('%2y', '([0-9]{2})'), ('%m', '([0-9]{2})'), ('%d', '([0-9]{2})'), ('.', '\\.')]: name_re = name_re.replace(rep[0], rep[1]) # Build the replacer regex name_sub = '' # TODO: Figure out how to grab values from the sub()ed results # Get a list of all the files downloaded thus far file_list = os.listdir(folder) # Sort them so the latest ones are first file_list.sort(reverse=True) # Determine the latest file's name latest = None for f in file_list: if None != re.matches(name_re): latest = f break if latest == None: print('Found no matching webcomic images!') return False else: # TODO: Parse the filename into a date object pass
def test_004_me_can_register_image_within_instance(self): conn = self.connect_ssh(data['my_private_ip'], 'mykey') stdin, stdout = conn.exec_command('python ~/smoketests/register-image.py') conn.close() if re.matches('emi-{\w+}', stdout): data['my_image_id'] = stdout.strip() else: self.fail('expected emi-nnnnnn, got:\n ' + stdout)
def assert_response(resp, contains=None, matches=None, headers=None, status=200): assert status in resp.status, "Expected response %r not in %r" %(status, resp.status) if status == "200": assert resp.data, "Response data is empty." if contains: assert contains in resp.data, "Response does not contain %r" % contains reg = re.compile(matches) assert re.matches(resp.data), "Response does not match %r" % matches if headers: assert_equal(resp.headers, headers)
def get_inputs_for_model_paths(model_paths, pattern=None): edge_files = [] image_files = [] for model_path in model_paths: model_name = os.path.basename(model_path) for orientation in range(_ORIENTATIONS_PER_MODEL): edges_file_path = '%s/screenshots/%s-%d_thumb_padded.bin' % ( model_path, model_name, orientation) image_file_path = '%s/screenshots/%s-%d_thumb_padded.png' % ( model_path, model_name, orientation) if not pattern or re.matches(image_file_path): edge_files.append(edges_file_path) image_files.append(image_file_path) orientations = list(range(_ORIENTATIONS_PER_MODEL)) * len(model_paths) return edge_files, image_files, orientations
def make_app(name, slug=None, config=FormConfig() ): """a decorator that turns a class into a form app""" re.compile(r'[a-zA-Z0-9 ]*') if not re.matches(name) raise Exception('App names must be made only ' 'of spaces, and alphanumerical chars') if slug is None: slug = name.replace(' ', '_') approot = os.path.join(config['appsroot'], slug) if not os.path.isdir(approot): raise FileNotFoundError('app root does not ' 'exist') appdir = path.join(approot, slug) os.mkdir(appdir) def decorator(cls, name=name, # these default arguments are here # to bind objects from the current scope to the # decorator slug=slug, config=config): """class decorator, that generates the app frontend""" form = FormApp(cls, name, slug, config) form.render() return cls return decorator
"""Matching vs. searching """ #end_pymotw_header import re text = 'This is some text -- with punctuation.' pattern = '.+ is.*' print 'Text :', text print 'Pattern:', pattern m = re.match(pattern, text) print dir(m) print 'Match :', m s = re.search(pattern, text) print 'Search :', s text = "id integer default 'abc'" pattern = ".+ DEFAULT\\s+(.+)" if re.matches(".+ DEFAULT\\s+.+", text): # if re.matches(".+ DEFAULT\\s+\".+\""): pass # else: query_pattern = re.compile(pattern) findall = query_pattern.findall(text.upper()) print str(findall[0])