/usr/bin/odfuserfield is in python-odf 1.2.0-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 | #!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (C) 2006-2007 Søren Roug, European Environment Agency
#
# This is free software. You may redistribute it under the terms
# of the Apache license and the GNU General Public License Version
# 2 or at your option any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Contributor(s): Michael Howitz, gocept gmbh & co. kg
import sys
import getopt
import odf.userfield
listfields = False
Listfields = False
xfields = []
Xfields = []
setfields = {}
outputfile = None
inputfile = None
def exitwithusage(exitcode=2):
""" print out usage information """
sys.stderr.write("Usage: %s [-lL] [-xX metafield] [-s metafield:value]... "
"[-o output] [inputfile]\n" % sys.argv[0])
sys.stderr.write("\tInputfile must be OpenDocument format\n")
sys.exit(exitcode)
try:
opts, args = getopt.getopt(sys.argv[1:], "lLs:o:x:X:")
except getopt.GetoptError:
exitwithusage()
if len(opts) == 0:
exitwithusage()
for o, a in opts:
if o == '-s':
if a.find(":") >= 0:
k,v = a.split(":",1)
else:
k,v = (a, "")
if len(k) == 0:
exitwithusage()
setfields[k] = unicode(v, 'utf-8')
if o == '-l':
listfields = True
Listfields = False
if o == '-L':
Listfields = True
listfields = False
if o == "-x":
xfields.append(a)
if o == "-X":
Xfields.append(a)
if o == "-o":
outputfile = a
if len(args) != 0:
inputfile = args[0]
user_fields = odf.userfield.UserFields(inputfile, outputfile)
if xfields:
for value in user_fields.list_values(xfields):
print value
if Listfields or Xfields:
if Listfields:
Xfields = None
for field_name, value_type, value in user_fields.list_fields_and_values(
Xfields):
print "%s#%s:%s" % (field_name, value_type, value)
if listfields:
for value in user_fields.list_fields():
print value
if setfields:
user_fields.update(setfields)
|