| 1 |
# Copyright (c) 2006-2011 Shaun McCance <shaunm@gnome.org> |
| 2 |
# |
| 3 |
# This file is part of Blip, a program for displaying various statistics |
| 4 |
# of questionable relevance about software and the people who make it. |
| 5 |
# |
| 6 |
# Blip is free software; you can redistribute it and/or modify it under the |
| 7 |
# terms of the GNU General Public License as published by the Free Software |
| 8 |
# Foundation; either version 2 of the License, or (at your option) any later |
| 9 |
# version. |
| 10 |
# |
| 11 |
# Blip is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 13 |
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 14 |
# details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License along |
| 17 |
# with Blip; if not, write to the Free Software Foundation, 59 Temple Place, |
| 18 |
# Suite 330, Boston, MA 0211-1307 USA. |
| 19 |
# |
| 20 |
|
| 21 |
import datetime |
| 22 |
import re |
| 23 |
import os |
| 24 |
|
| 25 |
import blip.db |
| 26 |
import blip.utils |
| 27 |
|
| 28 |
import blip.parsers |
| 29 |
import blip.parsers.automake |
| 30 |
|
| 31 |
import blip.plugins.modules.sweep |
| 32 |
|
| 33 |
class QuickRefScanner (blip.plugins.modules.sweep.ModuleFileScanner): |
| 34 |
def __init__ (self, scanner): |
| 35 |
self.document = None |
| 36 |
blip.plugins.modules.sweep.ModuleFileScanner.__init__ (self, scanner) |
| 37 |
|
| 38 |
def process_file (self, dirname, basename): |
| 39 |
""" |
| 40 |
Process a Makefile.am file for the Evolution Quick Reference Card. |
| 41 |
""" |
| 42 |
branch = self.scanner.branch |
| 43 |
is_quickref = False |
| 44 |
if branch.scm_server == 'git://git.gnome.org/' and branch.scm_module == 'evolution': |
| 45 |
if basename == 'Makefile.am': |
| 46 |
if os.path.join (self.scanner.repository.directory, 'help/quickref') == dirname: |
| 47 |
is_quickref = True |
| 48 |
if not is_quickref: |
| 49 |
return |
| 50 |
|
| 51 |
filename = os.path.join (dirname, basename) |
| 52 |
rel_ch = blip.utils.relative_path (os.path.join (dirname, filename), |
| 53 |
self.scanner.repository.directory) |
| 54 |
bserver, bmodule, bbranch = branch.ident.split('/')[2:] |
| 55 |
|
| 56 |
with blip.db.Timestamp.stamped (filename, self.scanner.repository) as stamp: |
| 57 |
try: |
| 58 |
stamp.check (self.scanner.request.get_tool_option ('timestamps')) |
| 59 |
except: |
| 60 |
data = {'parent' : branch} |
| 61 |
scm_dir, scm_file = os.path.split (rel_ch) |
| 62 |
data['scm_dir'] = os.path.join (scm_dir, 'C') |
| 63 |
doc = blip.db.Branch.select_one (type=u'Document', **data) |
| 64 |
if doc is not None: |
| 65 |
self.scanner.add_child (doc) |
| 66 |
self.document = doc |
| 67 |
raise |
| 68 |
|
| 69 |
stamp.log () |
| 70 |
makefile = blip.parsers.get_parsed_file (blip.parsers.automake.Automake, |
| 71 |
self.scanner.branch, filename) |
| 72 |
|
| 73 |
ident = u'/'.join(['/doc', bserver, bmodule, 'quickref', bbranch]) |
| 74 |
document = blip.db.Branch.get_or_create (ident, u'Document') |
| 75 |
document.parent = branch |
| 76 |
|
| 77 |
for key in ('scm_type', 'scm_server', 'scm_module', 'scm_branch', 'scm_path'): |
| 78 |
setattr (document, key, getattr (branch, key)) |
| 79 |
document.subtype = u'evolutionquickref' |
| 80 |
document.scm_dir = blip.utils.relative_path (os.path.join (dirname, u'C'), |
| 81 |
self.scanner.repository.directory) |
| 82 |
document.scm_file = u'quickref.tex' |
| 83 |
|
| 84 |
self.scanner.add_child (document) |
| 85 |
self.document = document |
| 86 |
|
| 87 |
translations = [] |
| 88 |
for lang in makefile['SUBDIRS'].split(): |
| 89 |
if lang == 'C': |
| 90 |
continue |
| 91 |
lident = u'/l10n/' + lang + document.ident |
| 92 |
translation = blip.db.Branch.get_or_create (lident, u'Translation') |
| 93 |
translations.append (translation) |
| 94 |
for key in ('scm_type', 'scm_server', 'scm_module', 'scm_branch', 'scm_path'): |
| 95 |
setattr (translation, key, getattr (document, key)) |
| 96 |
translation.scm_dir = blip.utils.relative_path (os.path.join (dirname, lang), |
| 97 |
self.scanner.repository.directory) |
| 98 |
translation.scm_file = u'quickref.tex' |
| 99 |
translation.parent = document |
| 100 |
document.set_children (u'Translation', translations) |
| 101 |
|
| 102 |
def post_process (self): |
| 103 |
if self.document is None: |
| 104 |
return |
| 105 |
regexp = re.compile ('\\s*\\\\textbf{\\\\Huge{(.*)}}') |
| 106 |
filename = os.path.join (self.scanner.repository.directory, |
| 107 |
self.document.scm_dir, self.document.scm_file) |
| 108 |
with blip.db.Timestamp.stamped (filename, self.scanner.repository) as stamp: |
| 109 |
stamp.check (self.scanner.request.get_tool_option ('timestamps')) |
| 110 |
stamp.log () |
| 111 |
for line in open(filename): |
| 112 |
match = regexp.match (line) |
| 113 |
if match: |
| 114 |
self.document.name = blip.utils.utf8dec (match.group(1)) |
| 115 |
break |
| 116 |
rev = blip.db.Revision.get_last_revision (branch=self.document.parent, |
| 117 |
files=[os.path.join (self.document.scm_dir, |
| 118 |
self.document.scm_file)]) |
| 119 |
if rev is not None: |
| 120 |
self.document.mod_datetime = rev.datetime |
| 121 |
self.document.mod_person = rev.person |
| 122 |
self.document.updated = datetime.datetime.utcnow () |
| 123 |
|
| 124 |
for translation in blip.db.Branch.select (type=u'Translation', parent=self.document): |
| 125 |
rev = blip.db.Revision.get_last_revision (branch=self.document.parent, |
| 126 |
files=[os.path.join (translation.scm_dir, |
| 127 |
translation.scm_file)]) |
| 128 |
if rev is not None: |
| 129 |
translation.mod_datetime = rev.datetime |
| 130 |
translation.mod_person = rev.person |
| 131 |
translation.updated = datetime.datetime.utcnow() |