1010
1111
1212class EEFileUtils ():
13- """Method to operate on files"""
13+ """Utilities to operate on files"""
1414 def __init__ ():
1515 pass
1616
1717 def remove (self , filelist ):
18+ """remove files from given path"""
1819 for file in filelist :
1920 if os .path .isfile (file ):
2021 Log .info (self , "Removing {0:65}" .format (file ), end = ' ' )
@@ -33,6 +34,10 @@ def remove(self, filelist):
3334 Log .error (self , 'Unable to Remove file ' )
3435
3536 def create_symlink (self , paths , errormsg = '' ):
37+ """
38+ Create symbolic links provided in list with first as source
39+ and second as destination
40+ """
3641 src = paths [0 ]
3742 dst = paths [1 ]
3843 if not os .path .islink (dst ):
@@ -45,13 +50,21 @@ def create_symlink(self, paths, errormsg=''):
4550 Log .debug (self , "Destination: {0} exists" .format (dst ))
4651
4752 def remove_symlink (self , filepath ):
53+ """
54+ Removes symbolic link for the path provided with filepath
55+ """
4856 try :
4957 os .unlink (filepath )
5058 except Exception as e :
5159 Log .debug (self , "{0}" .format (e ))
5260 Log .error (self , "Unable to reomove symbolic link ...\n " )
5361
5462 def copyfile (self , src , dest ):
63+ """
64+ Copies files:
65+ src : source path
66+ dest : destination path
67+ """
5568 try :
5669 shutil .copy2 (src , dest )
5770 except shutil .Error as e :
@@ -64,6 +77,12 @@ def copyfile(self, src, dest):
6477 .fromat (src , dest ))
6578
6679 def searchreplace (self , fnm , sstr , rstr ):
80+ """
81+ Search replace strings in file
82+ fnm : filename
83+ sstr: search string
84+ rstr: replace string
85+ """
6786 try :
6887 for line in fileinput .input (fnm , inplace = True ):
6988 print (line .replace (sstr , rstr ), end = '' )
@@ -74,6 +93,11 @@ def searchreplace(self, fnm, sstr, rstr):
7493 .format (fnm , sstr , rstr ))
7594
7695 def mvfile (self , src , dst ):
96+ """
97+ Moves file from source path to destination path
98+ src : source path
99+ dst : Destination path
100+ """
77101 try :
78102 Log .debug (self , "Moving file from {0} to {1}" .format (src , dst ))
79103 shutil .move (src , dst )
@@ -83,13 +107,25 @@ def mvfile(self, src, dst):
83107 .format (src , dst ))
84108
85109 def chdir (self , path ):
110+ """
111+ Change Directory to path specified
112+ Path : path for destination directory
113+ """
86114 try :
87115 os .chdir (path )
88116 except OSError as e :
89117 Log .debug (self , "{err}" .format (err = e .strerror ))
90118 Log .error (self , 'Unable to Change Directory {0}' .format (path ))
91119
92120 def chown (self , path , user , group , recursive = False ):
121+ """
122+ Change Owner for files
123+ change owner for file with path specified
124+ user: username of owner
125+ group: group of owner
126+ recursive: if recursive is True change owner for all
127+ files in directory
128+ """
93129 userid = pwd .getpwnam (user )[2 ]
94130 groupid = pwd .getpwnam (user )[3 ]
95131 try :
@@ -111,6 +147,12 @@ def chown(self, path, user, group, recursive=False):
111147 Log .error (self , "Unable to change owner : {0} " .format (path ))
112148
113149 def chmod (self , path , perm , recursive = False ):
150+ """
151+ Changes Permission for files
152+ path : file path permission to be changed
153+ perm : permissions to be given
154+ recursive: change permission recursively for all files
155+ """
114156 try :
115157 if recursive :
116158 for root , dirs , files in os .walk (path ):
@@ -125,13 +167,21 @@ def chmod(self, path, perm, recursive=False):
125167 Log .error (self , "Unable to change owner : {0}" .format (path ))
126168
127169 def mkdir (self , path ):
170+ """
171+ create directories.
172+ path : path for directory to be created
173+ Similar to `mkdir -p`
174+ """
128175 try :
129176 os .makedirs (path )
130177 except OSError as e :
131178 Log .debug (self , "{0}" .format (e .strerror ))
132179 Log .error (self , "Unable to create directory {0} " .format (path ))
133180
134181 def isexist (self , path ):
182+ """
183+ Check if file exist on given path
184+ """
135185 try :
136186 if os .path .exists (path ):
137187 return (True )
@@ -142,6 +192,9 @@ def isexist(self, path):
142192 Log .error (self , "Unable to check path {0}" .format (path ))
143193
144194 def grep (self , fnm , sstr ):
195+ """
196+ Searches for string in file and returns the matched line.
197+ """
145198 try :
146199 for line in open (fnm ):
147200 if sstr in line :
@@ -152,6 +205,9 @@ def grep(self, fnm, sstr):
152205 .format (sstr , fnm ))
153206
154207 def rm (self , path ):
208+ """
209+ Remove files
210+ """
155211 if EEFileUtils .isexist (self , path ):
156212 try :
157213 if os .path .isdir (path ):
0 commit comments