File: getframes.py

package info (click to toggle)
felix 1.1.1-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,992 kB
  • ctags: 1,178
  • sloc: python: 7,260; makefile: 408; sh: 58
file content (236 lines) | stat: -rwxr-xr-x 8,117 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#line 10 "interscript/src/interscript_options.ipk"
import sys
import traceback
import string
import glob
import os

from interscript.getoptions import getopt

#line 20 "interscript/src/interscript_options.ipk"
#option help dictionary
shortoptdict = { 'v':'verbose (trace everything)' }

longoptdict = {
  'weaver=': {
    'html': 'flat html',
    'latex': 'latex2e',
    'llambda': 'lambda',
    'text':'plain text',
    'web':'html tree',
    'lout':'lout'
  },

  'inhibit-sref':{
    0:'generate original src xref(default)',
    1:'inhibit generation of src xrefs'},
  'language=': 'two letter code for human language to weave (mandatory if weaver selected)',
  'tangler-prefix=':'absolute native os prefix prepended to tangled code filenames',
  'weaver-prefix=':'absolute native os prefix prepended to woven documentation filenames',
  'tangler-directory=':'interscript filename prefix prepended to tangled code filenames',
  'weaver-directory=':'interscript filename prefix prepended to woven documentation filenames',
  'python=':'execute python script',
  'update=':{
    0:'Allow buffered file write (default)',
    1:'Inhibit buffered file write'},
  'download=':{
    'never':'do not download from the Internet',
    'always':'force download by ftp or http'},
  'refresh_interval=':
    'download when local file is older than this number of days (default 28)',
  'tabwidth=':'column width for tab expansion (default 8)',
  'passes=':'passs on each file (default 1)',
  'logfile=':'<filename> for messages (append to old file)',
  'new-logfile=':'<filename> for messages (cleared first)',
  'nocache':'disable persistent cache usage',
  'copyright': '(prints) 1998 John Skaller, Australia',
  'licence': '(prints) Free for any use',
  'author': '(prints) mailto:skaller@users.sf.next <John Skaller>',
  'homepage': '(prints) http://interscript.sf.net',
  'executable': 'print python executable name',
  'python-version': 'print python version string',
  'title=':'set document title',
  'encoding=':'encoding of file, defaults to utf8',
  'test':'MUST BE FIRST: try to load interscript from current directory',
  'html-eol=': {
    'CRLF': 'Kludge Unix host (only) to end html lines (only) with CR/LF'
  },
  'trace=':{
    'frames'  : 'creation and destruction of architectural frames',
    'weavers' : 'creation and destruction of weavers',
    'tanglers': 'creation and destruction of tanglers',
    'sinks'   : 'creation and destructioin of sinks',
    'sources' : 'opening and closing of sources',
    'changes' : 'changed outputs',
    'script'  : 'execution of client script',
    'options' : 'dump options',
    'input'   : 'list all input lines',
    'cache'   : 'contents of persistent storage on loading and saving',
    'deps'    : 'source file dependency and change tracking'
  },
  'help':'this help',
  'usage':'this help' }


def print_help():
  print 'Usage: python iscr.py [options] <filename>'
  print 'Short options:'
  keys = shortoptdict.keys()
  keys.sort()
  for k in keys: print_help1(k)
  print 'Long options:'
  keys = longoptdict.keys()
  keys.sort()
  for k in keys: print_help1(k)

def print_help1(k):
  if longoptdict.has_key(k):
    usek = '--'+ k
    values = longoptdict[k]
  elif longoptdict.has_key(k+'='):
    usek = '--'+ k + '='
    values = longoptdict[k+'=']
  elif shortoptdict.has_key(k):
    usek = '-' + k
    values = shortoptdict[k]
  elif shortoptdict.has_key(k+'='):
    usek = '-' + k + '='
    values = shortoptdict[k+'=']
  else:
    usek = k
    values = 'Unknown option'

  print '  '+usek,
  if values is None:
    print
  elif type(values) is type({}):
    print
    for value in values.keys():
      print '   '+str(value)+':',values[value]
  else:
    print values

