aboutsummaryrefslogtreecommitdiffstats
path: root/src/mount.wikipediafs
blob: 50d7541f4e07911c4e4db44ccace1a3e67d9d919 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# WikipediaFS
# Copyright (C) 2005 - 2007 Mathieu Blondel
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import os
import sys
from sys import exit

try:
    from fuse import FuseError
except:
    print("The Python bindings for fuse do not seem to be installed.")
    print("Please install fuse-python 0.2 or later.")
    exit(1)
    
# When WFS is mounted with fstab, HOME is not defined...
# We have to deal with this since we need HOME for the config and the log.
if "HOME" not in os.environ:
    last = len(sys.argv) - 1
    mountoptions = sys.argv[last]
    arr = []
    home = None
    for o in mountoptions.split(","):
        if o[0:5] == "home=":
            spl = o.split("=")
            if len(spl) == 2:
                home = spl[1]
        elif o != "noauto" and o != "user" and o != "auto" and o != "nouser":
            arr.append(o)
    sys.argv[last] = ','.join(arr)

    if home:    
        os.environ["HOME"] = home
    elif "USER" in os.environ:
        if os.environ["USER"] == "root":
            os.environ["HOME"] = "/root/"
        else:
            os.environ["HOME"] = "/home/%s/" % os.environ["USER"]

from wikipediafs.fs import WikipediaFS

try:
    from wikipediafs.version import VERSION
except:
    VERSION = 'development version'
   
try:
    server = WikipediaFS(version="%prog " + VERSION,
                         usage='%prog mountpoint',
                         dash_s_do='undef')

    server.parse(errex=1)
    server.multithreaded = 0
    server.main()
except FuseError as detail:
    print(detail)