Modify

Opened 14 years ago

Closed 13 years ago

#7713 closed enhancement (fixed)

Allow loading of .bib file from htdocs

Reported by: pauld.mccarthy@… Owned by: Roman Mohr
Priority: normal Component: TracBibPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.11

Description

Being able to store and load a .bib file as a static resource from the htdocs/ directory is useful for me. I have a single .bib file, containing all the references for my work, which is under independent version control. With the patch below, I can simply create a symlink from htdocs to my .bib file, so I don't need to maintain a separate .bib file.

Using the patch as-is, to add a .bib file stored in $TRAC_ENV/htdocs/library.bib, you would type [[BibAdd(static:library.bib)]].

  • trunk/tracbib/tracbib.py

     
    5656from trac.wiki.formatter import WikiProcessor
    5757from trac.util.text import to_unicode
    5858
     59import os
    5960import re
    6061import bibtexparse
    6162
     
    186187          raise TracError('No code block on page \'' + whom[1] + '\' found.')
    187188      else:
    188189        raise TracError('No wiki page named \'' + whom[1] + '\' found.')
     190
     191    elif whom[0] == 'static':
     192
     193      if (len(whom) != 2):
     194        raise TracError('Wrong syntax for environment \'static\'; Usage BibAdd(static:/path/to/static/file)')
     195
     196      htdir = self.env.get_htdocs_dir()
     197      fdir = os.path.join(htdir,whom[1])
     198
     199      if not os.path.exists(fdir):
     200        raise TracError('Static resource %s does not exist')
     201      if not os.path.isfile(fdir):
     202        raise TracError('Static resource %s is not a file')
     203
     204      fd = open(fdir, 'rt')
     205      string = fd.read()
     206      fd.close()
     207
    189208    else:
    190209      raise TracError('Unknown location \''+ whom[0] +'\'')
    191210    try:

Attachments (0)

Change History (1)

comment:1 Changed 13 years ago by Roman Mohr

Resolution: fixed
Status: newclosed

Since r11553, as part of a full rewrite its now possible to load bibtex files from everywhere in the web.

Example:

[[BibAdd(http://www.example.site.com/bibtex.bib)

Its not exactly what you wanted, because I don't like the idea of hardcoding something for the symlink, but you can have the same effect by using the 'http' prefix and securing your file via your webserver.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Roman Mohr.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.