349 ############################################################################### |
349 ############################################################################### |
350 ## functions for version handling |
350 ## functions for version handling |
351 ############################################################################### |
351 ############################################################################### |
352 |
352 |
353 |
353 |
354 def versionToTuple(version): |
354 def versionToTuple(version, length=3): |
355 """ |
355 """ |
356 Module function to convert a version string into a tuple. |
356 Module function to convert a version string into a tuple. |
357 |
357 |
358 Note: A version string consists of non-negative decimals separated by "." |
358 Note: A version string consists of non-negative decimals separated by "." |
359 optionally followed by a suffix. Suffix is everything after the last |
359 optionally followed by a suffix. Suffix is everything after the last |
360 decimal. |
360 decimal. |
361 |
361 |
362 @param version version string |
362 @param version version string |
363 @type str |
363 @type str |
|
364 @param length desired length of the version tuple |
|
365 @type int |
364 @return version tuple without the suffix |
366 @return version tuple without the suffix |
365 @rtype tuple of int |
367 @rtype tuple of int |
366 """ |
368 """ |
367 versionParts = [] |
369 versionParts = [] |
368 |
370 |
369 # step 1: extract suffix |
371 # step 1: extract suffix |
370 version = re.split(r"[^\d.]", version)[0] |
372 version = re.split(r"[^\d.]", version)[0] |
371 for part in version.split("."): |
373 for part in version.split("."): |
372 versionParts.append(int(part)) |
374 versionParts.append(int(part)) |
373 |
375 versionParts.extend([0] * length) |
374 return tuple(versionParts) |
376 |
|
377 return tuple(versionParts[:length]) |
375 |
378 |
376 |
379 |
377 def qVersionTuple(): |
380 def qVersionTuple(): |
378 """ |
381 """ |
379 Module function to get the Qt version as a tuple. |
382 Module function to get the Qt version as a tuple. |