Ejemplo n.º 1
0
def main():
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    parser = argparse.ArgumentParser()
    parser.add_argument('attach', type=str, nargs='?', help='attach file to new note')
    parser.add_argument('--open', type=int, help='open note')
    parser.add_argument('--create', action='store_true', help='create new note')
    parser.add_argument('--all-notes', action='store_true', help='show all notes window')
    parser.add_argument('--settings', action='store_true', help='settings and management')
    parser.add_argument('--replace', action='store_true', help='replace already runned')
    parser.add_argument('--version', '-v', action='store_true', help='show version')
    args = parser.parse_args(sys.argv[1:])
    if args.version:
        print_version()
    if args.replace:
        try:
            pad = get_pad()
            pad.kill()
        except dbus.exceptions.DBusException:
            pass
    fp = open('/tmp/everpad-%s.lock' % getpass.getuser(), 'w')
    try:
        fcntl.lockf(fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
        app = PadApp(sys.argv)
        app.setApplicationName('everpad')
        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
        session_bus = dbus.SessionBus()
        app.provider = get_provider(session_bus)
        app.provider.connect_to_signal(
            'sync_state_changed',
            app.on_sync_state_changed,
            dbus_interface="com.everpad.provider",
        )
        app.launcher = get_launcher('application://everpad.desktop', session_bus, '/')
        bus = dbus.service.BusName("com.everpad.App", session_bus)
        service = EverpadService(app, session_bus, '/EverpadService')
        if args.open:
            app.indicator.open(args.open)
        if args.create:
            app.indicator.create()
        if args.settings:
            app.indicator.show_management()
        if args.attach:
            app.indicator.create(args.attach)
        if args.all_notes:
            app.indicator.show_all_notes()
        app.exec_()
    except IOError:
        pad = get_pad()
        if args.open:
            pad.open(args.open)
        if args.create:
            pad.create()
        if args.settings:
            pad.settings()
        if args.attach:
            pad.create_wit_attach(args.attach)
        if args.all_notes:
            pad.all_notes()
        sys.exit(0)
Ejemplo n.º 2
0
def main():
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    parser = argparse.ArgumentParser()
    parser.add_argument("attach", type=str, nargs="?", help="attach file to new note")
    parser.add_argument("--open", type=int, help="open note")
    parser.add_argument("--create", action="store_true", help="create new note")
    parser.add_argument("--all-notes", action="store_true", help="show all notes window")
    parser.add_argument("--settings", action="store_true", help="settings and management")
    parser.add_argument("--replace", action="store_true", help="replace already runned")
    parser.add_argument("--version", "-v", action="store_true", help="show version")
    args = parser.parse_args(sys.argv[1:])
    if args.version:
        print_version()
    if args.replace:
        try:
            pad = get_pad()
            pad.kill()
        except dbus.exceptions.DBusException:
            pass
    fp = open("/tmp/everpad-%s.lock" % getpass.getuser(), "w")
    try:
        fcntl.lockf(fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
        app = PadApp(sys.argv)
        app.setApplicationName("everpad")
        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
        session_bus = dbus.SessionBus()
        app.provider = get_provider(session_bus)
        app.provider.connect_to_signal(
            "sync_state_changed", app.on_sync_state_changed, dbus_interface="com.everpad.provider"
        )
        app.provider.connect_to_signal("data_changed", app.on_data_changed, dbus_interface="com.everpad.provider")
        app.launcher = get_launcher("application://everpad.desktop", session_bus, "/")
        bus = dbus.service.BusName("com.everpad.App", session_bus)
        service = EverpadService(session_bus, "/EverpadService")
        if args.open:
            app.indicator.open(args.open)
        if args.create:
            app.indicator.create()
        if args.settings:
            app.indicator.show_management()
        if args.attach:
            app.indicator.create(args.attach)
        if args.all_notes:
            app.indicator.show_all_notes()
        app.exec_()
    except IOError:
        pad = get_pad()
        if args.open:
            pad.open(args.open)
        if args.create:
            pad.create()
        if args.settings:
            pad.settings()
        if args.attach:
            pad.create_wit_attach(args.attach)
        if args.all_notes:
            pad.all_notes()
        sys.exit(0)