Exemple #1
0
def parsefile(fname,encoding='utf-8'):
  helper.openfile(fname)
  s= fname.read()
  db= parsedata(s)
#   db= parsedata(unicode(s,encoding=encoding))
  helper.closefile(fname)
  return db
Exemple #2
0
def parsefile(fname, encoding="utf-8"):
    helper.openfile(fname)
    s = fname.read()
    db = parsedata(s)
    #   db= parsedata(unicode(s,encoding=encoding))
    helper.closefile(fname)
    return db
Exemple #3
0
 def dump(self, fname, protocol=pickle.HIGHEST_PROTOCOL):
   '''
   Store the biblist in file "fname" using the standard cPickle module.
   It can be used uncompressed or compressed with gzip or bzip
   '''
   # if not '.dmp' in fname: fname='%s.dmp' %(fname)
   try:
     fo=helper.openfile(fname,'wb');  pickle.dump(self,fo,protocol=pickle.HIGHEST_PROTOCOL);
     helper.closefile(fo)
   except:
     raise ValueError, 'Error loading data'
Exemple #4
0
 def dump(self, fname, protocol=pickle.HIGHEST_PROTOCOL):
   '''
   Store the biblist in file "fname" using the standard cPickle module.
   It can be used uncompressed or compressed with gzip or bzip
   '''
   # if not '.dmp' in fname: fname='%s.dmp' %(fname)
   try:
     fo=helper.openfile(fname,'wb');  pickle.dump(self,fo,protocol=pickle.HIGHEST_PROTOCOL);
     helper.closefile(fo)
   except:
     raise ValueError, 'Error loading data'
Exemple #5
0
 def load(self, fname):
   '''
   Load a biblist from file "fname" using the standard cPickle module.
   It can be used uncompressed or compressed with gzip or bzip
   '''
   try:
     fi= helper.openfile(fname,'rb');  c= pickle.load(fi);  helper.closefile(fi)
   except: 
     raise ValueError, 'Error loading data'
   try:    self.update(c)
   except: raise ValueError, 'Error updating data'
Exemple #6
0
 def load(self, fname):
   '''
   Load a biblist from file "fname" using the standard cPickle module.
   It can be used uncompressed or compressed with gzip or bzip
   '''
   try:
     fi= helper.openfile(fname,'rb');  c= pickle.load(fi);  helper.closefile(fi)
   except: 
     raise ValueError, 'Error loading data'
   try:    self.update(c)
   except: raise ValueError, 'Error updating data'
Exemple #7
0
  def export_latex(self, fname=None, style={}, head=None,tail=None):
    """
    Export a bibliography (set of items) to a file in latex format:
    """
    if head == None:
      head= r'''\documentclass[12pt]{article}
\newcommand{\authors}[1]{#1}
\usepackage{hyperref}
\begin{document}
\begin{enumerate}
'''
    if tail== None:
      tail= r'\end{enumerate} \end{document}'
    s= '%s\n%s\n%s\n'%(head, self.to_latex(style=style).encode('latex'), tail)
    fi= helper.openfile(fname,'w');  fi.write(s);  helper.closefile(fi)
Exemple #8
0
  def export_latex(self, fname=None, style={}, label = r'\item', head=None,tail=None):
    """
    Export a bibliography (set of items) to a file in latex format:
    """
    if head == None:
      head= r'''\documentclass[12pt]{article}
\newcommand{\authors}[1]{#1}
\usepackage{hyperref}
\begin{document}
\begin{enumerate}
'''
    if tail== None:
      tail= r'\end{enumerate} \end{document}'
    s= '%s\n%s\n%s\n'%(head, self.to_latex(style=style, label = label).encode('latex'), tail)
    fi= helper.openfile(fname,'w');  fi.write(s);  helper.closefile(fi)
Exemple #9
0
  def export_xml(self, fname=None, prefix='', head='', tail='', indent=2):
    """
    Export a bibliography (set of items) to a file in xml format:
    A prefix may be added to account for a namespace. But if added both head and tail
    should take it into account to make it a valid xml document
    """
    if head == '':
      head='''<?xml version="1.0" encoding="utf-8"?>
  <''' + prefix +'''bibliography>
'''
    if tail == '':
      tail="\n</"+prefix+"bibliography>"
      
    s= head + self.to_xml(prefix=prefix) + tail
    fi= helper.openfile(fname,'w');  fi.write(s.encode('utf-8','xmlcharrefreplace'))
    helper.closefile(fi)
