Changeset 276:080785bf7633 in hatta-dev


Ignore:
Timestamp:
02/01/09 01:12:57 (3 years ago)
Author:
sheep@…
Branch:
default
Message:

License, more comments

Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • hatta.py

    r274 r276  
    11#!/usr/bin/python 
    22# -*- coding: utf-8 -*- 
     3 
     4# @copyright: 2008-2009 Radomir Dopieralski <hatta@sheep.art.pl> 
     5# @license: GNU GPL, see COPYING for details. 
    36 
    47""" 
     
    176179 
    177180    def _parse_environ(self): 
     181        """Check the environment variables for options.""" 
     182 
    178183        prefix = 'HATTA_' 
    179184        settings = {} 
     
    185190 
    186191    def _parse_args(self): 
     192        """Check the commandline arguments for options.""" 
     193 
    187194        import optparse 
    188195        parser = optparse.OptionParser() 
     
    222229 
    223230    def _parse_files(self, files=()): 
     231        """Check the config files for options.""" 
     232 
    224233        import ConfigParser 
     234        # XXX TODO 
    225235 
    226236class WikiStorage(object): 
     
    262272 
    263273    def _find_repo_path(self, path): 
     274        """Go up the directory tree looking for a repository.""" 
     275 
    264276        while not os.path.isdir(os.path.join(path, ".hg")): 
    265277            old_path, path = path, os.path.dirname(path) 
     
    281293 
    282294    def save_file(self, title, file_name, author=u'', comment=u'', parent=None): 
     295        """Save an existing file as specified page.""" 
     296 
    283297        user = author.encode('utf-8') or _(u'anon').encode('utf-8') 
    284298        text = comment.encode('utf-8') or _(u'comment').encode('utf-8') 
     
    331345 
    332346    def save_text(self, title, text, author=u'', comment=u'', parent=None): 
     347        """Save text or data as specified page.""" 
     348 
    333349        try: 
    334350            temp_path = tempfile.mkdtemp(dir=self.path) 
     
    372388 
    373389    def page_file_meta(self, title): 
     390        """Get page's inode number, size and last modification time.""" 
     391 
    374392        try: 
    375393            (st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, 
     
    380398 
    381399    def page_meta(self, title): 
     400        """Get page's revision, date, last editor and his edit comment.""" 
     401 
    382402        filectx_tip = self._find_filectx(title) 
    383403        if filectx_tip is None: 
     
    398418 
    399419    def page_mime(self, title): 
     420        """Guess page's mime type ased on corresponding file name.""" 
     421 
    400422        file_path = self._file_path(title) 
    401423        return page_mime(file_path) 
    402424 
    403425    def _find_filectx(self, title): 
     426        """Find the last revision in which the file existed.""" 
     427 
    404428        repo_file = self._title_to_file(title) 
    405429        changectx = self.repo.changectx('tip') 
     
    415439 
    416440    def page_history(self, title): 
     441        """Iterate over the page's history.""" 
     442 
    417443        filectx_tip = self._find_filectx(title) 
    418444        if filectx_tip is None: 
     
    429455 
    430456    def page_revision(self, title, rev): 
     457        """Get the contents of specified revision of the page.""" 
     458 
    431459        filectx_tip = self._find_filectx(title) 
    432460        if filectx_tip is None: 
     
    438466 
    439467    def history(self): 
     468        """Iterate over the history of entire wiki.""" 
     469 
    440470        changectx = self.repo.changectx('tip') 
    441471        maxrev = changectx.rev() 
     
    457487 
    458488    def all_pages(self): 
     489        """Iterate over the titles of all pages in the wiki.""" 
     490 
    459491        for filename in os.listdir(self.path): 
    460492            if (os.path.isfile(os.path.join(self.path, filename)) 
     
    748780 
    749781    def parse_line(self, line): 
     782        """Find all the line-level markup and return HTML for it.""" 
     783 
    750784        for m in self.markup_re.finditer(line): 
    751785            func = getattr(self, "line_%s" % m.lastgroup) 
     
    754788    def parse(self, lines, wiki_link, wiki_image, wiki_syntax=None, 
    755789              wiki_math=None): 
     790        """Parse a list of lines of wiki markup, yielding HTML for it.""" 
     791 
    756792        def key(line): 
    757793            match = self.block_re.match(line) 
     
    844880 
    845881    def split_text(self, text): 
     882        """Split text into words. Uses Japanese splitter if available.""" 
     883 
    846884        for match in self.word_pattern.finditer(text): 
    847885            word = match.group(0) 
     
    861899 
    862900    def filter_words(self, words): 
     901        """Filter out stop words, numbers, too long words, etc.""" 
    863902        for word in words: 
    864903            if len(word) >= 25: 
     
    870909 
    871910    def count_words(self, words): 
     911        """Check how many times each word appears in the list.""" 
     912 
    872913        count = {} 
    873914        for word in words: 
     
    876917 
    877918    def add_words(self, title, text): 
     919        """Add words to the word index for specified page.""" 
     920 
    878921        encoded_title = title.encode('utf-8', 'backslashreplace') 
    879922        if text: 
     
    896939 
    897940    def add_links(self, title, links_and_labels): 
     941        """Add links to the link index for specified page.""" 
     942 
    898943        links, labels = links_and_labels 
    899944        self.links.sync() 
     
    905950 
    906951    def regenerate_backlinks(self): 
     952        """Create backlinks indices based on the links indices.""" 
     953 
    907954        self.links.sync() 
    908955        for key in self.backlinks: 
     
    918965 
    919966    def update_backlinks(self, title, old_links, new_links): 
     967        """Updates backlinks index for specified page.""" 
     968 
    920969        encoded_title = title.encode('utf-8', 'backslashreplace') 
    921970        self.backlinks.sync() 
     
    938987 
    939988    def page_backlinks(self, title): 
     989        """Get the backlinks to specified page.""" 
     990 
    940991        timestamp = os.stat(self.backlinks_file).st_mtime 
    941992        if timestamp > self.backlinks_timestamp: 
     
    947998 
    948999    def page_links(self, title): 
     1000        """Get link targets from specified page.""" 
     1001 
    9491002        timestamp = os.stat(self.links_file).st_mtime 
    9501003        if timestamp > self.links_timestamp: 
     
    9551008 
    9561009    def page_labels(self, title): 
     1010        """Get link labels from specified page.""" 
     1011 
    9571012        encoded_title = title.encode('utf-8', 'backslashreplace') 
    9581013        return self.labels.get(encoded_title, []) 
    9591014 
    9601015    def find(self, words): 
     1016        """Find words in the pages.""" 
     1017 
    9611018        first = words[0] 
    9621019        rest = words[1:] 
     
    10081065 
    10091066    def wiki_link(self, addr, label, class_='wiki', image=None): 
     1067        """Create HTML for a wiki link.""" 
     1068 
    10101069        text = werkzeug.escape(label) 
    10111070        if external_link(addr): 
     
    10351094 
    10361095    def wiki_image(self, addr, alt, class_='wiki'): 
     1096        """Create HTML for a wiki image.""" 
     1097 
    10371098        chunk = '' 
    10381099        if external_link(addr): 
     
    10561117 
    10571118    def get_author(self): 
     1119        """Try to guess the author name. Use IP address as last resort.""" 
     1120 
    10581121        author = (self.form.get("author") 
    10591122                  or werkzeug.url_unquote(self.cookies.get("author", "")) 
     
    10631126 
    10641127    def _get_file_stream(self): 
     1128        """Save all the POSTs to temporary files.""" 
     1129 
    10651130        class FileWrapper(file): 
    10661131            def __init__(self, f): 
     
    10881153 
    10891154    def cleanup(self): 
     1155        """Clean up the temporary files created by POSTs.""" 
     1156 
    10901157        for temp_path in self.tmpfiles: 
    10911158            try: 
     
    11691236 
    11701237    def html_page(self, request, title, content, page_title=u''): 
     1238        """The main page template.""" 
     1239 
    11711240        rss = request.adapter.build(self.rss, method='GET') 
    11721241        atom = request.adapter.build(self.atom, method='GET') 
Note: See TracChangeset for help on using the changeset viewer.