|
| 1 | +#!/usr/bin/python |
| 2 | +""" |
| 3 | +/*************************************************************************** |
| 4 | + contxt_help_id.py |
| 5 | + ------------------- |
| 6 | + begin : 2009-11-16 |
| 7 | + copyright : (C) 2009 by Gary E.Sherman |
| 8 | + email : gsherman at mrcc.com |
| 9 | + ***************************************************************************/ |
| 10 | +
|
| 11 | +/*************************************************************************** |
| 12 | + * * |
| 13 | + * This program is free software; you can redistribute it and/or modify * |
| 14 | + * it under the terms of the GNU General Public License as published by * |
| 15 | + * the Free Software Foundation; either version 2 of the License, or * |
| 16 | + * (at your option) any later version. * |
| 17 | + * * |
| 18 | + ***************************************************************************/ |
| 19 | +
|
| 20 | + This script generates a unique context id based for use in the QGIS |
| 21 | + context sensitive help system. It uses the SHA1 hash for the class name |
| 22 | + and converts the first 12 characters to a unique integer. |
| 23 | +
|
| 24 | + To create a context id, pass the name of the QGIS class on the command line. |
| 25 | + Example: |
| 26 | + ./context_help_id.py QgsAbout |
| 27 | +
|
| 28 | + This script requires Python 2.5 or higher (hashlib was introduced at 2.5). |
| 29 | +
|
| 30 | + NOTE: Due to a change in the way context ids are generated, ids |
| 31 | + generated by the old method (Java hashCode function) will be different than |
| 32 | + the id generated by the new method for the same class. |
| 33 | +""" |
| 34 | +import hashlib |
| 35 | +import sys |
| 36 | +# check to see if a class name was specified and if so, craete the context id |
| 37 | +if len(sys.argv) > 1: |
| 38 | + hash = hashlib.sha1() |
| 39 | + # set the hash to the name passed on the command line |
| 40 | + hash.update(sys.argv[1]) |
| 41 | + # generate the context id by converting the first 12 characters of the hash |
| 42 | + # to decimal |
| 43 | + context_id = int(hash.hexdigest()[:12],16) |
| 44 | + # print the result |
| 45 | + print context_id |
| 46 | +else: |
| 47 | + # if no class name was specified, give a bit of help |
| 48 | + print "To generate a context sensitive help id, specify the QGIS class name on the command line" |
0 commit comments