File: CommandLineParser.py

package info (click to toggle)
scribes 0.4~r543-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 6,836 kB
  • ctags: 6,779
  • sloc: python: 32,963; perl: 2,747; xml: 2,233; sh: 847; makefile: 597
file content (82 lines) | stat: -rw-r--r-- 2,387 bytes parent folder | download
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
from gettext import gettext as _

class Parser(object):

	def __init__(self):
		self.__init_attributes()
		self.__add_options()
		self.__args = self.__parser.parse_args()[-1]

	def __init_attributes(self):
		from optparse import OptionParser
		self.__parser = OptionParser(usage=_("usage: %prog [OPTION...] [FILE...]"),
			description=_("%prog is a text editor for GNOME.\n\n http://scribes.sf.net/"),
			)
		self.__args = []
		self.__readonly = False
		self.__encoding = "utf-8"
		self.__newfile = False
		return

	args = property(lambda self: self.__args)
	readonly = property(lambda self: self.__readonly)
	encoding = property(lambda self: self.__encoding)
	newfile = property(lambda self: self.__newfile)

	def __add_options(self):
		parser = self.__parser
		parser.add_option("-v", "--version",
			help=_("display the version of Scribes currently running"),
			action="callback",
			callback=self.__print_version)
		parser.add_option("-i", "--info",
			help=_("display detailed information about Scribes"),
			action="callback",
			callback=self.__print_info)
		parser.add_option("-n", "--newfile",
			help=_("create a new file and open the file in Scribes"),
			action="callback",
			callback=self.__create_newfile)
		parser.add_option("-e", "--encoding",
			help=_("open file(s) with specified encoding"),
			action="callback",
			callback=self.__use_encoding)
		parser.add_option("-r", "--readonly",
			help=_("open file(s) in readonly mode"),
			action="callback",
			callback=self.__enable_readonly)
		return

	def __print_version(self, *args):
		from Globals import version
		from i18n import msg0042
		from locale import getpreferredencoding
		encoding = getpreferredencoding(True)
		print msg0042.decode("utf-8").encode(encoding) % version.encode(encoding, "replace")
		raise SystemExit
		return False

	def __print_info(self, *args):
		from CommandLineInfo import print_info
		print_info()
		raise SystemExit
		return False

	def __create_newfile(self, *args):
		if not self.__args: return False
		self.__newfile = True
		return False

	def __use_encoding(self, *args):
		if not self.__args: return False
		self.__encoding = "utf-8"
		print "ERROR: NOT YET IMPLEMENTED"
		raise SystemExit
		return False

	def __enable_readonly(self, *args):
		if not self.__args: return False
		self.__readonly = True
		print "ERROR: NOT YET IMPLEMENTED"
		raise SystemExit
		return False