All Classes Files Functions Variables Enumerations Enumerator Macros
tasks.cpp
Go to the documentation of this file.
1 #include "output.hpp"
10 
19 // Outputs the commands needed to perform tasks
20 void OutPut::outputTasks( Episode *libObj, ConfigOpts *confObj, ostream &tout )
21 {
22  // Create a command string
23  string strCmd;
24 
25  //Check if rename flag is not set
26  if( !confObj->getFlags( confObj->RenameInputFiles_flag ) )
27  {
28  // Check if the new directory exists
29  if( !isDir( libObj ) )
30  {
31  // Create a make directory command
32  strCmd = MKDIR"\"" + libObj->getDirectory() + "\"";
33  // Check if the execute flag is set
34  if( confObj->getFlags( confObj->ExecuteInternally_flag ) )
35  {
36  // Create a non-const pointer to const char
37  const char *charCmd = strCmd.c_str();
38  // Check if compiling on Windows
39  #ifdef _WIN32
40  // Execute Windows system command
41  system( charCmd );
42  // Else compiling on Linux
43  #else
44  // Execute Linux system command
45  if ( system( charCmd ) == 0 ) {};
46  #endif
47  }
48  // If the execute flag is not set
49  else
50  {
51  // Output the command
52  tout << strCmd << endl;
53  }
54  }
55  }
56 
57  // Check if move flag is set
58  if( confObj->getFlags( confObj->MoveInputFiles_flag ) )
59  {
60  // Create a move file command
61  strCmd = MOVE;
62  }
63  // Check if copy flag is set
64  else if( confObj->getFlags( confObj->CopyInputFiles_flag ) )
65  {
66  // Create a copy file command
67  strCmd = COPY;
68  }
69 
70  // Assemble the command with the old directory and file name, and the new directory and file name
71  strCmd += '"' + libObj->getOldDir() + libObj->getOldFile() + "\" \"" + libObj->getDirectory() + libObj->getFilename() + '"';
72 
73  // Check if rename flag is set
74  if( confObj->getFlags( confObj->RenameInputFiles_flag ) )
75  {
76  // Create the rename command with the old directory and old file name, and the old directory and new file name
77  strCmd = RENAME"\"" + libObj->getOldDir() + libObj->getOldFile() + "\" \"" + libObj->getOldDir() + libObj->getFilename() + '"';
78  }
79 
80  // Check if execute flag is set
81  if( confObj->getFlags( confObj->ExecuteInternally_flag ) )
82  {
83  // Create a non-const pointer to const char
84  const char *charCmd = strCmd.c_str();
85  // Check if compiling on Windows
86  #ifdef _WIN32
87  // Execute Windows system command
88  system( charCmd );
89  // Else compiling on Linux
90  #else
91  // Execute Linux system command
92  if ( system( charCmd ) == 0 ) {};
93  #endif
94  }
95  // If the execute flag is not set
96  else
97  {
98  // Output the command
99  tout << strCmd << endl;
100  }
101 };
102 
107 // Check if the objects new directory exists
108 bool OutPut::isDir( Episode *epObj )
109 {
110  // Create an object of type struct stat
111  struct stat readBuffer;
112  // Check if output exists
113  if( stat( epObj->getDirectory().c_str(), &readBuffer) == 0 )
114  {
115  // Check if the output is a directory
116  if( S_ISDIR( readBuffer.st_mode ) )
117  {
118  // Return with true
119  return 1;
120  }
121  }
122 
123  // Return with false
124  return 0;
125 };
The OutPut class prints summary and error information from objects.
static bool getFlags(flagValue)
Retrieves the user configuration flags from an array.
Definition: mainPublic.cpp:280
move the input files
Definition: options.hpp:105
perform an internal action instead of writing a script
Definition: options.hpp:101
string getFilename() const
Definition: episode.cpp:131
#define MKDIR
Definition: options.hpp:26
copy the input files
Definition: options.hpp:106
Stores parsed file information regarding a single episode; to be used as a vector.
Definition: episode.hpp:25
string getOldDir() const
Definition: episode.cpp:125
#define MOVE
Definition: options.hpp:28
string getOldFile() const
Definition: episode.cpp:119
#define COPY
Definition: options.hpp:27
rename the input files
Definition: options.hpp:104
#define RENAME
Definition: options.hpp:29
Stores all config options, settings, and flags for clerk.
Definition: options.hpp:60
string getDirectory() const
Definition: episode.cpp:137
static bool isDir(Episode *)
Checks if the object's new directory exists yet.
Definition: tasks.cpp:108
static void outputTasks(Episode *, ConfigOpts *, ostream &)
Outputs to the given stream the commands needed to perform the requested tasks.
Definition: tasks.cpp:20