~ubuntu-branches/ubuntu/gutsy/moin/gutsy

« back to all changes in this revision

Viewing changes to MoinMoin/scripts/import/IrcLogImporter.py

  • Committer: Bazaar Package Importer
  • Author(s): Sivan Greenberg
  • Date: 2006-07-09 19:28:02 UTC
  • Revision ID: james.westby@ubuntu.com-20060709192802-oaeuvt4v3e9300uj
Tags: 1.5.3-1ubuntu1
* Merge new debian version.
* Reapply Ubuntu changes:
    + debian/rules:
      - Comment out usage of control.ubuntu.in (doesn't fit!).
    + debian/control.in:
      - Dropped python2.3 binary package.
    + debian/control:
      - Dropped python2.3 binary, again.
      - Dropped python2.3-dev from Build-Depends-Indep.
    + debian/patches/001-attachment-xss-fix.patch:
      - Dropped this patch. It's now in upstream's distribution.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
"""
3
 
MoinMoin - Push files into the wiki.
4
 
 
5
 
This script pushes files from a directory into the wiki. It is usable in order
6
 
to mirror IRC logs for example.
7
 
 
8
 
    @copyright: 2005 by MoinMoin:AlexanderSchremmer
9
 
    @license: GNU GPL, see COPYING for details.
10
 
"""
11
 
 
12
 
### Configuration
13
 
# the request URL, important for farm configurations
14
 
url = "moinmoin.wikiwikiweb.de/"
15
 
 
16
 
# the author, visible in RecentChanges etc.
17
 
author = "IrcLogImporter"
18
 
 
19
 
# the directory that should be pushed
20
 
local_dir = '/home/aschremmer/channel-logging/logs/ChannelLogger/freenode/#moin-dev'
21
 
 
22
 
# basepage of the pushed files
23
 
base_page = 'MoinMoinChat/Logs/'
24
 
 
25
 
# this function generates a pagename from the file name
26
 
def filename_function(filename):
27
 
    filename = filename.lstrip('#')
28
 
    splitted = filename.split('.')
29
 
    return '/'.join(splitted[0:2])
30
 
### end of configuration
31
 
 
32
 
import os, sys
33
 
sys.path.insert(0, '/srv/moin_tw/moin--main--1.5')
34
 
sys.path.insert(0, '/srv/de.wikiwikiweb.moinmaster/bin15')
35
 
 
36
 
from MoinMoin import wikiutil
37
 
from MoinMoin.request import RequestCLI
38
 
from MoinMoin.PageEditor import PageEditor
39
 
 
40
 
def decodeLinewise(text):
41
 
    resultList = []
42
 
    for line in text.splitlines():
43
 
        try:
44
 
            decoded_line = line.decode("utf-8")
45
 
        except UnicodeDecodeError:
46
 
            decoded_line = line.decode("iso-8859-1")
47
 
        resultList.append(decoded_line)
48
 
    return '\n'.join(resultList)
49
 
 
50
 
request = RequestCLI(url=url) #pagename necessary here?
51
 
 
52
 
for root, dirs, files in os.walk(local_dir):
53
 
    files.sort()
54
 
    for filename in files[:-1]: # do not push the last file as it is constantly written to
55
 
        pagename = base_page + filename_function(filename)
56
 
        print "Pushing %r as %r" % (filename, pagename)
57
 
        p = PageEditor(request, pagename,
58
 
                       do_editor_backup=0, uid_override=author)
59
 
        if p.exists():
60
 
            continue
61
 
                    
62
 
        fileObj = open(os.path.join(root, filename), 'rb')
63
 
        try:
64
 
            p.saveText("#format plain\n" + decodeLinewise(fileObj.read()), 0)
65
 
        except PageEditor.SaveError, e:
66
 
            print "Got %r" % (e, )
67
 
        fileObj.close()
68
 
 
69
 
print "Finished."