svn-gvsig-desktop / branches / v2_0_0_prep / build / buildman / bin / bmplugins / DeleteFilePlugIn.py @ 27363
History | View | Annotate | Download (1.3 KB)
1 |
from bmbase.IPlugIn import IPlugIn |
---|---|
2 |
from bmbase.PlugInManager import PlugInManager |
3 |
from bmcore.BMUtil import BMUtil |
4 |
import os |
5 |
import sys |
6 |
import shutil |
7 |
|
8 |
class DeleteFilePlugIn(IPlugIn): |
9 |
def __init__(self): |
10 |
IPlugIn.__init__(self)
|
11 |
self._path = "" |
12 |
|
13 |
def init(self): |
14 |
self.addGoal("delete", "deletes a file or directory") |
15 |
self.addGoalOption("delete", "--path", "Sets the file/path to be deleted") |
16 |
execute = False
|
17 |
while self._arguments.read("delete"): |
18 |
execute = True
|
19 |
|
20 |
if execute:
|
21 |
args = [""]
|
22 |
while self._arguments.read("--path",args): |
23 |
self._path = args[0] |
24 |
|
25 |
self.setExecute(True) |
26 |
|
27 |
def initFromXML(self,node): |
28 |
if node.localName=="delete": |
29 |
if node.hasAttributes():
|
30 |
if node.attributes.has_key("path"): |
31 |
self._path = node.attributes.get("path").value |
32 |
|
33 |
def execute(self): |
34 |
print "Executing Plugin:" + str(self.__class__) |
35 |
if self._path == "": |
36 |
self.reportError("Missing required path option") |
37 |
|
38 |
self._path = os.path.abspath(self._path) |
39 |
util = BMUtil() |
40 |
if not os.path.exists(self._path): |
41 |
return True |
42 |
if os.path.isdir(self._path): |
43 |
print "* Removing directory " + self._path |
44 |
util.rmdir(self._path)
|
45 |
else:
|
46 |
print "* Removing file " + self._path |
47 |
os.remove(self._path)
|
48 |
|
49 |
return True |
50 |
|
51 |
PlugInManager().registerPlugIn("DeleteFilePlugIn",DeleteFilePlugIn())
|
52 |
|
53 |
|