File: platform.py

package info (click to toggle)
thawab 4.1-2
  • links: PTS, VCS
  • area: non-free
  • in suites: bullseye, sid
  • size: 1,912 kB
  • sloc: python: 4,041; makefile: 134; sh: 33
file content (80 lines) | stat: -rw-r--r-- 2,433 bytes parent folder | download
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
74
75
76
77
78
79
80
# -*- coding: UTF-8 -*-
"""
Platform specific routines of thawab
Copyright © 2008-2010, Muayyad Alsadi <alsadi@ojuba.org>

        Released under terms of Waqf Public License.
        This program is free software; you can redistribute it and/or modify
        it under the terms of the latest version Waqf Public License as
        published by Ojuba.org.

        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.

        The Latest version of the license can be found on
        "http://waqf.ojuba.org/license"

"""
import sys, os, os.path
from glob import glob

if sys.platform  ==  'win32':
    def uri_to_filename(u):
        if len(u) <= 1:
            return u
        return u[1:].replace('/','\\')

    def get_drives():
        return [j for j in [chr(i)+':\\' for i in range(67,91)] if os.path.exists(j)]

    try:
        from winpaths import get_appdata as application_data
    except ImportError:
        try:
            from winshell import application_data
        except ImportError:
            try:
                import win32com.shell as shell
                def application_data():
                    return shell.SHGetFolderPath(0, 26, 0, 0)
            except ImportError:
                application_data = None
    if application_data:
        app_data = application_data()
        th_conf = os.path.join(app_data, "thawab", "conf", "main.conf")
    else:
        app_data = "C:\\"
        th_conf = "C:\\thawab.conf"

else:
    app_data = "/usr/share/"
    application_data = None
    def uri_to_filename(u):
        return u

    def get_drives():
        return []
    th_conf = os.path.expanduser('~/.thawab/conf/main.conf')

def guess_prefixes():
    l = []
    ed = os.path.join(os.path.dirname(sys.argv[0]), 'thawab-data')
    ed_1st = False
    if os.path.isdir(ed) and os.access(ed, os.W_OK):
        l.append(ed)
        ed_1st = True
    if sys.platform  ==  'win32':
        l.append(os.path.join(app_data,'thawab'))
        if not ed_1st:
            l.append(ed)
        l.extend([os.path.join(d, 'thawab-data') for d in get_drives()])
    else:
        l.append(os.path.expanduser('~/.thawab'))
        if not ed_1st:
            l.append(ed)
        l.append('/usr/local/share/thawab')
        l.append('/usr/share/thawab')
    return l