root/branches/tango/sss/uninstall.d

Revision 795, 3.1 kB (checked in by Jim Panic, 1 year ago)

Compiles with Tango now

Line 
1 /**
2  * DSSS command "uninstall"
3  *
4  * Authors:
5  *  Gregor Richards
6  *
7  * License:
8  *  Copyright (c) 2006, 2007  Gregor Richards
9  * 
10  *  Permission is hereby granted, free of charge, to any person obtaining a
11  *  copy of this software and associated documentation files (the "Software"),
12  *  to deal in the Software without restriction, including without limitation
13  *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  *  and/or sell copies of the Software, and to permit persons to whom the
15  *  Software is furnished to do so, subject to the following conditions:
16  * 
17  *  The above copyright notice and this permission notice shall be included in
18  *  all copies or substantial portions of the Software.
19  * 
20  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  *  DEALINGS IN THE SOFTWARE.
27  */
28
29 module sss.uninstall;
30
31 import tango.io.Console;
32 import tango.io.File;
33 import tango.io.FileConst;
34 import tango.io.FilePath;
35 import tango.io.FileSystem;
36
37 import tango.text.Util;
38
39 import sss.clean;
40 import sss.conf;
41
42 import hcf.path;
43
44 /** Entry to the "uninstall" function */
45 int uninstall(char[][] toolList, bool quiet = false)
46 {
47     if (toolList.length == 0) {
48         Cout("Uninstall what?").newline;
49         return 1;
50     }
51    
52     foreach (tool; toolList)
53     {
54         // uninstall this tool
55         char[] manifestFile = manifestPrefix ~ FileConst.PathSeparatorChar ~ tool ~ ".manifest";
56         if (!(new FilePath(manifestFile)).exists()) {
57             if (!quiet)
58                 Cout("Tool ")(tool)(" is not installed.").newline;
59             return 1;
60         }
61        
62         Cout("Uninstalling ")(tool).newline;
63        
64         // get the list
65         char[][] manifest = split(
66             cast(char[]) (new File(manifestFile)).read(),
67             "\n");
68        
69         // then delete them
70         foreach (filen; manifest) {
71             if (filen == "") continue;
72            
73             auto file = new FilePath(filen);
74            
75             // if it's not absolute, infer the absolute path
76             if (!file.isAbsolute()) {
77                 file = new FilePath(forcePrefix ~ FileConst.PathSeparatorChar ~ filen);
78                 cleanTree(file.path());
79             }
80            
81             Cout("Removing ")(file).newline;
82             tryRemove(file.toUtf8());
83         }
84        
85         Cout.newline;
86     }
87    
88     return 0;
89 }
90
91 /** Entry to the "installed" function */
92 int installed()
93 {
94     auto manifests = new FilePath(manifestPrefix);
95     foreach (pkg; manifests.toList((FilePath p, bool b) { return true; }).sort)
96     {
97         if (pkg.name.length < 9 || pkg.name[$-9 .. $]  != ".manifest") continue;
98         auto pkgName = pkg.name[0 .. $-9];
99        
100         Cout(pkgName).newline;
101     }
102    
103     return 0;
104 }
Note: See TracBrowser for help on using the browser.