def find_url(wlib, url): """ @url - url to search for. String matching, no normalization. @return list of matched WebPages """ if util.isFileURL(url): # use a for flexible match rule to account for file name variations. ### TODO: NT specific? ### TODO: need optimize? scheme, netloc, url_path, _, _, _ = urlparse.urlparse(url) pathname = util.nt_url2pathname(url_path) pathname = os.path.normcase(pathname) result = [] for item in wlib.webpages: scheme, netloc, url_path, _, _, _ = urlparse.urlparse(item.url) if scheme != 'file': continue p1 = util.nt_url2pathname(url_path) p1 = os.path.normcase(p1) if pathname == p1: result.append(item) return result else: return [item for item in wlib.webpages if item.url == url]
def render(self, node, bean, tags): item = bean.item wlib = store.getWeblib() if item.id == -1: node.form_title.content %= 'Add Entry' node.edit_header.omit() else: node.form_title.content %= 'Edit Entry' node.add_header.omit() form = node.form id = item.id < 0 and '_' or str(item.id) form.atts['action'] = request.rid_url(id) if bean.errors: escaped_errors = map(saxutils.escape, bean.errors) form.error.message.raw = '<br />'.join(escaped_errors) else: form.error.omit() if item: form.name .atts['value'] = item.name form.created .atts['value'] = item.created form.url .atts['value'] = item.url form.description.content = item.description form.tags .atts['value'] = bean.item.tags_description form.nickname .atts['value'] = item.nickname if weblib_util.isFileURL(item.url): scheme, netloc, url_path, _, _, _ = urlparse.urlparse(item.url) pathname = weblib_util.nt_url2pathname(url_path) form.url_link.atts['href'] = '/weblib/%s/url#%s' % (item.id, item.url) form.filename.content = pathname else: form.url_link.atts['href'] = item.url form.filename.omit() # if item.modified: # form.modified_txt.content = item.modified # if item.fetched: # form.snapshot_txt.content = item.fetched tags_strings = [u' "%s"' % response.jsEscapeString(unicode(tag)) for tag in tags] node.form.tags_array.raw = node.form.tags_array.raw % ',\n'.join(tags_strings) new_tags = bean.newTags and u', '.join(bean.newTags) or '' encoded_tags = response.jsEscapeString(new_tags) node.form.new_tags_js_var.raw = node.form.new_tags_js_var.raw % encoded_tags # weblibForm get invoked from CGI weblib.py #if __name__ == "__main__": # main(sys.stdin, sys.stdout, os.environ)
def updateWebPage(page): """ Update the corresponding file's NTFS summary property. @returns - pathname if data is updated, None otherwise """ scheme, netloc, url_path, _, _, _ = urlparse.urlparse(page.url) assert scheme == 'file' p = path(util.nt_url2pathname(url_path)) category = ', '.join(map(unicode,page.tags)) # _writeProp() only work for read file # check this in advance to get friendlier error than the com_error if p.isfile(): try: _writeProp(p, page.name, page.description, category) return p except (pywintypes.com_error, AttributeError), e: # file locked? log.exception('Unable to write NTFS property: %s' % p) return None
def makeWebPage(file_url): """ Read the corresponding file's NTFS summary property and build a WebPage object. Fill with blank fields if can't read the properties. @returns - WebPage, tags (string) """ scheme, netloc, url_path, _, _, _ = urlparse.urlparse(file_url) assert scheme == 'file' p = path(util.nt_url2pathname(url_path)) props = None # _readProp() only work for read file # check this in advance to get friendlier error than the com_error if p.isfile(): try: props = _readProp(p) except pywintypes.com_error, e: # file locked? log.exception('Unable to read NTFS property: %s' % p)
def launch(file_url): scheme, netloc, url_path, _, _, _ = urlparse.urlparse(file_url) p = path(util.nt_url2pathname(url_path)) log.debug('Launching file: %s' % p) os.startfile(p)