| 1 |
#! /usr/bin/env python |
|---|
| 2 |
|
|---|
| 3 |
################################################################################ |
|---|
| 4 |
# Authors: Brian Schott (Sir Alaran) |
|---|
| 5 |
# Copyright: Brian Schott (Sir Alaran) |
|---|
| 6 |
# Date: Sep 24 2009 |
|---|
| 7 |
# License: |
|---|
| 8 |
# |
|---|
| 9 |
# This program is free software: you can redistribute it and/or modify |
|---|
| 10 |
# it under the terms of the GNU General Public License as published by |
|---|
| 11 |
# the Free Software Foundation, either version 3 of the License, or |
|---|
| 12 |
# (at your option) any later version. |
|---|
| 13 |
# |
|---|
| 14 |
# This program is distributed in the hope that it will be useful, |
|---|
| 15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 |
# GNU General Public License for more details. |
|---|
| 18 |
# |
|---|
| 19 |
# You should have received a copy of the GNU General Public License |
|---|
| 20 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 21 |
################################################################################ |
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
from __future__ import print_function |
|---|
| 25 |
|
|---|
| 26 |
import logging |
|---|
| 27 |
import getopt |
|---|
| 28 |
import sys |
|---|
| 29 |
if sys.hexversion < 0x020600f0: |
|---|
| 30 |
print("Please upgrade to Python 2.6. It is necessary for JSON file I/O") |
|---|
| 31 |
|
|---|
| 32 |
import pygtk |
|---|
| 33 |
import gtk |
|---|
| 34 |
|
|---|
| 35 |
import arcmap.window |
|---|
| 36 |
import arcmap.preferences |
|---|
| 37 |
|
|---|
| 38 |
def setLogging(l, f): |
|---|
| 39 |
logging.basicConfig(level=l, format="%(levelname)5s %(name)8s %(lineno)4d: %(message)s", |
|---|
| 40 |
datefmt="%d %b %Y", filename=f, filemode="w") |
|---|
| 41 |
|
|---|
| 42 |
def printUsage(): |
|---|
| 43 |
print( |
|---|
| 44 |
"""Usage: {0} (options) file |
|---|
| 45 |
Options: |
|---|
| 46 |
-h, --help Print this message |
|---|
| 47 |
-d, --debug=level Set debug logging level |
|---|
| 48 |
Can be debug, info, warn, error or |
|---|
| 49 |
critical |
|---|
| 50 |
-lf, --logfile=file Set log file""".format(sys.argv[0])) |
|---|
| 51 |
|
|---|
| 52 |
def getDebugLevel(string): |
|---|
| 53 |
d = { |
|---|
| 54 |
"debug" : logging.DEBUG, |
|---|
| 55 |
"info" : logging.INFO, |
|---|
| 56 |
"warn" : logging.WARN, |
|---|
| 57 |
"error" : logging.ERROR, |
|---|
| 58 |
"critical" : logging.CRITICAL |
|---|
| 59 |
} |
|---|
| 60 |
if string not in d: |
|---|
| 61 |
return logging.WARN |
|---|
| 62 |
else: |
|---|
| 63 |
return d[string] |
|---|
| 64 |
|
|---|
| 65 |
def main(): |
|---|
| 66 |
# Setup the logging first |
|---|
| 67 |
try: |
|---|
| 68 |
options, arguments = getopt.getopt(sys.argv[1:], "hd:l:", |
|---|
| 69 |
["help", "debug=", "logfile="]) |
|---|
| 70 |
except getopt.GetoptError, err: |
|---|
| 71 |
print(str(err)) |
|---|
| 72 |
printUsage() |
|---|
| 73 |
sys.exit(2) |
|---|
| 74 |
|
|---|
| 75 |
logFile = None |
|---|
| 76 |
fileName = None |
|---|
| 77 |
debugLevel = logging.NOTSET |
|---|
| 78 |
|
|---|
| 79 |
for o, a in options: |
|---|
| 80 |
if o in ("-h", "--help"): |
|---|
| 81 |
printUsage() |
|---|
| 82 |
return |
|---|
| 83 |
elif o in ("-d", "--debug"): |
|---|
| 84 |
debugLevel = getDebugLevel(a) |
|---|
| 85 |
elif o in ("-l", "--logfile"): |
|---|
| 86 |
logFile = a |
|---|
| 87 |
else: |
|---|
| 88 |
print("unhandled option") |
|---|
| 89 |
return |
|---|
| 90 |
|
|---|
| 91 |
setLogging(debugLevel, logFile) |
|---|
| 92 |
|
|---|
| 93 |
if len(sys.argv) > 1: |
|---|
| 94 |
fileName = sys.argv[1] |
|---|
| 95 |
|
|---|
| 96 |
arcmap.preferences.load() |
|---|
| 97 |
w = arcmap.window.MainWindow(fileName) |
|---|
| 98 |
gtk.main() |
|---|
| 99 |
|
|---|
| 100 |
if __name__ == "__main__": |
|---|
| 101 |
main() |
|---|