fix indentation

This commit is contained in:
Martin Konecny 2012-07-03 16:43:24 -04:00
parent 0286aa364e
commit 619f17b2f9
1 changed files with 19 additions and 19 deletions

View File

@ -31,7 +31,7 @@ class MediaMonitorCommon:
def is_temp_file(self, filename): def is_temp_file(self, filename):
info = filename.split(".") info = filename.split(".")
# if file doesn't have any extension, info[-2] throws exception # if file doesn't have any extension, info[-2] throws exception
# Hence, checking length of info before we do anything # Hence, checking length of info before we do anything
if(len(info) >= 2): if(len(info) >= 2):
@ -56,7 +56,7 @@ class MediaMonitorCommon:
try: try:
uid = pwd.getpwnam(euid)[2] uid = pwd.getpwnam(euid)[2]
gid = grp.getgrnam(egid)[2] gid = grp.getgrnam(egid)[2]
#drop root permissions and become "nobody" #drop root permissions and become "nobody"
os.setegid(gid) os.setegid(gid)
os.seteuid(uid) os.seteuid(uid)
@ -85,15 +85,15 @@ class MediaMonitorCommon:
except Exception, e: except Exception, e:
self.logger.warn(u"Failed to check owner/group/permissions for %s", item) self.logger.warn(u"Failed to check owner/group/permissions for %s", item)
return False return False
def make_file_readable(self, pathname, is_dir): def make_file_readable(self, pathname, is_dir):
if is_dir: if is_dir:
#set to 755 #set to 755
os.chmod(pathname, stat.S_IRUSR|stat.S_IWUSR|stat.S_IXUSR | stat.S_IRGRP|stat.S_IXGRP | stat.S_IROTH|stat.S_IXOTH) os.chmod(pathname, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
else: else:
#set to 644 #set to 644
os.chmod(pathname, stat.S_IRUSR|stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH) os.chmod(pathname, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
def make_readable(self, pathname): def make_readable(self, pathname):
""" """
Should only call this function if is_readable() returns False. This function Should only call this function if is_readable() returns False. This function
@ -120,7 +120,7 @@ class MediaMonitorCommon:
except Exception, e: except Exception, e:
#something went wrong while we were trying to make world readable. #something went wrong while we were trying to make world readable.
return False return False
return True return True
#checks if path is a directory, and if it doesnt exist, then creates it. #checks if path is a directory, and if it doesnt exist, then creates it.
@ -165,7 +165,7 @@ class MediaMonitorCommon:
#non-critical exception because we probably tried to delete a non-empty dir. #non-critical exception because we probably tried to delete a non-empty dir.
#Don't need to log this, let's just "return" #Don't need to log this, let's just "return"
pass pass
#checks if path exists already in stor. If the path exists and the md5s are the #checks if path exists already in stor. If the path exists and the md5s are the
@ -195,7 +195,7 @@ class MediaMonitorCommon:
self.logger.error("Trying %s", new_filepath) self.logger.error("Trying %s", new_filepath)
if(os.path.exists(new_filepath)): if(os.path.exists(new_filepath)):
i = i+1; i = i + 1;
else: else:
filepath = new_filepath filepath = new_filepath
break break
@ -231,7 +231,7 @@ class MediaMonitorCommon:
md['MDATA_KEY_TRACKNUMBER'] = "%02d" % (int(md['MDATA_KEY_TRACKNUMBER'])) md['MDATA_KEY_TRACKNUMBER'] = "%02d" % (int(md['MDATA_KEY_TRACKNUMBER']))
#format bitrate as 128kbps #format bitrate as 128kbps
md['MDATA_KEY_BITRATE'] = str(md['MDATA_KEY_BITRATE']/1000)+"kbps" md['MDATA_KEY_BITRATE'] = str(md['MDATA_KEY_BITRATE'] / 1000) + "kbps"
filepath = None filepath = None
#file is recorded by Airtime #file is recorded by Airtime
@ -274,7 +274,7 @@ class MediaMonitorCommon:
if p.returncode != 0: if p.returncode != 0:
self.logger.warn("command \n%s\n return with a non-zero return value", command) self.logger.warn("command \n%s\n return with a non-zero return value", command)
self.logger.error(stderr) self.logger.error(stderr)
try: try:
""" """
File name charset encoding is UTF-8. File name charset encoding is UTF-8.
@ -283,14 +283,14 @@ class MediaMonitorCommon:
except Exception, e: except Exception, e:
stdout = None stdout = None
self.logger.error("Could not decode %s using UTF-8" % stdout) self.logger.error("Could not decode %s using UTF-8" % stdout)
return stdout return stdout
def scan_dir_for_new_files(self, dir): def scan_dir_for_new_files(self, dir):
command = 'find "%s" -iname "*.ogg" -o -iname "*.mp3" -type f -readable' % dir.replace('"', '\\"') command = 'find "%s" -iname "*.ogg" -o -iname "*.mp3" -type f -readable' % dir.replace('"', '\\"')
self.logger.debug(command) self.logger.debug(command)
stdout = self.exec_command(command) stdout = self.exec_command(command)
return stdout.splitlines() return stdout.splitlines()
def touch_index_file(self): def touch_index_file(self):
@ -312,7 +312,7 @@ class MediaMonitorCommon:
self.move_file(pathname, filepath) self.move_file(pathname, filepath)
self.make_readable(filepath) self.make_readable(filepath)
return filepath return filepath
def test_file_playability(self, pathname): def test_file_playability(self, pathname):
#when there is an single apostrophe inside of a string quoted by apostrophes, we can only escape it by replace that apostrophe #when there is an single apostrophe inside of a string quoted by apostrophes, we can only escape it by replace that apostrophe
#with '\''. This breaks the string into two, and inserts an escaped single quote in between them. #with '\''. This breaks the string into two, and inserts an escaped single quote in between them.
@ -323,13 +323,13 @@ class MediaMonitorCommon:
if return_code != 0: if return_code != 0:
#print pathname for py-interpreter.log #print pathname for py-interpreter.log
print pathname print pathname
return (return_code == 0) return (return_code == 0)
def move_to_problem_dir(self, source): def move_to_problem_dir(self, source):
dest = os.path.join(self.config.problem_directory, os.path.basename(source)) dest = os.path.join(self.config.problem_directory, os.path.basename(source))
try: try:
omask = os.umask(0) omask = os.umask(0)
os.rename(source, dest) os.rename(source, dest)
@ -338,4 +338,4 @@ class MediaMonitorCommon:
self.logger.error("traceback: %s", traceback.format_exc()) self.logger.error("traceback: %s", traceback.format_exc())
finally: finally:
os.umask(omask) os.umask(omask)