def main(argv): setup_locale() DBusGMainLoop(set_as_default=True) glib.set_application_name(APPNAME) glib.set_prgname(APPNAME) uargv = [fromlocaleencoding(arg, errors=False) for arg in argv[1:]] desktop_startup_id = os.getenv("DESKTOP_STARTUP_ID", "") try: m = MainInstance() except RuntimeError as exc: log(exc) return 1 except NameError as exc: log(exc) log("An instance already running, passing on commandline...") return service_send_commandline(uargv, "", desktop_startup_id) lazy_import("uuid") lazy_import("gtk") lazy_import("gio") glib.idle_add(m.setup_basic) glib.idle_add(m.setup_gui) glib.idle_add(m.handle_commandline_main, uargv, "", desktop_startup_id) ensuredir(get_notesdir()) try: gtk.main() finally: m.unregister() m.close_all()
def __init__(self): self.keyring = "login" self.display_name = "nodeutil" self.username = None self.password = None self.show_used = True glib.set_application_name(self.display_name)
def parse_server_capabilities(self, capabilities): XpraClientBase.parse_server_capabilities(self, capabilities) if not self.session_name: self.session_name = capabilities.get("session_name", "Xpra") try: import glib glib.set_application_name(self.session_name) except ImportError, e: log.warn("glib is missing, cannot set the application name, please install glib's python bindings: %s", e)
def _process_hello(self, packet): capabilities = packet[1] self.server_capabilities = capabilities if not self.session_name: self.session_name = capabilities.get("session_name", "Xpra") try: import glib glib.set_application_name(self.session_name) except ImportError, e: log.error("glib is missing, cannot set the application name, please install glib's python bindings: %s", e)
def _process_hello(self, packet): capabilities = packet[1] self.server_capabilities = capabilities if not self.session_name: self.session_name = capabilities.get("session_name", "Xpra") try: import glib glib.set_application_name(self.session_name) except ImportError, e: log.warn("glib is missing, cannot set the application name, please install glib's python bindings: %s", e)
def __init__(self): self.si="" self.VERSION = "0.1.1" self.LICENSE = license_file.LICENSE self.keyword = "" self.meaning = "" self.speak_result ="" glib.set_application_name("theeram") # Important in the case of Unity SysTray Whitelist regisn. self.libt = libtheeram.libtheeram() self.wnd_main()
def cmd_export_to_gnome_keyring(): """Write out accounts to Gnome Keyring. Only useful for 'backup', if you have keyring tools. There is currently no way to import these keys back into kip. Requires python2 and gnomekeyring lib. Note that this does NOT make the passwords usable to Chrome - this is not a counterpart to import_chrome_gnome_keyring. """ import time import gnomekeyring as gk import glib glib.set_application_name('kip') keyrings = gk.list_keyring_names_sync() if not 'kip' in keyrings: gk.create_sync('kip', None) # None means prompt user for password for filename in glob.glob('{}/*'.format(HOME_PWD)): user, pwd, notes = extract(filename) domain = os.path.basename(filename) print("Exporting {} ({})".format(domain, user)) """ msg = "Export %s (%s)? [y|N]" % (domain, user) try: choice = raw_input(msg) except NameError: # python 3 choice = input(msg) if choice.lower() != 'y': print('Skipping') continue """ attributes = { "username": user.encode("utf8"), "notes": notes.encode("utf8"), "date_created": str(int(time.time())), } gk.item_create_sync('kip', gk.ITEM_GENERIC_SECRET, domain, attributes, pwd.encode("utf8"), True)
def set_application_name(name): global NAME_SET if NAME_SET: return NAME_SET = True from xpra.log import Logger log = Logger() if sys.version_info[:2]<(2,5): log.warn("Python %s is too old!", sys.version_info) return try: import glib glib.set_application_name(name or "Xpra") except ImportError, e: log.warn("glib is missing, cannot set the application name, please install glib's python bindings: %s", e)
def start(self): global CONFIG CONFIG = json.load(open(CONFIG_FILE, 'r')) try: glib.set_application_name(APP_NAME) pynotify.init(APP_NAME) with LockFile(): self.keyring = Keyring() self.accounts = self.keyring.list_accounts() for account in self.accounts: self.modified[account] = datetime.datetime(1900, 1, 1) self.check_gmail() gtk.timeout_add(CONFIG['poll_frequency'] * 1000, self.check_gmail) gtk.main() except IOError: sys.stderr.write('[ERROR] Only one instance of ' + APP_NAME + ' can run at a time.')
def main(): try: import glib glib.set_application_name(APPLICATION_NAME) except: pass if len(sys.argv) == 2: update_options_from_file(sys.argv[1]) app = ApplicationWindow() if xpra_opts.autoconnect == "True": #file says we should connect, do that only: process = app.start_xpra_process() return process.wait() else: app.create_window() app.run() if xpra_opts.password_file: os.unlink(xpra_opts.password_file) return 0
def cmd_import_from_chrome(): """Import keys stored in Gnome Keyring by Chrome. Depends on gnomekeyring (python lib) which unfortunately is Python2 only, so run: python cli.py --import-chrome Note that this does NOT import the keys created by export_to_gnome_keyring, below. This imports what Chrome stores, the export method below pushes kip keys into keyring. """ import gnomekeyring as gk import glib def clean_domain(domain): return domain.replace('http://', '').replace('https://', '').strip('/') glib.set_application_name('kip') ids = gk.list_item_ids_sync('login') for id in ids: attrs = gk.item_get_attributes_sync('login', id) domain = clean_domain(attrs['signon_realm']) username = attrs['username_value'] info = gk.item_get_info_sync('login', id) pwd = info.get_secret() msg = "Import %s (%s)? [y|N]" % (domain, username) try: choice = raw_input(msg) except NameError: # python 3 choice = input(msg) if choice.lower() != 'y': print('Skipping') continue create(domain, username, pwd=pwd)
def do_set_application_name(name): try: import glib glib.set_application_name(name) except: pass
def __init__(self): #Builder and main window glib.set_application_name("pkgcreator-gtk") self.filename = None self.dict = {} self.phase = 0
def __init__(self): global keyring self.username = None self.password = None self.multiline = False self.separator = False self.gconf = gconf.client_get_default() self.appname = "gtracker" self.username_key = "/apps/gtracker/username" self.password_key = "/apps/gtracker/password" self.interval_key = "/apps/gtracker/interval" self.multi_key = "/apps/gtracker/multiline" self.sep_key = "/apps/gtracker/separator" self.interval = self.gconf.get_int(self.interval_key) if self.interval<1: self.interval = 15 self.gconf.set_int(self.interval_key,self.interval) self.multiline = self.gconf.get_bool(self.multi_key) if self.multiline==None: self.multiline = True self.gconf.set_bool(self.multi_key,self.multiline) self.separator = self.gconf.get_bool(self.sep_key) if self.separator==None: self.separator = True self.gconf.set_bool(self.sep_key,self.separator) if keyring: try: glib.set_application_name(self.appname) except: pass if gk.is_available(): names = gk.list_keyring_names_sync() if not self.appname in names: gk.create_sync(self.appname,"") keys = gk.list_item_ids_sync(self.appname) if len(keys)==1: gk.unlock_sync(self.appname,"") info = gk.item_get_info_sync(self.appname,keys[0]) self.username = info.get_display_name() self.password = info.get_secret() else: self.username = "" self.password = "" else: keyring = False if not keyring: self.username = self.gconf.get_string(self.username_key) if self.username==None or len(self.username)<1: self.username = "" self.gconf.set_string(self.username_key,"") self.password = self.gconf.get_string(self.password_key) if self.password==None or len(self.password)<1: self.password = "" self.gconf.set_string(self.password_key,self.password) else: self.gconf.unset(self.username_key) self.gconf.unset(self.password_key)
#!/usr/bin/env python # Save proxy password in keyring for NetBeans IDE import gnomekeyring as gk import glib import sys if (len(sys.argv) >= 2): password=str(sys.argv[1]) if (password == '%%PASSWORD%%'): password = '' else: password = '' glib.set_application_name("NetBeans IDE 8.1.0") gk.item_create_sync ("login", gk.ITEM_GENERIC_SECRET, "Proxy password", {'key': 'proxyAuthenticationPassword'}, password, True)
class NoSuchKeyringError(GnomeKeyringException): pass except ImportError: try: # Fall back to pygobject2 bindings for GNOME keyring. import gnomekeyring as gk def get_item(krname, item_id): return gk.item_get_info_sync(krname, item_id) NoSuchKeyringError = gk.NoSuchKeyringError try: import glib # Avoid: WARNING **: g_set_application_name not set. glib.set_application_name('splunk') except: pass except ImportError: import_advice('import pygobject2/pygobject3 bindings for GnomeKeyring') raise # re-raise # # from gi.repository import Secret # # The stable API for libsecret only supports getting, setting, and removing # individual items with known attributes. For example, there is no way to # iterate over an existing collection and enumerate all existing items. # # This means the stable APIs do not meet our requirements, which include # "generic fetch of a group of related-but-arbitrary items". #
def __init__(self): gtk.Window.__init__(self) glib.set_application_name("TouchMenu") glib.set_prgname("TouchMenu") self.set_title("Configuration") self.set_border_width(12) self.connect("delete_event", self.delete_event) self.connect("destroy", self.destroy) table = gtk.Table(2, 8) table.set_col_spacings(12) table.set_row_spacings(12) self.add(table) label = gtk.Label("Configuration Options") table.attach(label, 0, 2, 0, 1) labelEmail = gtk.Label("Email Settings (imap only):") labelEmail.set_alignment(1.0, 0.5) table.attach(labelEmail, 0, 2, 1, 2) labeleDomain = gtk.Label("Domain:") labeleDomain.set_alignment(1.0, 0.5) table.attach(labeleDomain, 0, 1, 2, 3) self.domain = gtk.Entry() table.attach(self.domain, 1, 2, 2, 3) labelePort = gtk.Label("Port:") labelePort.set_alignment(1.0, 0.5) table.attach(labelePort, 0, 1, 3, 4) self.port = gtk.Entry() self.port.set_text("993") table.attach(self.port, 1, 2, 3, 4) labeleUser = gtk.Label("Username:"******"Password:"******"Quit") quit.connect("clicked", self.close) table.attach(quit, 1, 2, 7, 8) save = gtk.Button("Save") save.connect("clicked", self.save) table.attach(save, 0, 1, 7, 8) self.show_all()
def main(): # When changing this, make sure to update configure.ac as well if sys.version_info < (2, 6, 1): message = "Reinteract requires Python 2.6.1 or newer" print >> sys.stderr, message try: dialog = gtk.MessageDialog(buttons=gtk.BUTTONS_OK, type=gtk.MESSAGE_ERROR, message_format=message) dialog.run() finally: sys.exit(1) # When launched from the finder on OS X, the command line will have a # -psx (process serial number) argument. Strip that out. sys.argv = filter(lambda x: not x.startswith("-psn"), sys.argv) parser = OptionParser() parser.add_option("-u", "--ui", choices=("standard", "mini"), default="standard", help="the user interface mode (standard or mini)") parser.add_option("-d", "--debug", action="store_true", help="enable internal debug messages") options, args = parser.parse_args() if options.debug: logging.basicConfig(level=logging.DEBUG) global_settings.mini_mode = options.ui == "mini" user_ext_path = os.path.expanduser( os.path.join('~', '.reinteract', 'modules')) if os.path.exists(user_ext_path): sys.path[0:0] = [user_ext_path] gtk.window_set_default_icon_name("reinteract") glib.set_application_name("Reinteract") if len(args) > 0: if sys.platform == 'win32': args = [a.decode("mbcs") for a in args] else: args = [a.decode("UTF-8") for a in args] if options.ui == "standard": for arg in args: application.open_path(os.path.abspath(arg)) if len(application.windows) == 0: # nothing opened successfully sys.exit(1) else: # mini-mode, can specify one notebook if len(args) > 1: print >> sys.stderr, "Ignoring extra command line arguments." absolute = os.path.abspath(args[0].decode("UTF-8")) # We look to see if we can find the specified notebook so that we can # produce a good error message instead of opening a worksheet window notebook_path, relative = application.find_notebook_path(absolute) if not notebook_path: if os.path.isdir(absolute): error_message = "'%s' is not a Reinteract notebook" % args[ 0] else: error_message = "'%s' is not inside a Reinteract notebook" % args[ 0] dialog = gtk.MessageDialog(buttons=gtk.BUTTONS_OK, type=gtk.MESSAGE_ERROR, message_format=error_message) dialog.run() sys.exit(1) if not application.open_path(absolute): sys.exit(1) else: recent_notebooks = application.state.get_recent_notebooks() window = None for notebook in recent_notebooks: notebook_dir = notebook.path try: window = application.open_notebook(notebook_dir) except OSError: pass else: break if window is None: notebook_dir = os.path.expanduser( os.path.join(global_settings.notebooks_dir, "Main")) if not os.path.exists(notebook_dir): window = application.create_notebook( notebook_dir, description= "Notebook for scratch work.\nCreate worksheets here if they are not part of a larger project, or for quick experiments." ) else: window = application.open_notebook(notebook_dir) # This really should be a more general check for "is writeable" if notebook_dir != global_settings.examples_dir: window.add_initial_worksheet() gtk.main()
import appindicator except ImportError: HAS_INDICATOR = False else: HAS_INDICATOR = True if __import__('os').environ.get('DESKTOP_SESSION') in ('gnome-2d', 'classic-gnome'): HAS_INDICATOR = False try: import i18n except: from gettext import gettext as _ try: import glib glib.set_application_name(_("Hermelin")) except: pass HERMELIN_DBUS_PATH = '/org/hermelin/service' HERMELIN_DBUS_NAME = 'org.hermelin.service' class HermelinDbusService(dbus.service.Object): def __init__(self, app): bus_name = dbus.service.BusName(HERMELIN_DBUS_NAME, bus=dbus.SessionBus()) dbus.service.Object.__init__(self, bus_name, HERMELIN_DBUS_PATH) self.app = app s = [] @dbus.service.method(dbus_interface=HERMELIN_DBUS_NAME, in_signature="", out_signature="i") def unread(self):
def main(): # When changing this, make sure to update configure.ac as well if sys.version_info < (2, 6, 1): message = "Reinteract requires Python 2.6.1 or newer" print >>sys.stderr, message try: dialog = gtk.MessageDialog(buttons=gtk.BUTTONS_OK, type=gtk.MESSAGE_ERROR, message_format=message) dialog.run() finally: sys.exit(1) # When launched from the finder on OS X, the command line will have a # -psx (process serial number) argument. Strip that out. sys.argv = filter(lambda x: not x.startswith("-psn"), sys.argv) parser = OptionParser() parser.add_option("-u", "--ui", choices=("standard", "mini"), default="standard", help="the user interface mode (standard or mini)") parser.add_option("-d", "--debug", action="store_true", help="enable internal debug messages") options, args = parser.parse_args() if options.debug: logging.basicConfig(level=logging.DEBUG) global_settings.mini_mode = options.ui == "mini" user_ext_path = os.path.expanduser(os.path.join('~', '.reinteract', 'modules')) if os.path.exists(user_ext_path): sys.path[0:0] = [user_ext_path] gtk.window_set_default_icon_name("reinteract") glib.set_application_name("Reinteract") if len(args) > 0: if sys.platform == 'win32': args = [a.decode("mbcs") for a in args] else: args = [a.decode("UTF-8") for a in args] if options.ui == "standard": for arg in args: application.open_path(os.path.abspath(arg)) if len(application.windows) == 0: # nothing opened successfully sys.exit(1) else: # mini-mode, can specify one notebook if len(args) > 1: print >>sys.stderr, "Ignoring extra command line arguments." absolute = os.path.abspath(args[0].decode("UTF-8")) # We look to see if we can find the specified notebook so that we can # produce a good error message instead of opening a worksheet window notebook_path, relative = application.find_notebook_path(absolute) if not notebook_path: if os.path.isdir(absolute): error_message = "'%s' is not a Reinteract notebook" % args[0] else: error_message = "'%s' is not inside a Reinteract notebook" % args[0] dialog = gtk.MessageDialog(buttons=gtk.BUTTONS_OK, type=gtk.MESSAGE_ERROR, message_format=error_message) dialog.run() sys.exit(1) if not application.open_path(absolute): sys.exit(1) else: recent_notebooks = application.state.get_recent_notebooks() window = None for notebook in recent_notebooks: notebook_dir = notebook.path try: window = application.open_notebook(notebook_dir) except OSError: pass else: break if window is None: notebook_dir = os.path.expanduser(os.path.join(global_settings.notebooks_dir, "Main")) if not os.path.exists(notebook_dir): window = application.create_notebook(notebook_dir, description="Notebook for scratch work.\nCreate worksheets here if they are not part of a larger project, or for quick experiments.") else: window = application.open_notebook(notebook_dir) # This really should be a more general check for "is writeable" if notebook_dir != global_settings.examples_dir: window.add_initial_worksheet() gtk.main()
import dbus,gobject,sys from gobject import * from dbus.mainloop.glib import DBusGMainLoop from listeners import * from displayers import * from monitor import MediapadMonitor # Create the threaded mainloop DBusGMainLoop(set_as_default=True) mainloop = gobject.MainLoop() gobject.threads_init() context = mainloop.get_context() import glib glib.set_application_name(TRAY_TOOLTIP) # The global MediapadMonitor global monitored monitored = None def create_menu_item(menu, label, func=None,icon=''): item = wx.MenuItem(menu, -1, label) if icon != '': item.SetBitmap(wx.Bitmap(icon)) if func != None: menu.Bind(wx.EVT_MENU, func, id=item.GetId()) menu.AppendItem(item) return item class SysTrayMonitor(wx.TaskBarIcon):
# Indicator indicator_unread = indicate.Indicator() indicator_unread.set_property("name", label) indicator_unread.set_property("count", "0") indicator_unread.set_property("draw-attention", "false"); indicator_unread.label = label indicator_unread.show() try: import i18n except: from gettext import gettext as _ try: import glib glib.set_application_name(_("Hotot")) except: pass HOTOT_DBUS_PATH = '/org/hotot/service' HOTOT_DBUS_NAME = 'org.hotot.service' class HototDbusService(dbus.service.Object): def __init__(self, app): bus_name = dbus.service.BusName(HOTOT_DBUS_NAME, bus=dbus.SessionBus()) dbus.service.Object.__init__(self, bus_name, HOTOT_DBUS_PATH) self.app = app s = [] @dbus.service.method(dbus_interface=HOTOT_DBUS_NAME, in_signature="", out_signature="i") def unread(self):
def getUnreadImap(server, port, inbox, login, password): serv = imaplib.IMAP4_SSL(server, port) # if your imap mail server doesn't use ssl comment the above # line and uncomment this one. # serv = imaplib.IMAP4(server,port) serv.login(login, password) serv.select(inbox) data = str(serv.status(inbox, "(MESSAGES UNSEEN)")) serv.close() serv.logout() # prepare regular expression p = re.compile("(.*UNSEEN |\) '\]\))") return int(p.sub("", data)) glib.set_application_name(APP_NAME) keyrings = gk.list_keyring_names_sync() if KEYRING_NAME not in keyrings: print "Keyring", KEYRING_NAME, "not found" exit() if gk.get_info_sync(KEYRING_NAME).get_is_locked(): message = "Give password for keyring" while True: password = get_password(message) if password is not None: try: gk.unlock_sync(KEYRING_NAME, password) break except gk.IOError: message = "Password is wrong. Try again."
opts.first_run = not os.path.isfile(opts.config) try: from cf import ipc ipc_client = ipc.get_client() except AttributeError, err: logging.warning('No IPC available: %s', err) ipc_client = None # Let's import gtk and related. # Note: We import them here to allow command line usage # (e.g. crunchyfrog --version) without gkt requirements. try: import glib glib.set_application_name('CrunchyFrog') except ImportError: logging.debug('glib module not found.') import pygtk if not sys.platform == 'win32': pygtk.require('2.0') import gtk try: import gnome have_gnome = True except ImportError: have_gnome = False logging.info('GNOME enabled: %s', have_gnome and 'yes' or 'no')
HAS_ME_MENU = False else: HAS_ME_MENU = True if __import__('os').environ.get('DESKTOP_SESSION') in ('gnome-2d', 'classic-gnome'): HAS_INDICATOR = False HAS_ME_MENU = False HAS_ME_MENU = False try: import i18n except: from gettext import gettext as _ try: import glib glib.set_application_name(_("Hotot")) except: pass HOTOT_DBUS_PATH = '/org/hotot/service' HOTOT_DBUS_NAME = 'org.hotot.service' class HototDbusService(dbus.service.Object): def __init__(self, app): bus_name = dbus.service.BusName(HOTOT_DBUS_NAME, bus=dbus.SessionBus()) dbus.service.Object.__init__(self, bus_name, HOTOT_DBUS_PATH) self.app = app @dbus.service.method(dbus_interface=HOTOT_DBUS_NAME, sender_keyword='sender') def unread(self, sender=None): return self.app.state['unread_count']
# along with Pycle. If not, see <http://www.gnu.org/licenses/>. try: import gnomekeyring as gk keyring = 'gk' except ImportError: try: import PyKDE4.kdeui.KWallet keyring = 'kk' except ImportError: import PyMacAdmin.Security.Keychain keyring = 'xk' import glib import objects glib.set_application_name('gk_text') if 'pycle' not in gk.list_keyring_names_sync(): gk.create_sync('pycle', 'pyclepass') class Connection(object): """A database connection""" def __init__(self, username, password, **params): if 'key' in params: self.key = params['key'] else: self.key = None if 'sid' in params: self.sid = params['sid'] self.name = username + '@' + self.sid
def _process_hello(self, packet): capabilities = packet[1] self.server_capabilities = capabilities if not self.session_name: self.session_name = capabilities.get("session_name", "Xpra") import glib glib.set_application_name(self.session_name) self.keyboard_as_properties = capabilities.get("keyboard_as_properties", False) self._raw_keycodes_feature = capabilities.get("raw_keycodes_feature", False) self._raw_keycodes_full = capabilities.get("raw_keycodes_full", False) self._focus_modifiers_feature = capabilities.get("raw_keycodes_feature", False) self._remote_version = capabilities.get("__prerelease_version") or capabilities.get("version") if not is_compatible_with(self._remote_version): self.quit() return if capabilities.get("dynamic_compression", False): self.send_deflate_level() elif "deflate" in capabilities: #"deflate" is the old-style (pre 0.0.7.33): enable straight away: self._protocol.enable_deflate(capabilities["deflate"]) self.server_actual_desktop_size = capabilities.get("actual_desktop_size") self.server_desktop_size = capabilities.get("desktop_size") if self.server_desktop_size: avail_w, avail_h = self.server_desktop_size root_w, root_h = gtk.gdk.get_default_root_window().get_size() if (avail_w, avail_h) < (root_w, root_h): log.warn("Server's virtual screen is too small -- " "(server: %sx%s vs. client: %sx%s)\n" "You may see strange behavior.\n" "Please see " "http://xpra.org/trac/ticket/10" % (avail_w, avail_h, root_w, root_h)) self._protocol._send_size = capabilities.get("packet_size", False) self.server_randr = capabilities.get("resize_screen", False) log.debug("server has randr: %s", self.server_randr) if self.server_randr: display = gtk.gdk.display_get_default() i=0 while i<display.get_n_screens(): screen = display.get_screen(i) screen.connect("size-changed", self._screen_size_changed) i += 1 e = capabilities.get("encoding") if e and e!=self.encoding: log.debug("server is using %s encoding" % e) self.encoding = e self.bell_enabled = capabilities.get("bell", False) self.notifications_enabled = capabilities.get("notifications", False) clipboard_server_support = capabilities.get("clipboard", True) self.clipboard_enabled = clipboard_server_support and self._client_extras.supports_clipboard() self.send_damage_sequence = capabilities.get("damage_sequence", False) self.can_ping = capabilities.get("ping", False) self.send_nuisance_modifiers = capabilities.get("modifiers_nuisance", False) self.mmap_enabled = self.supports_mmap and self.mmap_file and capabilities.get("mmap_enabled") if self.mmap_enabled: log.info("mmap enabled using %s", self.mmap_file) self.server_start_time = capabilities.get("start_time", -1) self.server_platform = capabilities.get("platform") #the server will have a handle on the mmap file by now, safe to delete: self.clean_mmap() #ui may want to know this is now set: self.emit("clipboard-toggled") self.key_repeat_delay, self.key_repeat_interval = capabilities.get("key_repeat", (-1,-1)) self.key_repeat_modifiers = capabilities.get("key_repeat_modifiers", False) self.emit("handshake-complete") if clipboard_server_support: #from now on, we will send a message to the server whenever the clipboard flag changes: self.connect("clipboard-toggled", self.send_clipboard_enabled_status)
import gnomekeyring import glib glib.set_application_name('Amazon daily app downloader') class Keyring(): """ Easy interface for Gnome-keyring.""" def __init__(self): if not gnomekeyring.is_available(): raise Exception("Gnome keyring not available!") self.keyring_name = gnomekeyring.get_default_keyring_sync() def set_password(self, key_name, user, password): return gnomekeyring.item_create_sync( self.keyring_name, gnomekeyring.ITEM_GENERIC_SECRET, key_name, {"user": user, "key_name": key_name}, password, True) def __get_credentials(self, key_name): try: items = gnomekeyring.find_items_sync( gnomekeyring.ITEM_GENERIC_SECRET, {"key_name": key_name}) return items[0].attributes["user"], items[0].secret except (gnomekeyring.DeniedError, gnomekeyring.NoMatchError): return None, None
import gnomekeyring import glib glib.set_application_name('Amazon daily app downloader') class Keyring(): """ Easy interface for Gnome-keyring.""" def __init__(self): if not gnomekeyring.is_available(): raise Exception("Gnome keyring not available!") self.keyring_name = gnomekeyring.get_default_keyring_sync() def set_password(self, key_name, user, password): return gnomekeyring.item_create_sync(self.keyring_name, gnomekeyring.ITEM_GENERIC_SECRET, key_name, { "user": user, "key_name": key_name }, password, True) def __get_credentials(self, key_name): try: items = gnomekeyring.find_items_sync( gnomekeyring.ITEM_GENERIC_SECRET, {"key_name": key_name}) return items[0].attributes["user"], items[0].secret except (gnomekeyring.DeniedError, gnomekeyring.NoMatchError): return None, None def get_user(self, key_name): return self.__get_credentials(key_name)[0]
def __init__(self,guifiles=[],configfile=None,mainapp=True,env=None,controlled_quit=True,dialogs=True,splash=True,debug=False,localedir='locale',pixmapsdir='pixmaps',disablenotifsys=False,forceinternalnotifsys=False,**kwargs): """ Class constructor """ # Setting up variables self.__guifiles=guifiles self.__main_app=mainapp self.__debug=debug self.__splashscreen=None self.APP_DIR=os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe().f_back))) self.PIXMAPS_DIR=self.APP_DIR + '/' + pixmapsdir self.LOCALE_DIR=self.APP_DIR + '/' + localedir # Main app initialization if mainapp: # Setup glib application name glib.set_application_name(self.metadata['APP_CODENAME']) # Set up exception handler if this is the main app self.excepthandler=_ExceptionHandler(catch_all=debug) # If controlled quit is enabled set a handler self.excepthandler.set_handler(KeyboardInterrupt,self.__control_c_handler) # Initialize notifications system if disablenotifsys: # No graphical notifications system. Fallback to dummy notification system self.notifsys=notifsystem.DummyNotificationSystem(self.metadata['APP_NAME']) else: if not forceinternalnotifsys and evogtk.HAS_PYNOTIFY: # Use PyNotify as notification system self.notifsys=notifsystem.PyNotifyNotificationSystem(self.metadata['APP_NAME']) else: # Use internal notification system self.notifsys=notifsystem.NotificationSystem(self.metadata['APP_NAME']) if splash: self.show_splash() # Create GtkBuilder instance self.__builder_instance=gtk.Builder() # Setup internationalization gettext.textdomain(self.metadata['APP_CODENAME']) gettext.bindtextdomain(self.metadata['APP_CODENAME'], self.LOCALE_DIR) gtk.glade.bindtextdomain(self.metadata['APP_CODENAME'], self.LOCALE_DIR) gtk.glade.textdomain(self.metadata['APP_CODENAME']) self.__builder_instance.set_translation_domain(self.metadata['APP_CODENAME']) # Load GUI files for guifile in guifiles: self.__builder_instance.add_from_file(self.APP_DIR + '/' + guifile) # Prepare widgets for easy access self.widgets=GUIWidgets(self.__builder_instance) # Load default widget access shortcuts self.ui=WidgetAccess(self.widgets) # Connect GUI signals self.__connect_signals() # Load shortcuts helper self.shortcuts=ShortcutsHelper(self) # Set application environment if env: self.set_environment(env) # Create preferences helper if needed if self.metadata.has_key('APP_PREFERENCES'): self.preferences=_PreferencesHelper(self.metadata['APP_PREFERENCES'],'%s/settings.conf' % self.metadata['APP_NAME'],self.ui) # Load Application preferences self.preferences.load() else: self.preferences=None # Load current icon theme self.icon_theme=gtk.icon_theme_get_default() # Set current task mode to unknown self.__current_task_mode=None # Set class as initialized self.__initialised=True self.__quit=False # Dialog module initialization if dialogs: self.dialogs=DialogFactory(self,self.widgets.winMain) # Call application initialization method passing extra parameters self.initialize(**kwargs)
# 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, see <http://www.gnu.org/licenses/> # Description: # A simple script for authorization in the mipt network # Wrote for login page present at 12 December, 2010 from urllib import urlopen from hashlib import md5 import re from sys import stderr import gnomekeyring as gk from glib import set_application_name set_application_name("Mipt-telecom login agent") def create_pass(login, password): gk.item_create_sync("login", gk.ITEM_GENERIC_SECRET, "Mipt telcom account", {"username": login}, password, True) def get_creditals(): item_keys = gk.list_item_ids_sync("login") for key in item_keys: item_info = gk.item_get_info_sync("login", key) if (item_info.get_display_name() == "Mipt telcom account"): return (gk.item_get_attributes_sync("login", key)["username"], item_info.get_secret()) return None
import getpass import glib import logging import optparse import os.path import sys try: import gnomekeyring as gk except ImportError: raise RuntimeError("gnome-keyring module is not installed on your system.") glib.set_application_name("gktool.py") def parse_kvpairs(s): """Construct and returns a dict ({key: val, ....}) from given string in format such like "key0:val0[,key1:val1,...]". >>> parse_kvpairs("key0:val0,key1:val1,key2:val2") {'key0': 'val0', 'key1': 'val1', 'key2': 'val2'} >>> parse_kvpairs("key0:val0") {'key0': 'val0'} >>> parse_kvpairs("") {} >>> parse_kvpairs(":") {} >>> parse_kvpairs("key0")
def __init__(self): global keyring self.username = None self.password = None self.multiline = False self.separator = False self.gconf = gconf.client_get_default() self.appname = "gtracker" self.username_key = "/apps/gtracker/username" self.password_key = "/apps/gtracker/password" self.interval_key = "/apps/gtracker/interval" self.multi_key = "/apps/gtracker/multiline" self.sep_key = "/apps/gtracker/separator" self.interval = self.gconf.get_int(self.interval_key) if self.interval < 1: self.interval = 15 self.gconf.set_int(self.interval_key, self.interval) self.multiline = self.gconf.get_bool(self.multi_key) if self.multiline == None: self.multiline = True self.gconf.set_bool(self.multi_key, self.multiline) self.separator = self.gconf.get_bool(self.sep_key) if self.separator == None: self.separator = True self.gconf.set_bool(self.sep_key, self.separator) if keyring: try: glib.set_application_name(self.appname) except: pass if gk.is_available(): names = gk.list_keyring_names_sync() if not self.appname in names: gk.create_sync(self.appname, "") keys = gk.list_item_ids_sync(self.appname) if len(keys) == 1: gk.unlock_sync(self.appname, "") info = gk.item_get_info_sync(self.appname, keys[0]) self.username = info.get_display_name() self.password = info.get_secret() else: self.username = "" self.password = "" else: keyring = False if not keyring: self.username = self.gconf.get_string(self.username_key) if self.username == None or len(self.username) < 1: self.username = "" self.gconf.set_string(self.username_key, "") self.password = self.gconf.get_string(self.password_key) if self.password == None or len(self.password) < 1: self.password = "" self.gconf.set_string(self.password_key, self.password) else: self.gconf.unset(self.username_key) self.gconf.unset(self.password_key)