~ubuntu-branches/ubuntu/quantal/usb-modeswitch/quantal

« back to all changes in this revision

Viewing changes to debian/mkrules.py

  • Committer: Bazaar Package Importer
  • Author(s): Didier Raboud
  • Date: 2009-11-03 11:02:31 UTC
  • Revision ID: james.westby@ubuntu.com-20091103110231-6ldcm8jt48x39qix
Tags: 1.0.5-1
* New 1.0.5 upstream version
  - Configurations are now stored in independent files under
    /etc/usb_modeswitch.d/
  - The devices detection is greatly improved by having a broader set of
    detection fields (Closes: #527122).
  - Two new binaries: usb_modeswitch_sh and usb_modeswitch_tcl.
* Adaptation to new upstream:
  - Add tclsh to Depends.
  - Drop mkrules.py and thus python B-D (Closes: #535445).
  - Update manpage to 1.0.5 (add --version)
* Patches:
  - 01_correct_broken_huawei_conf.patch : refresh. 
  - 02_umconf_is_no_exec.patch          : remove, merged upstream.
  - 03_build_system_to_policy.patch     : refresh.
  - 04_convert_umconf_to_unicode.patch  : Add to get everything in utf-8.
                                          Thanks to W. Martin Borgert.
  - 05_move_wrappers_to_usr.patch       : Add. Moves wrappers to specific
                                          /usr/share/usb_modeswitch
  - 06_disables_rules.patch             : Add to get the udev rules "opt-in"
                                          (See NEWS.Debian)
  - Add headers to make them all comply to DEP-3 Patch Tagging Guidelines.
* Bump Standards-Version to 3.8.3
  - Add README.source.
* Document the major changes in NEWS.Debian
* Switch to source format 3.0 (quilt). Drop quilt Build-Dep and dh snippet.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
 
3
 
import fileinput
4
 
 
5
 
## Common variables
6
 
commentBlock = False
7
 
 
8
 
configIndex = -1
9
 
 
10
 
configList = [{}]
11
 
 
12
 
optionMap = {
13
 
        'DefaultVendor': ' --default-vendor ',
14
 
        'DefaultProduct': ' --default-product ',
15
 
        'TargetVendor': ' --target-vendor ',
16
 
        'TargetProduct': ' --target-product ',
17
 
        'TargetClass': ' --target-class ',
18
 
        'MessageEndpoint': ' --message-endpoint ',
19
 
        'MessageContent': ' --message-content ',
20
 
        'ResponseEndpoint': ' --response-endpoint ',
21
 
        'DetachStorageOnly': ' --detach-storage-only ',
22
 
        'HuaweiMode': ' --huawei-mode ',
23
 
        'SierraMode': ' --sierra-mode ',
24
 
        'SonyMode': ' --sony-mode ',
25
 
        'ResetUSB': ' --reset-usb ',
26
 
        'Interface': ' --interface ',
27
 
        'Configuration': ' --configuration ',
28
 
        'AltSetting': ' --altsetting '
29
 
}
30
 
 
31
 
# Go through the whole file
32
 
for line in fileinput.input():
33
 
        # Take widely commented lines 
34
 
        if line[0:4] == '####':
35
 
                configIndex += 1
36
 
                configList += [{}]
37
 
                commentBlock = True
38
 
                configList[configIndex]['Comment'] = line
39
 
                continue
40
 
        if line[0] == '#' and commentBlock:
41
 
                configList[configIndex]['Comment'] += line
42
 
                continue
43
 
        if len(line) < 1:
44
 
                commentBlock = False
45
 
                continue
46
 
 
47
 
        # Take only lines with actual configuration
48
 
        if line[0] == ';':
49
 
                # We have a variable
50
 
 
51
 
                # Where does the variable end ?
52
 
                equalPos = line.find('=')
53
 
                
54
 
                variableName = line[1:equalPos]
55
 
                variableContent = line[equalPos+1:-1].strip()
56
 
                
57
 
                # print variableName,"=",variableContent
58
 
 
59
 
                configList[configIndex][variableName] = variableContent
60
 
 
61
 
print '''### /etc/udev/rules.d/usb_modeswitch.rules ###
62
 
# This file is generated from /etc/usb_modeswitch.conf
63
 
#
64
 
# For multiply-defined ID, only the first one is uncommented.
65
 
# Other ones are available but commented.
66
 
#
67
 
 
68
 
'''
69
 
def um_comAdd(indic, indivConfig, toggle=False):
70
 
        if indic in indivConfig:
71
 
                if not toggle:
72
 
                        return optionMap[indic] + indivConfig[indic]
73
 
                else:
74
 
                        return optionMap[indic]
75
 
        else:
76
 
                return ''
77
 
 
78
 
# Now we have everything needed in configList
79
 
uniqIds = {}
80
 
for indivConfig in configList:
81
 
        if 'DefaultVendor' in indivConfig and 'DefaultProduct' in indivConfig:
82
 
                uniqId = indivConfig['DefaultVendor'] + ":" + indivConfig['DefaultProduct']
83
 
                print indivConfig['Comment'],
84
 
                
85
 
                print '# Vendor:Product id =',uniqId
86
 
 
87
 
                um_commandline  = '/usr/sbin/usb_modeswitch'
88
 
                um_commandline += um_comAdd('DefaultVendor',indivConfig)
89
 
                um_commandline += um_comAdd('DefaultProduct',indivConfig)
90
 
                um_commandline += um_comAdd('MessageEndpoint', indivConfig)
91
 
                if 'MessageContent' in indivConfig:
92
 
                        um_commandline += optionMap['MessageContent'] +  indivConfig['MessageContent'][1:-1]
93
 
                um_commandline += um_comAdd('ResponseEndpoint', indivConfig)
94
 
                um_commandline += um_comAdd('DetachStorageOnly', indivConfig, True)
95
 
                um_commandline += um_comAdd('Interface', indivConfig)
96
 
 
97
 
                ruleLine  = 'SUBSYSTEM=="usb", '
98
 
                ruleLine += 'SYSFS{idVendor}=="' + indivConfig['DefaultVendor'][2:] +'", '
99
 
                ruleLine += 'SYSFS{idProduct}=="' + indivConfig['DefaultProduct'][2:] + '", '
100
 
                ruleLine += 'RUN+="' + um_commandline + '"'
101
 
 
102
 
                if uniqId not in uniqIds:
103
 
                        uniqIds[uniqId] = ''
104
 
                        print ruleLine
105
 
                else:
106
 
                        print '#' + ruleLine
107
 
                print '' 
108