本文整理汇总了Python中sugar3.env.get_profile_path函数的典型用法代码示例。如果您正苦于以下问题:Python get_profile_path函数的具体用法?Python get_profile_path怎么用?Python get_profile_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_profile_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _setup_env
def _setup_env(display, scaling, emulator_pid):
# We need to remove the environment related to gnome-keyring-daemon,
# so a new instance of gnome-keyring-daemon can be started and
# registered properly.
for variable in ['GPG_AGENT_INFO', 'SSH_AUTH_SOCK',
'GNOME_KEYRING_CONTROL', 'GNOME_KEYRING_PID']:
if variable in os.environ:
del os.environ[variable]
os.environ['SUGAR_EMULATOR'] = 'yes'
os.environ['GABBLE_LOGFILE'] = os.path.join(
env.get_profile_path(), 'logs', 'telepathy-gabble.log')
os.environ['SALUT_LOGFILE'] = os.path.join(
env.get_profile_path(), 'logs', 'telepathy-salut.log')
os.environ['MC_LOGFILE'] = os.path.join(
env.get_profile_path(), 'logs', 'mission-control.log')
os.environ['STREAM_ENGINE_LOGFILE'] = os.path.join(
env.get_profile_path(), 'logs', 'telepathy-stream-engine.log')
os.environ['DISPLAY'] = ':%d' % (display)
os.environ['SUGAR_EMULATOR_PID'] = emulator_pid
os.environ['MC_ACCOUNT_DIR'] = os.path.join(
env.get_profile_path(), 'accounts')
if scaling:
os.environ['SUGAR_SCALING'] = scaling
示例2: _load_favorites
def _load_favorites(self):
for i in range(desktop.get_number_of_views()):
# Special-case 0 for backward compatibility
if i == 0:
favorites_path = env.get_profile_path('favorite_activities')
else:
favorites_path = env.get_profile_path(
'favorite_activities_%d' % (i))
if os.path.exists(favorites_path):
favorites_data = json.load(open(favorites_path))
favorite_bundles = favorites_data['favorites']
if not isinstance(favorite_bundles, dict):
raise ValueError('Invalid format in %s.' % favorites_path)
if favorite_bundles:
first_key = favorite_bundles.keys()[0]
if not isinstance(first_key, basestring):
raise ValueError('Invalid format in %s.' %
favorites_path)
first_value = favorite_bundles.values()[0]
if first_value is not None and \
not isinstance(first_value, dict):
raise ValueError('Invalid format in %s.' %
favorites_path)
self._favorite_bundles[i] = favorite_bundles
示例3: _write_favorites_file
def _write_favorites_file(self, favorite_view):
if favorite_view == 0:
path = env.get_profile_path('favorite_activities')
else:
path = env.get_profile_path('favorite_activities_%d' %
(favorite_view))
favorites_data = {
'favorites': self._favorite_bundles[favorite_view]}
json.dump(favorites_data, open(path, 'w'), indent=1)
示例4: _write_favorites_file
def _write_favorites_file(self, favorite_view):
if favorite_view == 0:
path = env.get_profile_path("favorite_activities")
else:
path = env.get_profile_path("favorite_activities_%d" % (favorite_view))
favorites_data = {
"defaults-mtime": self._last_defaults_mtime[favorite_view],
"favorites": self._favorite_bundles[favorite_view],
}
json.dump(favorites_data, open(path, "w"), indent=1)
示例5: __init__
def __init__(self, activity, window_xid):
self.parent_window_xid = window_xid
url, title = get_help_url_and_title(activity)
has_local_help = url is not None
self._mode = _MODE_HELP if has_local_help else _MODE_SOCIAL_HELP
Gtk.Window.__init__(self)
box = Gtk.Box()
box.set_orientation(Gtk.Orientation.VERTICAL)
self.add(box)
box.show()
self.set_decorated(False)
self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
self.set_border_width(style.LINE_WIDTH)
self.set_has_resize_grip(False)
width = Gdk.Screen.width() - style.GRID_CELL_SIZE * 2
height = Gdk.Screen.height() - style.GRID_CELL_SIZE * 2
self.set_size_request(width, height)
self.connect('realize', self.__realize_cb)
self.connect('hide', self.__hide_cb)
self.connect('key-press-event', self.__key_press_event_cb)
toolbar = Toolbar(title, has_local_help)
box.pack_start(toolbar, False, False, 0)
toolbar.show()
toolbar.connect('stop-clicked', self.__stop_clicked_cb)
toolbar.connect('mode-changed', self.__mode_changed_cb)
session = WebKit.get_default_session()
cookie_jar = SoupGNOME.CookieJarSqlite(
filename=os.path.join(env.get_profile_path(),
'social-help.cookies'),
read_only=False)
session.add_feature(cookie_jar)
self._webview = WebKit.WebView()
self._webview.set_full_content_zoom(True)
self._webview.connect('resource-request-starting',
self._resource_request_starting_cb)
scrolled_window = Gtk.ScrolledWindow()
scrolled_window.add(self._webview)
scrolled_window.show()
box.pack_start(scrolled_window, True, True, 0)
self._webview.show()
language = self._get_current_language()
if has_local_help:
self._help_url = 'file://' + self._get_help_file(language, url)
self._social_help_url = '{}/goto/{}'.format(
get_social_help_server(), activity.get_bundle_id())
self._webview.connect(
'notify::load-status', self.__load_status_changed_cb)
self._load_mode(self._mode)
示例6: _store_identifiers
def _store_identifiers(serial_number, uuid_, backup_url):
""" Stores the serial number, uuid and backup_url
in the identifier folder inside the profile directory
so that these identifiers can be used for backup. """
identifier_path = os.path.join(env.get_profile_path(), 'identifiers')
if not os.path.exists(identifier_path):
os.mkdir(identifier_path)
if os.path.exists(os.path.join(identifier_path, 'sn')):
os.remove(os.path.join(identifier_path, 'sn'))
serial_file = open(os.path.join(identifier_path, 'sn'), 'w')
serial_file.write(serial_number)
serial_file.close()
if os.path.exists(os.path.join(identifier_path, 'uuid')):
os.remove(os.path.join(identifier_path, 'uuid'))
uuid_file = open(os.path.join(identifier_path, 'uuid'), 'w')
uuid_file.write(uuid_)
uuid_file.close()
if os.path.exists(os.path.join(identifier_path, 'backup_url')):
os.remove(os.path.join(identifier_path, 'backup_url'))
backup_url_file = open(os.path.join(identifier_path, 'backup_url'), 'w')
backup_url_file.write(backup_url)
backup_url_file.close()
示例7: create_profile
def create_profile(name, color=None):
if not color:
color = XoColor()
client = GConf.Client.get_default()
client.set_string('/desktop/sugar/user/nick', name)
client.set_string('/desktop/sugar/user/color', color.to_string())
client.suggest_sync()
if profile.get_pubkey() and profile.get_profile().privkey_hash:
logging.info('Valid key pair found, skipping generation.')
return
# Generate keypair
import commands
keypath = os.path.join(env.get_profile_path(), 'owner.key')
if os.path.exists(keypath):
os.rename(keypath, keypath + '.broken')
logging.warning('Existing private key %s moved to %s.broken',
keypath, keypath)
if os.path.exists(keypath + '.pub'):
os.rename(keypath + '.pub', keypath + '.pub.broken')
logging.warning('Existing public key %s.pub moved to %s.pub.broken',
keypath, keypath)
logging.debug("Generating user keypair")
cmd = "ssh-keygen -q -t dsa -f %s -C '' -N ''" % (keypath, )
(s, o) = commands.getstatusoutput(cmd)
if s != 0:
logging.error('Could not generate key pair: %d %s', s, o)
logging.debug("User keypair generated")
示例8: _hash_private_key
def _hash_private_key(self):
key_path = os.path.join(env.get_profile_path(), 'owner.key')
if not os.path.exists(key_path):
return None
try:
f = open(key_path, 'r')
lines = f.readlines()
f.close()
except IOError:
logging.exception('Error reading private key')
return None
key = ""
begin_found = False
end_found = False
for l in lines:
l = l.strip()
if l.startswith('-----BEGIN DSA PRIVATE KEY-----'):
begin_found = True
continue
if l.startswith('-----END DSA PRIVATE KEY-----'):
end_found = True
continue
key += l
if not (len(key) and begin_found and end_found):
logging.error('Error parsing public key.')
return None
# hash it
key_hash = util.sha_data(key)
return util.printable_hash(key_hash)
示例9: get_environment
def get_environment(activity):
environ = os.environ.copy()
bin_path = os.path.join(activity.get_path(), 'bin')
activity_root = env.get_profile_path(activity.get_bundle_id())
_mkdir(activity_root)
instance_dir = os.path.join(activity_root, 'instance')
_mkdir(instance_dir)
data_dir = os.path.join(activity_root, 'data')
_mkdir(data_dir)
tmp_dir = os.path.join(activity_root, 'tmp')
_mkdir(tmp_dir)
environ['SUGAR_BUNDLE_PATH'] = activity.get_path()
environ['SUGAR_BUNDLE_ID'] = activity.get_bundle_id()
environ['SUGAR_ACTIVITY_ROOT'] = activity_root
environ['PATH'] = bin_path + ':' + environ['PATH']
if activity.get_path().startswith(env.get_user_activities_path()):
environ['SUGAR_LOCALEDIR'] = os.path.join(activity.get_path(),
'locale')
return environ
示例10: __init__
def __init__(self):
GObject.GObject.__init__(self)
self._friends = {}
self._path = os.path.join(env.get_profile_path(), 'friends')
self.load()
示例11: __init__
def __init__(self, handle):
activity.Activity.__init__(self, handle)
self._autosearch_timer = None
# Paths to watch: ~/.sugar/someuser/logs, /var/log
paths = []
paths.append(env.get_profile_path('logs'))
paths.append('/var/log')
# Additional misc files.
ext_files = []
ext_files.append(os.path.expanduser('~/.bash_history'))
self.viewer = MultiLogView(paths, ext_files)
self.set_canvas(self.viewer)
self.viewer.grab_focus()
self._build_toolbox()
# Get Sugar's clipboard
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
self.show()
self._configure_cb(None)
Gdk.Screen.get_default().connect('size-changed', self._configure_cb)
示例12: uninstall
def uninstall(self, force=False, delete_profile=False):
install_path = self.get_path()
if os.path.islink(install_path):
# Don't remove the actual activity dir if it's a symbolic link
# because we may be removing user data.
os.unlink(install_path)
return
xdg_data_home = os.getenv("XDG_DATA_HOME", os.path.expanduser("~/.local/share"))
mime_dir = os.path.join(xdg_data_home, "mime")
installed_mime_path = os.path.join(mime_dir, "packages", "%s.xml" % self._bundle_id)
if os.path.exists(installed_mime_path):
os.remove(installed_mime_path)
os.spawnlp(os.P_WAIT, "update-mime-database", "update-mime-database", mime_dir)
mime_types = self.get_mime_types()
if mime_types is not None:
installed_icons_dir = os.path.join(xdg_data_home, "icons/sugar/scalable/mimetypes")
if os.path.isdir(installed_icons_dir):
for f in os.listdir(installed_icons_dir):
path = os.path.join(installed_icons_dir, f)
if os.path.islink(path) and os.readlink(path).startswith(install_path):
os.remove(path)
if delete_profile:
bundle_profile_path = env.get_profile_path(self._bundle_id)
if os.path.exists(bundle_profile_path):
os.chmod(bundle_profile_path, 0775)
shutil.rmtree(bundle_profile_path, ignore_errors=True)
self._uninstall(install_path)
示例13: _configure_vt
def _configure_vt(self, vt):
conf = ConfigParser.ConfigParser()
conf_file = os.path.join(env.get_profile_path(), 'terminalrc')
if os.path.isfile(conf_file):
f = open(conf_file, 'r')
conf.readfp(f)
f.close()
else:
conf.add_section('terminal')
font = self._get_conf(conf, 'font', 'Monospace')
vt.set_font(Pango.FontDescription(font))
self._theme_colors = {"light": {'fg_color': '#000000',
'bg_color': '#FFFFFF'},
"dark": {'fg_color': '#FFFFFF',
'bg_color': '#000000'}}
fg_color = self._theme_colors[self._theme_state]['fg_color']
bg_color = self._theme_colors[self._theme_state]['bg_color']
try:
vt.set_colors(Gdk.color_parse(fg_color),
Gdk.color_parse(bg_color), [])
except TypeError:
# Vte 0.38 requires the colors set as a different type
# in Fedora 21 we get a exception
# TypeError: argument foreground: Expected Gdk.RGBA,
# but got gi.overrides.Gdk.Color
vt.set_colors(Gdk.RGBA(*Gdk.color_parse(fg_color).to_floats()),
Gdk.RGBA(*Gdk.color_parse(bg_color).to_floats()), [])
blink = self._get_conf(conf, 'cursor_blink', False)
vt.set_cursor_blink_mode(blink)
bell = self._get_conf(conf, 'bell', False)
vt.set_audible_bell(bell)
scrollback_lines = self._get_conf(conf, 'scrollback_lines', 1000)
vt.set_scrollback_lines(scrollback_lines)
vt.set_allow_bold(True)
scroll_key = self._get_conf(conf, 'scroll_on_keystroke', True)
vt.set_scroll_on_keystroke(scroll_key)
scroll_output = self._get_conf(conf, 'scroll_on_output', False)
vt.set_scroll_on_output(scroll_output)
if hasattr(vt, 'set_emulation'):
# set_emulation is not available after vte commit
# 4e253be9282829f594c8a55ca08d1299e80e471d
emulation = self._get_conf(conf, 'emulation', 'xterm')
vt.set_emulation(emulation)
if hasattr(vt, 'set_visible_bell'):
visible_bell = self._get_conf(conf, 'visible_bell', False)
vt.set_visible_bell(visible_bell)
conf.write(open(conf_file, 'w'))
示例14: check_profile
def check_profile():
profile = get_profile()
path = os.path.join(env.get_profile_path(), 'config')
if os.path.exists(path):
profile.convert_profile()
return profile.is_valid()
示例15: _create_file
def _create_file(self):
activity_root = env.get_profile_path(self._activity.get_type())
instance_path = os.path.join(activity_root, "instance")
file_path = os.path.join(instance_path, "%i" % time.time())
file_object = open(file_path, "w")
return file_path, file_object