File: CommandSpecFileCopy.cxx

package info (click to toggle)
caret 5.6.1.3~dfsg.1-4
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 23,352 kB
  • ctags: 27,394
  • sloc: cpp: 363,314; python: 6,718; ansic: 5,507; makefile: 227; sh: 9
file content (191 lines) | stat: -rw-r--r-- 7,916 bytes parent folder | download | duplicates (2)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*LICENSE_START*/
/*
 *  Copyright 1995-2002 Washington University School of Medicine
 *
 *  http://brainmap.wustl.edu
 *
 *  This file is part of CARET.
 *
 *  CARET 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.
 *
 *  CARET is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with CARET; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
/*LICENSE_END*/

#include "CommandSpecFileCopy.h"
#include "FileFilters.h"
#include "ProgramParameters.h"
#include "ScriptBuilderParameters.h"
#include "SpecFileUtilities.h"

/**
 * constructor.
 */
CommandSpecFileCopy::CommandSpecFileCopy()
   : CommandBase("-spec-file-copy",
                 "SPEC FILE COPY")
{
}

/**
 * destructor.
 */
CommandSpecFileCopy::~CommandSpecFileCopy()
{
}

/**
 * get the script builder parameters.
 */
void 
CommandSpecFileCopy::getScriptBuilderParameters(ScriptBuilderParameters& paramsOut) const
{
   paramsOut.clear();
   std::vector<QString> values, descriptions;
   values.push_back("COPY_ALL");   descriptions.push_back("Copy Spec and its Data Files");
   values.push_back("MOVE_ALL");   descriptions.push_back("Move Spec and its Data Files");
   values.push_back("COPY_SPEC_ONLY");   descriptions.push_back("Copy Spec File and Point to Data Files");

   paramsOut.addListOfItems("Copy Mode", values, descriptions);
   paramsOut.addFile("Input Spec File Name", FileFilters::getSpecFileFilter());
   paramsOut.addFile("Target  Name", FileFilters::getSpecFileFilter());

}

/**
 * get full help information.
 */
