This repository was archived by the owner on May 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgnoteroctrl
executable file
·59 lines (46 loc) · 2.01 KB
/
gnoteroctrl
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
#!/usr/bin/env python
"""
This file is part of Gnotero.
Gnotero is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gnotero 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with Gnotero. If not, see <http://www.gnu.org/licenses/>.
"""
import socket
import optparse
import sys
# Parse the command line options
parser = optparse.OptionParser("usage: gnoteroctrl [options]")
parser.set_defaults(search = "")
parser.set_defaults(activate = False)
parser.set_defaults(port = 43250)
parser.set_defaults(host = "localhost")
group = optparse.OptionGroup(parser, "Control Gnotero")
group.add_option("-s", "--search", action = "store", dest = "search", help = "Show Gnotero and perform a search")
group.add_option("-a", "--activate", action = "store_true", dest = "activate", help = "Show Gnotero")
parser.add_option_group(group)
group = optparse.OptionGroup(parser, "Connection parameters")
group.add_option("-p", "--port", action = "store", dest = "port", help = "Connection port (default = 43250)")
group.add_option("-o", "--host", action = "store", dest = "host", help = "Gnotero host (default = localhost)")
parser.add_option_group(group)
options, args = parser.parse_args(sys.argv)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
cmd = ""
if options.search != "":
cmd = "search %s" % options.search
elif options.activate:
cmd = "activate"
else:
print "gnoteroctrl: see gnoteroctrl --help for instructions"
quit()
try:
sock.sendto(cmd, (options.host, options.port) )
print "gnoteroctrl: sending '%s' to %s:%d" % (cmd, options.host, options.port)
except:
print "gnoteroctrl: failed to connect to Gnotero"