File: getoptions.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 (36 lines) | stat: -rwxr-xr-x 871 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
#line 10 "interscript/src/options.ipk"
import re

longopts=re.compile('^--([A-Za-z][-A-Za-z_0-9]*)(?:=(.*))?$')
shortopts=re.compile('^-([A-Za-z]+)(?:=(.*))?$')


def getopt(args):
  wordno = 0
  result = []
  opts=[]
  while wordno<len(args):
    filename = ''
    word = args[wordno]
    #print 'word',word,
    match = longopts.match(word)
    if match:
      opts.append((match.group(1),match.group(2)))
      #print ':longopt'
    else:
      match = shortopts.match(word)
      if match:
        #print ':shortopt'
        for letter in match.group(1)[:-1]:
          opts.append((letter,None))
        opts.append((match.group(1)[-1],match.group(2)))
      else:
        #print ':filename'
        filename = args[wordno]
        result.append((opts,filename))
        opts=[]
    wordno = wordno + 1

  if opts:
    result.append((opts,filename))
  return result