Exemple #10
0
  def export_xml(self, fname=None, prefix='', head='', tail='', indent=2):
    """
    Export a bibliography (set of items) to a file in xml format:
    A prefix may be added to account for a namespace. But if added both head and tail
    should take it into account to make it a valid xml document
    """
    if head == '':
      head='''<?xml version="1.0" encoding="utf-8"?>
  <''' + prefix +'''bibliography>
'''
    if tail == '':
      tail="\n</"+prefix+"bibliography>"
      
    s= head + self.to_xml(prefix=prefix) + tail
    fi= helper.openfile(fname,'w');  fi.write(s.encode('utf-8','xmlcharrefreplace'))
    helper.closefile(fi)
Exemple #11
0
  def output(self, fout=None, formato='short', verbose=True):
    """
    Export all entries to a fout file with default options. All strings are resolved.
    following formats are defined:
    short (default)
    long
    bibtex
    latex
    html
    xml
    """

    if verbose:
      print '# %d items to output' %(len(self.ListItems))

    if formato == 'bibtex':  self.export_bibtex(fout)
    elif formato == 'latex' :  self.export_latex(fout)
    elif formato == 'html'  :  self.export_html(fout)
    elif formato == 'xml'   :  self.export_xml(fout)
    else:
      fi= helper.openfile(fout,'w')
      if formato   == 'long'  :   fi.write(str(self))
      else:  fi.write(self.preview().encode(self.encoding))
      helper.closefile(fi)
Exemple #12
0
 def write_short(fout):
   fi= helper.openfile(fout,'w'); fi.write(self.preview().encode(self.encoding))
   helper.closefile(fi)
Exemple #13
0
 def write_full(fout):
   fi= helper.openfile(fout,'w'); fi.write(str(self)); helper.closefile(fi)
Exemple #14
0
  def export_html(self, fname=None, style={}, head='',tail='', separate_css='biblio.css', css_style=None, encoding='utf-8'):
    """
    Export a bibliography (set of items) to a file in bibtex format: style is a dictionary
    (like in bibitem objects) where the values is a pair (open,close) to insert around the
    data.
    head and tail are html code to insert before and after the list of publications
    separate_css may have the
    """
    # default style
    def_css_style="""
.title a,
.title {font-weight: bold;	color :    #416DFF; }
ol.bibliography li{	margin-bottom:0.5em;}
.journal {  font-style: italic;}
.book .series {  font-style: italic;}
.journal:after {content:" ";}
.series:after {content:" ";}
li.article .publisher {display:none;}
.publisher:before {content:" (";}
.publisher:after {content:") ";}
.year:before {content:" (";}
.year:after {content:").";}
.authors {font-weight:bold; display:list;}
.authors:after {content:". ";}
.volume { font-weight: bold;}
.book .volume: before { content: "Vol. ";}
.number:before {content:":";}
.button {display:inline; border: 3px ridge;line-height:2.2em;margin: 0pt 10pt 0pt 0pt;padding:1pt;}
.masterthesis:before{font-weight: bold;content:"Master Thesis"}
.phdthesis:before{font-weight: bold;content:"Phd Thesis"}
div.abstracts {display: inline; font-weight: bold; text-decoration : none;  border: 3px ridge;}
div.abstract {display: none;padding: 0em 1% 0em 1%; border: 3px double rgb(130,100,110); text-align: justify;} 
    """
    if css_style == None:  css_style= def_css_style

    if helper.is_string_like(separate_css):
      the_path, fname_css= os.path.split(separate_css)
      fpath= os.path.dirname(fname)
      the_path= os.path.normpath(os.path.join(fpath,the_path))
      fname_css= os.path.join(the_path,fname_css)
      css='  <link title="new" rel="stylesheet" href="' + separate_css + '" type="text/css">'
      fi=helper.openfile(fname_css,'w');  fi.write(css_style);  helper.closefile(fi)
    else:
      css= '<style type="text/css">' +css_style + '</style>'

    if head=='':
      head='''
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset='''+encoding.upper()+'''">
    ''' +  css + '''
    <title>Publicaciones</title>
    <script language="JavaScript" type="text/javascript">
    //<![CDATA[
    function toggle(thisid) {
    var thislayer=document.getElementById(thisid);
    if (thislayer.style.display == 'block') {
    thislayer.style.display='none';
    } else {
    thislayer.style.display='block';}
    }
    //]]>
    </script>
    </head>
    <body>
    <h2>Publicaciones</h2>
    <ol class="bibliography">
    '''
    if tail == '':
      tail="""
      </ol>
      </body>
      </html>
      """
      
    s= head + self.to_html(style=style) + tail
    fi= helper.openfile(fname,'w');  fi.write(s.encode(encoding,'xmlcharrefreplace'))
    helper.closefile(fi)
