()
| 139 | |
| 140 | |
| 141 | def main(): |
| 142 | options = "bahnd:" |
| 143 | long_opts = ['binary', 'ascii', 'help', 'no-encode', 'output-dir='] |
| 144 | |
| 145 | try: |
| 146 | opts, args = getopt.getopt(sys.argv[1:], options, long_opts) |
| 147 | except getopt.error(msg): |
| 148 | print(msg) |
| 149 | print(usage()) |
| 150 | print('-'*70) |
| 151 | print(msg) |
| 152 | sys.exit(1) |
| 153 | |
| 154 | mode = 'p' |
| 155 | encode = 1 |
| 156 | out_dir = None |
| 157 | for o, a in opts: |
| 158 | if o in ('-h', '--help'): |
| 159 | print(usage()) |
| 160 | sys.exit(0) |
| 161 | if o in ('-b', '--binary'): |
| 162 | mode = 'b' |
| 163 | if o in ('-a', '--ascii'): |
| 164 | mode = 'a' |
| 165 | if o in ('-n', '--no-encode'): |
| 166 | encode = 0 |
| 167 | if o in ('-d', '--output-dir'): |
| 168 | out_dir = a |
| 169 | if not os.path.exists(out_dir): |
| 170 | print("Error: Directory %s does not exist!"%out_dir) |
| 171 | sys.exit(1) |
| 172 | |
| 173 | if len(args) < 1: |
| 174 | print("\nError: Incorrect number of arguments\n") |
| 175 | print(usage()) |
| 176 | sys.exit(1) |
| 177 | |
| 178 | for i in args: |
| 179 | r, w = getReaderWriter(i, out_dir) |
| 180 | if not r: |
| 181 | print("\nError: Could not convert file: %s"%i) |
| 182 | print("Unsupported data format!\n") |
| 183 | else: |
| 184 | o = setAllAttributes(r) |
| 185 | w.SetInputData(o) |
| 186 | # set output modes |
| 187 | if mode == 'a': |
| 188 | w.SetDataModeToAscii() |
| 189 | elif mode == 'b': |
| 190 | w.SetDataModeToBinary() |
| 191 | else: |
| 192 | w.SetDataModeToAppended() |
| 193 | |
| 194 | w.SetEncodeAppendedData(encode) |
| 195 | w.Write() |
| 196 | |
| 197 | |
| 198 | if __name__ == "__main__": |
no test coverage detected