QString 
CommandSpecFileCopy::getHelpInformation() const
{
   QString helpInfo =
      (indent3 + getShortDescription() + "\n"
       + indent6 + parameters->getProgramNameWithoutPath() + " " + getOperationSwitch() + "  \n"
       + indent9 + "<copy-mode>\n"
       + indent9 + "<source-spec-file-name>\n"
       + indent9 + "<target-name>\n"
       + indent9 + "\n"
       + indent9 + "The source-spec-file and perhaps its data files are \n"
       + indent9 + "copied to the new location/spec file. \n"
       + indent9 + "  \n"
       + indent9 + "if \"target-name\" is a directory, the name of the  \n"
       + indent9 + "target spec file will be the same as the source spec \n"
       + indent9 + "file. \n"
       + indent9 + "  \n"
       + indent9 + "\"copy-mode\" is one of \n"
       + indent9 + "  \n"
       + indent9 + "   COPY_ALL   Copy the data files to the destination directory. \n"
       + indent9 + "   COPY_SPEC_ONLY   Copy only the spec file, the data files \n"
       + indent9 + "                    will not be copied.  Any absolute or  \n"
       + indent9 + "                    relative path on the specified spec file  \n"
       + indent9 + "                    is prepended to the data filenames in \n"
       + indent9 + "                    the new spec file. \n"
       + indent9 + "   MOVE ALL   Move all files from their old location to their \n"
       + indent9 + "              new location. \n"
       + indent9 + "  \n"
       + indent9 + "LIMITATIONS  \n"
       + indent9 + "   Either the source or target spec file must be in the  \n"
       + indent9 + "   current directory. \n"
       + indent9 + "  \n"
       + indent9 + "   If you are using the \"-s\" option to copy only the spec \n"
       + indent9 + "   file and want a relative path to the data files in the  \n"
       + indent9 + "   target spec file, you must run the command from the  \n"
       + indent9 + "   target directory as shown in the first example and use \n"
       + indent9 + "   a relative path to specify the spec file that is being \n"
       + indent9 + "   copied. \n"
       + indent9 + "  \n"
       + indent9 + "EXAMPLES  \n"
       + indent9 + "  \n"
       + indent9 + "   Copy the spec file brain.spec to the current directory. \n"
       + indent9 + "   The data files will not be copied but the path to each of the\n"
       + indent9 + "   data files in the spec file will be a RELATIVE path \n"
       + indent9 + "   since a relative path is used to specify the spec file. \n"
       + indent9 + "   Note that a \".\" is used to specify the current directory \n"
       + indent9 + "   for the target spec file. \n"
       + indent9 + "  \n"
       + indent9 + "      COPY_SPEC_ONLY ../../brain/brain.spec . \n"
       + indent9 + "  \n"
       + indent9 + "   Copy the spec file brain.spec to the current directory. \n"
       + indent9 + "   The data files will not be copied but the path to each of the\n"
       + indent9 + "   data files in the spec file will be an ABSOLUTE path \n"
       + indent9 + "   since an absolute path is used to specify the spec file. \n"
       + indent9 + "  \n"
       + indent9 + "      COPY_SPEC_ONLY /usr/data/brain/brain.spec . \n"
       + indent9 + "  \n"
       + indent9 + "   Copy the spec file occipital.spec located in the current \n"
       + indent9 + "   directory to the directory /usr/people/bob/brain_data. \n"
       + indent9 + "   The data files will also be copied. \n"
       + indent9 + "  \n"
       + indent9 + "      COPY_ALL  occipital.spec /usr/people/bob/brain_data \n"
       + indent9 + "  \n"
       + indent9 + "   Copy the spec file occipital.spec located in the current \n"
       + indent9 + "   directory to the directory /usr/people/bob/brain_data. \n"
       + indent9 + "   The data files will not be copied and the path to each of  \n"
       + indent9 + "   the data files in the spec file will be an absolute path \n"
       + indent9 + "   since the command is run from the directory containing \n"
       + indent9 + "   the spec file. \n"
       + indent9 + " \n"
       + indent9 + "      COPY_SPEC_ONLY occipital.spec /usr/people/bob/brain_data \n"
       + indent9 + "\n");
      
   return helpInfo;
}

/**
 * execute the command.
 */
void 
CommandSpecFileCopy::executeCommand() throw (BrainModelAlgorithmException,
                                     CommandException,
                                     FileException,
                                     ProgramParametersException,
                                     StatisticException)
{
   const QString copyModeName =
      parameters->getNextParameterAsString("Copy Mode");
   const QString sourceSpecFileName =
      parameters->getNextParameterAsString("Source Spec File Name");
   const QString targetName =
      parameters->getNextParameterAsString("Target Name");
   checkForExcessiveParameters();
   
   SpecFileUtilities::MODE_COPY_SPEC_FILE copyMode;
   if (copyModeName == "COPY_ALL") {
      copyMode = SpecFileUtilities::MODE_COPY_SPEC_FILE_COPY_ALL;
   }
   else if (copyModeName == "COPY_SPEC_ONLY") {
      copyMode = SpecFileUtilities::MODE_COPY_SPEC_FILE_POINT_TO_DATA_FILES;
   }
   else if (copyModeName == "MOVE_ALL") {
      copyMode = SpecFileUtilities::MODE_COPY_SPEC_FILE_MOVE_ALL;
   }
   else {
      throw CommandException("Invalid copy mode \""
                             + copyModeName
                             + "\"");
   }
   
   QString errorMessage;
   const bool errorFlag = SpecFileUtilities::copySpecFile(sourceSpecFileName, 
                                                      targetName, 
                                                      copyMode, 
                                                      errorMessage,
                                                      true);
   if (errorFlag) {
      throw CommandException(errorMessage);
   }
}