|
|
@ -42,6 +42,8 @@ class EEFileUtils(): |
|
|
|
dst = paths[1] |
|
|
|
if not os.path.islink(dst): |
|
|
|
try: |
|
|
|
Log.debug(self, "Creating Symbolic link, Source:{0}, Dest:{1}" |
|
|
|
.format(src, dst)) |
|
|
|
os.symlink(src, dst) |
|
|
|
except Exception as e: |
|
|
|
Log.debug(self, "{0}{1}".format(e.errno, e.strerror)) |
|
|
@ -54,6 +56,7 @@ class EEFileUtils(): |
|
|
|
Removes symbolic link for the path provided with filepath |
|
|
|
""" |
|
|
|
try: |
|
|
|
Log.debug(self, "Removing symbolic link: {0}".format(filepath)) |
|
|
|
os.unlink(filepath) |
|
|
|
except Exception as e: |
|
|
|
Log.debug(self, "{0}".format(e)) |
|
|
@ -66,6 +69,8 @@ class EEFileUtils(): |
|
|
|
dest : destination path |
|
|
|
""" |
|
|
|
try: |
|
|
|
Log.debug(self, "Copying file, Source:{0}, Dest:{1}" |
|
|
|
.format(src, dst)) |
|
|
|
shutil.copy2(src, dest) |
|
|
|
except shutil.Error as e: |
|
|
|
Log.debug(self, "{0}".format(e)) |
|
|
@ -84,6 +89,8 @@ class EEFileUtils(): |
|
|
|
rstr: replace string |
|
|
|
""" |
|
|
|
try: |
|
|
|
Log.debug(self, "Doning search and replace, File:{0}," |
|
|
|
"Source string:{1}, Dest String:{2}".format(src, dst)) |
|
|
|
for line in fileinput.input(fnm, inplace=True): |
|
|
|
print(line.replace(sstr, rstr), end='') |
|
|
|
fileinput.close() |
|
|
@ -112,6 +119,8 @@ class EEFileUtils(): |
|
|
|
Path : path for destination directory |
|
|
|
""" |
|
|
|
try: |
|
|
|
Log.debug(self, "Changing directory to {0}" |
|
|
|
.format(path)) |
|
|
|
os.chdir(path) |
|
|
|
except OSError as e: |
|
|
|
Log.debug(self, "{err}".format(err=e.strerror)) |
|
|
@ -129,6 +138,8 @@ class EEFileUtils(): |
|
|
|
userid = pwd.getpwnam(user)[2] |
|
|
|
groupid = pwd.getpwnam(user)[3] |
|
|
|
try: |
|
|
|
Log.debug(self, "Changing ownership of {0}, User:{1}, Group:{2}" |
|
|
|
.format(path, user, group)) |
|
|
|
if recursive: |
|
|
|
for root, dirs, files in os.walk(path): |
|
|
|
for d in dirs: |
|
|
@ -154,6 +165,8 @@ class EEFileUtils(): |
|
|
|
recursive: change permission recursively for all files |
|
|
|
""" |
|
|
|
try: |
|
|
|
Log.debug(self, "Changing permission of {0}, Perm:{1}" |
|
|
|
.format(path, perm)) |
|
|
|
if recursive: |
|
|
|
for root, dirs, files in os.walk(path): |
|
|
|
for d in dirs: |
|
|
@ -173,6 +186,8 @@ class EEFileUtils(): |
|
|
|
Similar to `mkdir -p` |
|
|
|
""" |
|
|
|
try: |
|
|
|
Log.debug(self, "Creating directories: {0}" |
|
|
|
.format(path, user, group)) |
|
|
|
os.makedirs(path) |
|
|
|
except OSError as e: |
|
|
|
Log.debug(self, "{0}".format(e.strerror)) |
|
|
@ -196,6 +211,8 @@ class EEFileUtils(): |
|
|
|
Searches for string in file and returns the matched line. |
|
|
|
""" |
|
|
|
try: |
|
|
|
Log.debug(self, "Finding string {0} to file {1}" |
|
|
|
.format(sstr, fnm)) |
|
|
|
for line in open(fnm, encoding='utf-8'): |
|
|
|
if sstr in line: |
|
|
|
return line |
|
|
@ -208,6 +225,7 @@ class EEFileUtils(): |
|
|
|
""" |
|
|
|
Remove files |
|
|
|
""" |
|
|
|
Log.debug(self, "Removing {0}".format(path)) |
|
|
|
if EEFileUtils.isexist(self, path): |
|
|
|
try: |
|
|
|
if os.path.isdir(path): |
|
|
|