Exemple #15
0
 def export_bibtex(self, fname=None,indent=2, width=80, fields=None, encoding='latex'):
   """
   Export a bibliography (set of items) to a file in bibtex format:
   """
   fi= helper.openfile(fname,'w');  fi.write(self.to_bibtex(indent, width, fields, encoding=encoding));
   helper.closefile(fi)
Exemple #16
0
 def export_bibtex(self, fname=None,indent=2, width=80):
   """
   Export a bibliography (set of items) to a file in bibtex format:
   """
   fi= helper.openfile(fname,'w');  fi.write(self.to_bibtex(width));  helper.closefile(fi)
Exemple #17
0
  def export_html(self, fname=None, style={}, head='',tail='', separate_css=None,encoding='utf-8'):
    """
    Export a bibliography (set of items) to a file in bibtex format: style is a dictionary
    (like in bibitem objects) where the values is a pair (open,close) to insert around the
    data.
    head and tail are html code to insert before and after the list of publications
    separate_css may have the
    """
    # default style
    css_style="""
.title a,
.title {font-weight: bold;	color :    #416DFF; }
ol.bibliography li{	margin-bottom:0.5em;}
.journal {  font-style: italic;}
.book .series {  font-style: italic;}
.journal:after {content:" ";}
.series:after {content:" ";}
li.article .publisher {display:none;}
.publisher:before {content:" (";}
.publisher:after {content:") ";}
.year:before {content:" (";}
.year:after {content:").";}
.authors {font-weight:bol; display:list;}
.authors:after {content:". ";}
.volume { font-weight: bold;}
.book .volume: before { content: "Vol. ";}
.number:before {content:":";}
.button {display:inline; border: 3px ridge;line-height:2.2em;margin: 0pt 10pt 0pt 0pt;padding:1pt;}
.masterthesis{content:"Master Thesis"}
.phdthesis{content:"Phd Thesis"}
div.abstracts {display: inline; font-weight: bold; text-decoration : none;  border: 3px ridge;}
div.abstract {display: none;padding: 0em 1% 0em 1%; border: 3px double rgb(130,100,110); text-align: justify;} 
    """

    if helper.is_string_like(separate_css):
      fi=helper.openfile(separate_css,'w');  fi.write(css_style);  helper.closefile(fi)
      name= os.path.commonprefix([os.path.dirname(fname),os.path.dirname(separate_css)])
      name= os.path.join(name,separate_css[len(name):])
      css='  <link title="new" rel="stylesheet" href="' + name + '" type="text/css">'
    else:
      css= '<style type="text/css">' +css_style + '</style>'

    if head=='':
      head='''
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset='''+encoding.upper()+'''">
    ''' +  css + '''
    <title>Bibliography</title>
    <script language="JavaScript" type="text/javascript">
    //<![CDATA[
    function toggle(thisid) {
    var thislayer=document.getElementById(thisid);
    if (thislayer.style.display == 'block') {
    thislayer.style.display='none';
    } else {
    thislayer.style.display='block';}
    }
    //]]>
    </script>
    </head>
    <body>
    <h2>Bibliography</h2>
    <ol class="bibliography">
    '''
    if tail == '':
      tail="""
      </ol>
      </body>
      </html>
      """
      
    s= head + self.to_html(style=style) + tail
    fi= helper.openfile(fname,'w');  fi.write(s.encode(encoding,'xmlcharrefreplace'))
    helper.closefile(fi)
Exemple #18
0
def parsefile(fname=None):
  fi= helper.openfile(fname)
  s= fi.read()
  db= parsedata(s)
  return db
Exemple #19
0
def parsefile(fname=None):
    fi = helper.openfile(fname)
    s = fi.read()
    db = parsedata(s)
    return db