]> git.donarmstrong.com Git - mothur.git/commitdiff
added system command
authorwestcott <westcott>
Wed, 8 Jul 2009 16:23:14 +0000 (16:23 +0000)
committerwestcott <westcott>
Wed, 8 Jul 2009 16:23:14 +0000 (16:23 +0000)
Mothur.xcodeproj/project.pbxproj
commandfactory.cpp
systemcommand.cpp [new file with mode: 0644]
systemcommand.h [new file with mode: 0644]

index dfe49ee66a679a32f986a14a5c17307ee90932c6..136b75f8081de9072b40ab718b6f7d732a7c0e12 100644 (file)
@@ -79,6 +79,7 @@
                37B73C761004BEFD008C4B41 /* listseqscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37B73C751004BEFD008C4B41 /* listseqscommand.cpp */; };
                37B73CA61004D89A008C4B41 /* getseqscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37B73CA51004D89A008C4B41 /* getseqscommand.cpp */; };
                37B73CC01004EB38008C4B41 /* removeseqscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37B73CBF1004EB38008C4B41 /* removeseqscommand.cpp */; };
+               37B73CCF1004F5E0008C4B41 /* systemcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37B73CCE1004F5E0008C4B41 /* systemcommand.cpp */; };
                37C1D9730F86506E0059E3F0 /* binsequencecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37C1D9720F86506E0059E3F0 /* binsequencecommand.cpp */; };
                37C753CE0FB3415200DBD02E /* distancecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37C753CD0FB3415200DBD02E /* distancecommand.cpp */; };
                37D928550F21331F001D4494 /* ace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37D927B80F21331F001D4494 /* ace.cpp */; };
                37B73CA51004D89A008C4B41 /* getseqscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = getseqscommand.cpp; sourceTree = "<group>"; };
                37B73CBE1004EB38008C4B41 /* removeseqscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = removeseqscommand.h; sourceTree = "<group>"; };
                37B73CBF1004EB38008C4B41 /* removeseqscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = removeseqscommand.cpp; sourceTree = "<group>"; };
+               37B73CCD1004F5E0008C4B41 /* systemcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = systemcommand.h; sourceTree = "<group>"; };
+               37B73CCE1004F5E0008C4B41 /* systemcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = systemcommand.cpp; sourceTree = "<group>"; };
                37C1D9710F86506E0059E3F0 /* binsequencecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = binsequencecommand.h; sourceTree = SOURCE_ROOT; };
                37C1D9720F86506E0059E3F0 /* binsequencecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = binsequencecommand.cpp; sourceTree = SOURCE_ROOT; };
                37C753CC0FB3415200DBD02E /* distancecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = distancecommand.h; sourceTree = SOURCE_ROOT; };
                                37D928460F21331F001D4494 /* summarycommand.cpp */,
                                37D9284B0F21331F001D4494 /* summarysharedcommand.h */,
                                37D9284A0F21331F001D4494 /* summarysharedcommand.cpp */,
+                               37B73CCD1004F5E0008C4B41 /* systemcommand.h */,
+                               37B73CCE1004F5E0008C4B41 /* systemcommand.cpp */,
                                211C38370F961E1F00FEE541 /* treegroupscommand.h */,
                                211C38360F961E1F00FEE541 /* treegroupscommand.cpp */,
                                7E09C5340FDA7F65002ECAE5 /* trimseqscommand.h */,
                                37B73C761004BEFD008C4B41 /* listseqscommand.cpp in Sources */,
                                37B73CA61004D89A008C4B41 /* getseqscommand.cpp in Sources */,
                                37B73CC01004EB38008C4B41 /* removeseqscommand.cpp in Sources */,
+                               37B73CCF1004F5E0008C4B41 /* systemcommand.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index c91dbf9abd520fc908698f68756d726d25002e95..fce55bbe9e856634a25b8141a3715965e88251b0 100644 (file)
@@ -53,6 +53,7 @@
 #include "listseqscommand.h"
 #include "getseqscommand.h"
 #include "removeseqscommand.h"
+#include "systemcommand.h"
 
 /***********************************************************/
 
@@ -104,6 +105,7 @@ CommandFactory::CommandFactory(){
        commands["list.seqs"]                   = "list.seqs";
        commands["get.seqs"]                    = "get.seqs";
        commands["remove.seqs"]                 = "get.seqs";
+       commands["system"]                              = "system";
        commands["quit"]                                = "quit"; 
 
 }
@@ -165,6 +167,7 @@ Command* CommandFactory::getCommand(string commandName, string optionString){
                else if(commandName == "get.seqs")                              {       command = new GetSeqsCommand(optionString);                             }
                else if(commandName == "remove.seqs")                   {       command = new RemoveSeqsCommand(optionString);                  }
                else if(commandName == "merge.files")                   {       command = new MergeFileCommand(optionString);                   }
+               else if(commandName == "system")                                {       command = new SystemCommand(optionString);                              }
                else                                                                                    {       command = new NoCommand(optionString);                                  }
 
                return command;
diff --git a/systemcommand.cpp b/systemcommand.cpp
new file mode 100644 (file)
index 0000000..5bc9b46
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ *  systemcommand.cpp
+ *  Mothur
+ *
+ *  Created by Sarah Westcott on 7/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "systemcommand.h"
+
+//**********************************************************************************************************************
+
+SystemCommand::SystemCommand(string option){
+       try {
+               abort = false;
+               
+               //allow user to run help
+               if(option == "help") { help(); abort = true; }
+               
+               else {
+                       //valid paramters for this command
+                       string Array[] =  {"command"};
+                       vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
+                       
+                       //check to make sure all parameters are valid for command
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       }
+                       
+                       //check for required parameters
+                       command = validParameter.validFile(parameters, "command", false);
+                       if (command == "not found") { mothurOut("command is a required parameter."); mothurOutEndLine(); abort = true; }
+               }       
+
+       }
+       catch(exception& e) {
+               errorOut(e, "SystemCommand", "SystemCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+
+void SystemCommand::help(){
+       try {
+               mothurOut("The system command allows you to execute a system command from within mothur.\n");
+               mothurOut("The system command parameter is command and it is required.\n");
+               mothurOut("The system command should be in the following format: system(command=yourCommand).\n");
+               mothurOut("Example system(command=clear).\n");
+               mothurOut("Note: No spaces between parameter labels (i.e. command), '=' and parameters (i.e.yourCommand).\n\n");
+       }
+       catch(exception& e) {
+               errorOut(e, "SystemCommand", "help");
+               exit(1);
+       }
+}
+
+//**********************************************************************************************************************
+
+int SystemCommand::execute(){
+       try {
+               
+               if (abort == true) { return 0; }
+               
+               system(command.c_str());
+               
+               return 0;               
+       }
+
+       catch(exception& e) {
+               errorOut(e, "SystemCommand", "execute");
+               exit(1);
+       }
+}
+
+//**********************************************************************************************************************
diff --git a/systemcommand.h b/systemcommand.h
new file mode 100644 (file)
index 0000000..410a12e
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef SYSTEMCOMMAND_H
+#define SYSTEMCOMMAND_H
+
+/*
+ *  systemcommand.h
+ *  Mothur
+ *
+ *  Created by Sarah Westcott on 7/8/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "command.hpp"
+
+
+class SystemCommand : public Command {
+       
+       public:
+       
+               SystemCommand(string);  
+               ~SystemCommand(){};
+               int execute();
+               void help();    
+               
+       private:
+               string command;
+               bool abort;
+               
+};
+
+#endif
+