author | mickeyl <mickeyl> | 2003-05-17 13:03:18 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-05-17 13:03:18 (UTC) |
commit | 6e3480b56d8962592e946f779ed9249749cf8dbb (patch) (unidiff) | |
tree | 1c59afc6fcb4245484e08275210418e099026baa /scripts/mkHelpSkeleton | |
parent | 6e75925dbe2e26a12f97dd7f1e90d889127e2294 (diff) | |
download | opie-6e3480b56d8962592e946f779ed9249749cf8dbb.zip opie-6e3480b56d8962592e946f779ed9249749cf8dbb.tar.gz opie-6e3480b56d8962592e946f779ed9249749cf8dbb.tar.bz2 |
For Zecke: script assisting in making help file skeletons
(took me an hour - like i said :-)
-rwxr-xr-x | scripts/mkHelpSkeleton | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/scripts/mkHelpSkeleton b/scripts/mkHelpSkeleton new file mode 100755 index 0000000..ffb21c2 --- a/dev/null +++ b/scripts/mkHelpSkeleton | |||
@@ -0,0 +1,118 @@ | |||
1 | #!/usr/bin/env python | ||
2 | """ | ||
3 | This skript creates a help skeleton for a certain application | ||
4 | (C) Michael 'Mickey' Lauer who did this even if he had a lot of other stuff to do... | ||
5 | """ | ||
6 | |||
7 | import os | ||
8 | import sys | ||
9 | |||
10 | COUNTRYCODES = "da de en fr nl pl hu no pt it pt_BR ja sl zh_CN es ko zh_TW".split() | ||
11 | OPIEDIR = os.environ["OPIEDIR"] | ||
12 | |||
13 | #Package: opie-appskey-help-en | ||
14 | #Files: help/en/html/opie-appskey.html | ||
15 | #Priority: optional | ||
16 | #Section: opie/onlinedoc | ||
17 | #Maintainer: ljp <llornkcor@handhelds.org> | ||
18 | #Architecture: arm | ||
19 | #Version: $QPE_VERSION-$SUB_VERSION | ||
20 | #Depends: opie-appskey | ||
21 | #License: GPL | ||
22 | #Description: Application Key help files (english) | ||
23 | |||
24 | def doit( name, cc ): | ||
25 | """Create a help skeleton corresponding to a package described by a desktop file.""" | ||
26 | |||
27 | desktop = {} | ||
28 | for line in file( name ): | ||
29 | try: | ||
30 | key, value = line.split( '=' ) | ||
31 | except ValueError: | ||
32 | pass | ||
33 | else: | ||
34 | desktop[key.strip()] = value.strip() | ||
35 | |||
36 | try: | ||
37 | application = desktop["Exec"] | ||
38 | except: | ||
39 | fail( "No Exec given in .desktop file" ) | ||
40 | |||
41 | print "Generating help skeleton for application '%s'..." % application | ||
42 | helpdirname = "%s/help/%s/html" % ( OPIEDIR, cc ) | ||
43 | helpappdirname = "%s/%s" % ( helpdirname, application ) | ||
44 | makecontrol( helpdirname, application, cc, desktop ) | ||
45 | makedir( helpappdirname ) | ||
46 | makehtml( helpdirname, application, cc, desktop ) | ||
47 | |||
48 | #------------------------------------------------------# | ||
49 | def makehtml( directory, application, cc, desktop ): | ||
50 | """Creates the help template file.""" | ||
51 | |||
52 | helpfilename = "%s/opie-%s.html" % ( directory, application ) | ||
53 | print "Creating help file '%s'" % helpfilename | ||
54 | h = file( helpfilename, "w" ) | ||
55 | print >> h, """ | ||
56 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> | ||
57 | <html> <head> <title>%s</title> </head> | ||
58 | <body> | ||
59 | <center><h1>%s</h1></center> | ||
60 | <hr> | ||
61 | </body> | ||
62 | </html> | ||
63 | """ % ( application, application ) | ||
64 | |||
65 | #------------------------------------------------------# | ||
66 | def makecontrol( directory, application, cc, desktop ): | ||
67 | """Creates the .control file.""" | ||
68 | |||
69 | controlfilename = "%s/opie-%s-help-%s.control" % ( directory, application, cc ) | ||
70 | print "Creating control file '%s'" % controlfilename | ||
71 | c = file( controlfilename, "w" ) | ||
72 | print >> c, "Package: opie-%s-help-%s" % ( application, cc ) | ||
73 | print >> c, "Files: help/%s/html/opie-%s.html help/%s/html/%s" % ( cc, application, cc, application ) | ||
74 | print >> c, "Priority: optional" | ||
75 | print >> c, "Section: opie/onlinedoc" | ||
76 | print >> c, "Maintainer: %s" % desktop.get( "Maintainer", "Team Opie <opie@handhelds.org>" ) | ||
77 | print >> c, "Version: $QPE_VERSION-$SUB_VERSION" | ||
78 | print >> c, "Depends: opie-%s" % application | ||
79 | print >> c, "License: GPL" | ||
80 | print >> c, "Description: %s help files (%s)" % ( application, cc ) | ||
81 | |||
82 | #------------------------------------------------------# | ||
83 | def makedir( name ): | ||
84 | """Creates a directory.""" | ||
85 | |||
86 | print "Creating directory '%s'" % name | ||
87 | if not os.path.exists( name ): os.mkdir( name ) | ||
88 | |||
89 | #------------------------------------------------------# | ||
90 | def fail( reason ): | ||
91 | """Fails with a reason.""" | ||
92 | print reason | ||
93 | sys.exit( -1 ) | ||
94 | |||
95 | #------------------------------------------------------# | ||
96 | def checkUsage( args ): | ||
97 | """Checks calling syntax.""" | ||
98 | |||
99 | if len( args ) < 2: | ||
100 | fail( """ | ||
101 | Usage: %s <application>.desktop [countrycode] | ||
102 | |||
103 | If no countrycode is given, defaults to 'en' | ||
104 | If countrycode 'all' is given, generates skeletons | ||
105 | for all known countrycodes: %s""" % ( args[0], ", ".join( COUNTRYCODES ) ) ) | ||
106 | |||
107 | #------------------------------------------------------# | ||
108 | |||
109 | if __name__ == "__main__": | ||
110 | checkUsage( sys.argv ) | ||
111 | |||
112 | if len ( sys.argv ) == 2: | ||
113 | doit( sys.argv[1], "en" ) | ||
114 | elif len( sys.argv ) == 3: | ||
115 | if sys.argv[2] == "all": | ||
116 | [ doit( sys.argv[1], x ) for x in split() ] | ||
117 | else: | ||
118 | doit( sys.argv[1], sys.argv[2] ) | ||