def __init__(self, env, req, file): from trac.versioncontrol import RepositoryManager from trac.versioncontrol.web_ui import get_existing_node if hasattr(RepositoryManager, 'get_repository_by_path'): # Trac 0.12 repo, file = RepositoryManager(env).get_repository_by_path(file)[1:3] else: repo = RepositoryManager(env).get_repository(req.authname) obj = get_existing_node(req, repo, file, None) TransformSource.__init__(self, "browser", "source", file, obj)
def __init__(self, env, hdf, file): from trac.versioncontrol.web_ui import get_existing_node repos = env.get_repository(hdf.get('trac.authname')) obj = get_existing_node(env, repos, file, None) TransformSource.__init__(self, "browser", "source", file, obj)
def parse_trac(self,filespec): """ Parse arguments like in the ImageMacro (trac/wiki/macros.py) """ parts = filespec.split(':') url = raw_url = None attachment = None if len(parts) == 3: # realm:id:attachment-filename realm, id, filename = parts attachment = Resource(realm, id).child('attachment', filename) elif len(parts) == 2: # TODO howto Access the Subversion / Browser ... # FIXME: somehow use ResourceSystem.get_known_realms() # ... or directly trac.wiki.extract_link from trac.versioncontrol.web_ui import BrowserModule try: browser_links = [res[0] for res in BrowserModule(self.env).get_link_resolvers()] except Exception: browser_links = [] # TODO what to do with browserlinks... if parts[0] in browser_links: # source:path ## ['repos', 'export', 'source', 'browser'] # TODO: use context here as well realm, filename = parts rev = None if '@' in filename: filename, rev = filename.split('@') url = self.formatter.href.browser(filename, rev=rev) raw_url = self.formatter.href.browser(filename, rev=rev, format='raw') from trac.versioncontrol.web_ui import get_existing_node from trac.versioncontrol import RepositoryManager if hasattr(RepositoryManager, 'get_repository_by_path'): # Trac 0.12 repo = RepositoryManager(self.env).get_repository_by_path(file)[1:3] else: repo = RepositoryManager(self.env).get_repository(self.formatter.req.authname) obj = get_existing_node(self.formatter.req, repo, filename, rev) svn_core_stream=obj.get_content() # write file to filesystem (needed for convert imgname="%s/%s" %(self.images_folder,self.filenamehash) f = open( imgname , 'w+') f.write( svn_core_stream.read() ) f.close() # set standard properties # SVN is always cache because it may change... self.cache = False self.pdfinput = imgname self.url=url self.rawurl=raw_url self.wikilink=filespec return # else: # #ticket:attachment or WikiPage:attachment else : # #ticket:attachment or WikiPage:attachment # FIXME: do something generic about shorthand forms... realm = None id, filename = parts if id and id[0] == '#': realm = 'ticket' id = id[1:] else: realm = 'wiki' if realm: attachment = Resource(realm, id).child('attachment', filename) elif len(parts) == 1: # it's an attachment of the current resource attachment = self.formatter.resource.child('attachment', filespec) else: raise TracError('No filespec given') if attachment and 'ATTACHMENT_VIEW' in self.formatter.perm(attachment): url = get_resource_url(self.env, attachment, self.formatter.href) raw_url = get_resource_url(self.env, attachment, self.formatter.href, format='raw') self.wikilink=filespec self.url=url self.rawurl=raw_url self.pdfinput=( Attachment(self.env,attachment) ).path self.env.log.debug("PdfImg..trac-Attachment %r ***", self.pdfinput )