-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
77 lines (63 loc) · 2.67 KB
/
utils.py
File metadata and controls
77 lines (63 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
/***************************************************************************
ShellDB
A QGIS plugin
Pass selected QGIS data to a shell script
-------------------
begin : 2012-01-31
copyright : (C) 2012 by Spatial Focus Inc
email : cshapiro@spatialfocus.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
from qgis.core import *
class utils:
def __init__(self,iface):
self.iface=iface
self.logfilename = "/tmp/shelldb_debug.txt"
self.logfile=None
def find_layer_by_string(self,layer_name):
"""Return a layer given its id. Might be unneccessary if I
understood the plugin API a little better."""
retVal=None
for kk in self.iface.mapCanvas().layers():
if kk.id() == layer_name:
retVal = kk
break;
return retVal
def openlog(self):
"""Open logfile."""
retVal=True
self.logfile=open(self.logfilename,"a")
return retVal
def closelog(self):
"""Close lotfile"""
self.logfile.close()
def write_dict_to_logfile(self,dict_name,dict):
"""Log contents of dictionary to logfile."""
self.openlog()
self.logfile.write("-------------------\n")
self.logfile.write("Dictionary: [%s]:\n" % (dict_name))
for kk in dict.keys():
self.logfile.write("\t[%s]:[%s]\n" % (kk,dict[kk]))
self.closelog()
def write_array_to_logfile(self,arrayname,array):
"""Log contents of an array"""
self.openlog()
self.logfile.write("Array: [%s]:\n" % (arrayname))
array_counter=0
for kk in range(0,len(array)):
self.logfile.write("\t%d: [%s]\n" % (kk,array[kk]))
self.closelog()
def write_str_to_logfile(self,str):
"""Log a string to the logfile"""
self.openlog()
self.logfile.write("***%s***\n" % (str))
self.closelog()