#line 125 "interscript/src/interscript_options.ipk"
class argument_frame:
  def copy(self):
     other = argument_frame()
     for k in self.__dict__.keys():
       setattr(other,k,getattr(self,k))
     return other

def getoption_frames(args): # note: has side effects!
  parsed =  getopt(args)
  process_options = argument_frame()
  process_options.logfile = None
  process_options.logfile_mode = None
  process_options.break_on_error = 0
  process_options.args = args
  process_options.trace = []
  master_frames = []

  frame = argument_frame()
  frame.update_files = 1
  frame.tabwidth = 8
  frame.download = 'regularly'
  frame.refresh_interval = 28
  frame.usecache = 1
  frame.passes = 1
  frame.weaver_prefix = ''
  frame.tangler_prefix = ''
  frame.weaver_directory= ''
  frame.tangler_directory = ''
  frame.autoweave = []
  frame.useropt = {}
  frame.encoding='utf8'
  frame.html_eol = '\n'
  frame.title = None
  frame.languages = []
  frame.inhibit_sref = 0
  for opts,filename in parsed:
    for opt,value in opts:
      try:
        if opt == 'break-on-error': process_options.break_on_error=1
        elif opt == 'v': process_options.trace = [
          'options',
          'frames',
          'input',
          'weavers',
          'tanglers',
          'lines',
          'sources',
          'sinks',
          'script',
          'cache',
          'deps']
        elif opt == 'inhibit-sref': frame.inhibit_sref = value
        elif opt == 'noupdate': frame.update_files = 0
        elif opt == 'nocache': frame.usecache = 0
        elif opt == 'nodownload': frame.download = 'never'
        elif opt == 'download': frame.download = 'always'
        elif opt == 'tabwidth': frame.tabwidth = int(value)
        elif opt == 'passes': frame.passes = int(value)
        elif opt == 'weaver': frame.autoweave.append(value)
        elif opt == 'weaver-prefix': frame.weaver_prefix = value
        elif opt == 'title': frame.title = value
        elif opt == 'tangler-prefix': frame.tangler_prefix = value
        elif opt == 'weaver-directory': frame.weaver_directory = value
        elif opt == 'language': frame.languages.append(value)
        elif opt == 'encoding': frame.encoding=value
        elif opt == 'trace': process_options.trace.append(value)
        elif opt == 'html-eol':
          if sys.platform == 'Win32':
            print 'CRLF kludge ignored for Win32'
            print 'Use on Unix only, to make html files in DOS format'
          else:
            frame.html_eol = '\r\n'
        elif opt == 'tangler-directory': frame.tangler_directory = value
        elif opt == 'homepage':
          print 'http://interscript.sf.net'
        elif opt == 'author':
          print 'mailto:skaller@users.sf.net <John Skaller>'
        elif opt == 'copyright':
          print 'Copyright (C)1998 John Skaller, Australia'
        elif opt == 'licence':
          print 'Free for any use'
        elif opt == 'executable':
          print sys.executable
        elif opt == 'python-version':
          print sys.version
        elif opt == 'python':
          try:
            if 'script' in process_options.trace:
              print 'Executing python:'
              print value
            exec value
          except:
            print 'Error in python option'
            traceback.print_exc()
        elif opt == 'logfile':
          process_options.logfile = value
          process_options.logfile_mode = 'a'
        elif opt == 'new-logfile':
          process_options.logfile = value
          process_options.logfile_mode = 'w'
        elif opt in ['help', 'usage']:
          print_help()
          print
        else:
          # FIX: all options should be OK (user options?)
          print 'Nonstandard option',opt,'value',value,'accepted as user option'
          frame.useropt[opt]=value
        if 'options' in process_options.trace: print 'Option:',opt,value
      except:
        print 'Warning: Option',opt,'has bad value',value
        prefix = ''
        while opt[0]=='-': prefix = prefix + '-'; opt=opt[1:]
        print_help1(opt)

    files = glob.glob( filename)
    for file in files:
      frame.source_prefix, frame.filename = os.path.split(file)
      if frame.source_prefix != '':
        frame.source_prefix = frame.source_prefix + os.sep
      master_frames.append(frame.copy())
  return process_options, master_frames