1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.millscript.millscript.apps.website;
22
23 import org.millscript.commons.vfs.VFS;
24 import org.millscript.commons.vfs.VFolder;
25 import org.millscript.millscript.conf.Configuration;
26 import org.millscript.millscript.conf.WebsiteConf;
27
28 import java.io.IOException;
29 import java.io.Reader;
30 import java.util.Iterator;
31
32 import com.townleyenterprises.command.CommandOption;
33
34
35 /**
36 *
37 *
38 */
39 public class StatusCommandOption extends CommandOption {
40
41 Configuration websiteConf = new WebsiteConf();
42
43 /**
44 *
45 */
46 public StatusCommandOption() {
47 super( "status", 's', true, "<dir>", "Show status of websites in <dir>", "." );
48 }
49
50 /**
51 * @see com.townleyenterprises.command.CommandOption#execute()
52 */
53 @Override
54 public void execute() throws Exception {
55 VFS vfs = new VFS();
56 VFolder cwd = vfs.getCurrentWorkingFolder();
57
58 this.status( cwd );
59 }
60
61 boolean isAWebsite( final VFolder folder ) {
62 return folder.getVFolder( ".website" ).exists();
63 }
64
65 void siteStatus( final VFolder folder ) {
66 System.out.print( "Status for " );
67 System.out.println( folder );
68 if ( this.websiteConf.getWebsiteLockFile().exists() ) {
69
70 } else if ( this.websiteConf.getWebsiteFailureFile().exists() ) {
71
72
73
74
75
76 } else if ( this.websiteConf.getWebsiteSuccessFile().exists() ) {
77 final Reader r = this.websiteConf.getWebsiteSuccessFile().getReader();
78 int c;
79 try {
80 while ( ( c = r.read() ) != -1 ) {
81 System.out.print( (char) c );
82 }
83 r.close();
84 } catch ( IOException ex ) {
85 System.out.println();
86 System.out.println( "Failed to read information from " );
87 }
88 } else {
89 System.out.println( "No info available" );
90 }
91 System.out.println();
92 }
93
94 void status( final VFolder folder ) {
95 if ( this.isAWebsite( folder ) ) {
96 this.siteStatus( folder );
97 } else {
98
99
100 final Iterator it = folder.listFolders().iterator();
101 while ( it.hasNext() ) {
102 this.status( (VFolder) it.next() );
103 }
104 }
105 }
106
107 }