/
__init__.py
136 lines (117 loc) · 5.05 KB
/
__init__.py
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# <copyright>
# Solipsis, a peer-to-peer serverless virtual world.
# Copyright (C) 2002-2005 France Telecom R&D
#
# This software is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This software 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# </copyright>
"""Plugin profile: allow users to define a set of personal information
and exchange it with other peers"""
__revision__ = "$Id$"
import os, os.path
import locale
import gettext
_ = gettext.gettext
from solipsis.services.profile.message import display_error, display_status
VERSION = "0.3.0"
DISCLAIMER = "All data in profiles are shared within Solipsis communauty"
DOWNLOAD_REPO = os.sep.join([os.path.expanduser("~"), ".solipsis", "download"])
PROFILE_DIR = os.sep.join([os.path.expanduser("~"), ".solipsis", "profiles"])
PREFS_FILE = os.path.join(PROFILE_DIR, ".preferences")
ENCODING = locale.getpreferredencoding()
KNOWN_ENCODINGS = [ENCODING, "utf-8", "utf-16",
"ISO-8859-1", "ISO-8859-15"
"cp1252", "cp437", "cp850"]
global solipsis_dir
def set_solipsis_dir(new_dir):
"""directory must be set at launch time since it's read in file
conf (and passed to the application through params"""
global solipsis_dir
solipsis_dir = new_dir
def force_unicode(chars):
"""return unicode string trying different encodings if locale one
failed"""
if isinstance(chars, unicode):
return chars
for encoding in KNOWN_ENCODINGS:
try:
return unicode(chars, encoding)
except UnicodeDecodeError:
print encoding, "does not apply on", chars
# Encoding not saved in preferences because it must be attached within
# the profile file (to be sent through network)
def save_encoding(file_obj, encoding):
"""write into profile document its encoding"""
file_obj.write("# profile-encoding::%s\n"% encoding)
def load_encoding(file_obj):
"""load from profile document its encoding"""
encoding_tag = file_obj.readline()
if not encoding_tag.startswith("# profile-encoding::"):
# wrong format
# first line has been wastes: rewind
file_obj.seek(0)
# return default
display_status(_("could not read encoding from profile file. "
"Using %s"% ENCODING))
return ENCODING
else:
encoding = encoding_tag.split("::")[-1].strip()
display_status(_("Profile read with encoding %s"% encoding))
return encoding
set_solipsis_dir(os.path.dirname(__file__))
images_dir = lambda : os.path.join(solipsis_dir, u"images")
PREVIEW_PT = lambda : os.path.join(solipsis_dir, u"preview.html")
REGEX_HTML = lambda : os.path.join(solipsis_dir, u"regex.html")
QUESTION_MARK = lambda : os.path.join(images_dir(), u"question_mark.gif")
ADD_CUSTOM = lambda : os.path.join(images_dir(), u"add_file.jpeg")
DEL_CUSTOM = lambda : os.path.join(images_dir(), u"del_file.jpeg")
ADD_BLOG = lambda : os.path.join(images_dir(), u"edit_file.gif")
DEL_BLOG = lambda : os.path.join(images_dir(), u"delete_file.gif")
ADD_COMMENT = lambda : os.path.join(images_dir(), u"comment.gif")
UPLOAD_BLOG = lambda : os.path.join(images_dir(), u"add_file.gif")
ADD_REPO = lambda : os.path.join(images_dir(), u"browse.jpeg")
DEL_REPO = lambda : os.path.join(images_dir(), u"del_file.jpeg")
SHARE = lambda : os.path.join(images_dir(), u"add_file.gif")
UNSHARE = lambda : os.path.join(images_dir(), u"delete_file.gif")
EDIT = lambda : os.path.join(images_dir(), u"edit_file.gif")
PREVIEW = lambda : os.path.join(images_dir(), u"loupe.gif")
DISPLAY_IMG = lambda : os.path.join(images_dir(), u"download_complete.gif")
DOWNLOAD = lambda : os.path.join(images_dir(), u"down_file.gif")
DOWNLOAD_DIR = lambda : os.path.join(images_dir(), u"browse.jpeg")
BULB_ON_IMG = lambda : os.path.join(images_dir(), u"bulb.gif")
BULB_OFF_IMG = lambda : os.path.join(images_dir(), "ubulb_off.gif")
TORE_IMG = lambda : os.path.join(images_dir(), u"tore.gif")
PROFILE_FILE = ".default"
PROFILE_EXT = ".prf"
BLOG_EXT = ".blog"
FILTER_EXT = ".filt"
UNIVERSAL_SEP = r"\\"
DEFAULT_INTERESTS = [_("City"), _("Country"),
_("Sport"), _("Studies"),
_("Favourite Book"), _("Favourite Movie"),
]
# GUI
NB_SHARED_COL = 1
FULL_PATH_COL = 2
NAME_COL = 0
SIZE_COL = 1
SHARED_COL = 2
TAG_COL = 3
# NETWORK
KNOWN_PORT = 1160
if not os.path.isdir(PROFILE_DIR):
print "creating conf directory %s"% PROFILE_DIR
os.makedirs(PROFILE_DIR)
if not os.path.exists(DOWNLOAD_REPO):
os.mkdir(DOWNLOAD_REPO)