casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DOos.h
Go to the documentation of this file.
1 //# DOos.h: Functions used to implement the DO functionality
2 //# Copyright (C) 1999,2000,2001
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //#
27 //# $Id$
28 
29 #ifndef CASA_DOOS_H
30 #define CASA_DOOS_H
31 
32 
33 //# Includes
34 #include <casacore/casa/aips.h>
36 
37 namespace casacore { //# NAMESPACE CASACORE - BEGIN
38 
39 //# Forward Declarations
40 class String;
41 
42 
43 // <summary>
44 // DO for accessing os-specific functions
45 // </summary>
46 
47 // <use visibility=export>
48 
49 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
50 // </reviewed>
51 
52 // <prerequisite>
53 // <li> <linkto module=OS>OS</linkto>
54 // </prerequisite>
55 
56 // <etymology>
57 // </etymology>
58 
59 // <synopsis>
60 // This class serves as the connection between the OS module and a tasking
61 // interface in Glish or Python.
62 // It is meant for access to OS-specific functions, in
63 // particular file handling.
64 // </synopsis>
65 
66 // <example>
67 // </example>
68 
69 // <motivation>
70 // </motivation>
71 
72 // <thrown>
73 // <li> AipsError if AIPSPATH or HOME is not defined
74 // </thrown>
75 
76 // <todo asof="1997/09/16">
77 // <li> Check for feasable extensions
78 // </todo>
79 
80 
81 class DOos
82 {
83 public:
84  // Are the given path names valid?
85  // I.e. does a file with the given name exist or can it be created?
86  static Vector<Bool> isValidPathName (const Vector<String>& pathName);
87 
88  // Do the given files exist?
89  // If follow is False, symbolic links are not followed.
90  static Vector<Bool> fileExists (const Vector<String>& fileName,
91  Bool follow = True);
92 
93  // Give the type of the given files.
94  static Vector<String> fileType (const Vector<String>& fileName,
95  Bool follow = True);
96 
97  // Give all file names in the directory matching the given pattern
98  // and file types.
99  // <br>The pattern can be a string like the filename pattern given in
100  // a shell (e.g. '*.cc'). If the string is empty, all files are taken
101  // into account.
102  // <br>Filetypes is a string determining which file types will be selected.
103  // Each character in the string determines a file type. They are:
104  // <dl>
105  // <dt>r<dd>regular file
106  // <dt>d<dd>directory
107  // <dt>s<dd>symbolic link
108  // <dt>R<dd>readable file
109  // <dt>W<dd>writable file
110  // <dt>X<dd>executable file
111  // </dl>
112  // The all flag determines if file names starting with a . will also
113  // be selected.
114  static Vector<String> fileNames (const String& directoryName,
115  const String& fileNamePattern,
116  const String& fileTypes,
117  Bool all = False,
118  Bool follow = True);
119 
120  // Make directories. It throws an exception if a file with that
121  // name already exists.
122  static void makeDirectory (const Vector<String>& directoryNames,
123  Bool makeParent = False);
124 
125  // Return the full absolute names for the given names.
126  static Vector<String> fullName (const Vector<String>& fileName);
127 
128  // Return the full directory names of the given files.
129  static Vector<String> dirName (const Vector<String>& fileName);
130 
131  // Return the base names of the given files.
132  static Vector<String> baseName (const Vector<String>& fileName);
133 
134  // Get the time of the given files.
135  // <src>whichTime</src> determines which time to return:
136  // <br>1 = time of last access
137  // <br>2 = time of last modification
138  // <br>3 = time of last status change
139  static Vector<Double> fileTime (const Vector<String>& fileName,
140  Int whichTime = 1, Bool follow = True);
141 
142  // Return the total size (in bytes) for each file or directory given.
143  // For a directory the size of all files (recursively) in it is given.
144  // If follow is False, symbolic links are not followed.
145  // <group>
146  static Vector<Double> totalSize (const Vector<String>& fileName,
147  Bool follow = True);
148  static Double totalSize (const String& fileName, Bool follow = True);
149  // </group>
150 
151  // Return the total size on the devices the given directories are on.
152  // If follow is False, symbolic links are not followed.
153  static Vector<Double> freeSpace (const Vector<String>& fileName,
154  Bool follow = True);
155 
156  // Copy the file (or directory recursively).
157  // If from is a symbolic link and follow is False, only the
158  // symbolic link is copied.
159  static void copy (const String& to, const String& from,
160  Bool overwrite = True, Bool follow = True);
161 
162  // Move the file or directory.
163  // If from is a symbolic link and follow is False, only the
164  // symbolic link is moved.
165  static void move (const String& to, const String& from,
166  Bool overwrite = True, Bool follow = True);
167 
168  // Remove the files (or directories recursively).
169  // If fileName is a symbolic link and follow is False, only the
170  // symbolic link is removed.
171  // <group>
172  static void remove (const String& fileName, Bool recursive,
173  Bool mustExist = True, Bool follow = True);
174  static void remove (const Vector<String>& fileNames, Bool recursive,
175  Bool mustExist = True, Bool follow = True);
176  // </group>
177 
178  // Tell if a table is used or locked by another process.
179  // It returns a vector containing 3 integers.
180  // The first one tells if the table is in use or locked.
181  // See <linkto class=LockFile>LockFile</linkto>\::showLock for details.
182  // The second one gives the pid of the process using/locking the table.
183  // The third one tells if the table is permanently locked (0 = not).
184  static Vector<Int> lockInfo (const String& tableName);
185 };
186 
187 
188 
189 } //# NAMESPACE CASACORE - END
190 
191 #endif
int Int
Definition: aipstype.h:50
static Vector< String > fileType(const Vector< String > &fileName, Bool follow=True)
Give the type of the given files.
static void copy(const String &to, const String &from, Bool overwrite=True, Bool follow=True)
Copy the file (or directory recursively).
DO for accessing os-specific functions.
Definition: DOos.h:81
static Vector< String > fileNames(const String &directoryName, const String &fileNamePattern, const String &fileTypes, Bool all=False, Bool follow=True)
Give all file names in the directory matching the given pattern and file types.
static Vector< Int > lockInfo(const String &tableName)
Tell if a table is used or locked by another process.
static Vector< String > baseName(const Vector< String > &fileName)
Return the base names of the given files.
static void move(const String &to, const String &from, Bool overwrite=True, Bool follow=True)
Move the file or directory.
double Double
Definition: aipstype.h:55
static Vector< String > dirName(const Vector< String > &fileName)
Return the full directory names of the given files.
static Vector< String > fullName(const Vector< String > &fileName)
Return the full absolute names for the given names.
static Vector< Bool > isValidPathName(const Vector< String > &pathName)
Are the given path names valid? I.e.
static Vector< Bool > fileExists(const Vector< String > &fileName, Bool follow=True)
Do the given files exist? If follow is False, symbolic links are not followed.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
const Bool False
Definition: aipstype.h:44
static void makeDirectory(const Vector< String > &directoryNames, Bool makeParent=False)
Make directories.
static Vector< Double > fileTime(const Vector< String > &fileName, Int whichTime=1, Bool follow=True)
Get the time of the given files.
static Vector< Double > freeSpace(const Vector< String > &fileName, Bool follow=True)
Return the total size on the devices the given directories are on.
String: the storage and methods of handling collections of characters.
Definition: String.h:225
LatticeExprNode all(const LatticeExprNode &expr)
const Bool True
Definition: aipstype.h:43
static Vector< Double > totalSize(const Vector< String > &fileName, Bool follow=True)
Return the total size (in bytes) for each file or directory given.