Removed unused or unneeded chunks of code and comments

This commit is contained in:
2010-01-26 10:55:09 +00:00
parent 4d4ef08ef7
commit ebbdb3917a

View File

@@ -31,116 +31,6 @@ from filename_config import tv_regex
# end configs # end configs
############################################## ##############################################
def colour(text,colour="red"):
nocolour=False
if nocolour: # Colour no supported, return plain text
return text
#end if
c = {'red':'[31m',
'green':'[32m',
'blue':'[34m',
}
CLR=chr(27)+'[0m'
if not colour in c.keys():
raise ValueError("Invalid colour")
else:
return chr(27)+c[colour] + text + CLR
#end if
#end colour
class ProgressBar:
"""From http://code.activestate.com/recipes/168639/"""
def __init__(self, minValue = 0, maxValue = 10, totalWidth=12):
self.progBar = "[]" # This holds the progress bar string
self.min = minValue
self.max = maxValue
self.span = maxValue - minValue
self.width = totalWidth
self.amount = 0 # When amount == max, we are 100% done
self.updateAmount(0) # Build progress bar string
def updateAmount(self, newAmount = 0):
if newAmount < self.min: newAmount = self.min
if newAmount > self.max: newAmount = self.max
self.amount = newAmount
# Figure out the new percent done, round to an integer
diffFromMin = float(self.amount - self.min)
percentDone = (diffFromMin / float(self.span)) * 100.0
percentDone = round(percentDone)
percentDone = int(percentDone)
# Figure out how many hash bars the percentage should be
allFull = self.width - 2
numHashes = (percentDone / 100.0) * allFull
numHashes = int(round(numHashes))
# build a progress bar with hashes and spaces
self.progBar = "[" + '#'*numHashes + ' '*(allFull-numHashes) + "]"
# figure out where to put the percentage, roughly centered
percentPlace = (len(self.progBar) / 2) - len(str(percentDone))
percentString = str(percentDone) + "%"
# slice the percentage into the bar
self.progBar = (self.progBar[0:percentPlace] + percentString
+ self.progBar[percentPlace+len(percentString):])
def __str__(self):
return str(self.progBar)
def copy_with_prog(src_file, dest_file, overwrite = False, block_size = 512):
if not overwrite:
if os.path.isfile(dest_file):
raise IOError("File exists, not overwriting")
# Open src and dest files, get src file size
src = open(src_file, "rb")
dest = open(dest_file, "wb")
src_size = os.stat(src_file).st_size
# Set progress bar
prgb = ProgressBar(totalWidth = 79, maxValue = src_size)
# Start copying file
cur_block_pos = 0 # a running total of current position
while True:
cur_block = src.read(block_size)
# Update progress bar
prgb.updateAmount(cur_block_pos)
cur_block_pos += block_size
sys.stdout.write(
'\r%s\r' % str(prgb)
)
# If it's the end of file
if not cur_block:
# ..write new line to prevent messing up terminal
print # print line break to clear progress bar
break
else:
# ..if not, write the block and continue
dest.write(cur_block)
#end while
# Close files
src.close()
dest.close()
# Check output file is same size as input one!
dest_size = os.stat(dest_file).st_size
if dest_size != src_size:
raise IOError(
"New file-size does not match original (src: %s, dest: %s)" % (
src_size, dest_size)
)
def findFiles(args): def findFiles(args):
""" """
Takes a list of files/folders, grabs files inside them. Does not recurse Takes a list of files/folders, grabs files inside them. Does not recurse
@@ -260,9 +150,8 @@ def main():
# Warn if no files are found, then exit # Warn if no files are found, then exit
if len(files) == 0: if len(files) == 0:
print colour('No files found','red') print 'No files found'
sys.exit(0) sys.exit(0)
#end if files == 0
for name in files: for name in files:
oldfile = os.path.join(name['filepath'], name['filename']) + "." + name['ext'] oldfile = os.path.join(name['filepath'], name['filename']) + "." + name['ext']
@@ -286,7 +175,6 @@ def main():
os.rename(oldfile, newfile) os.rename(oldfile, newfile)
except Exception, errormsg: except Exception, errormsg:
print "[!] Error moving file! %s" % (errormsg) print "[!] Error moving file! %s" % (errormsg)
#end try
else: else:
print "[*] Copying file" print "[*] Copying file"
try: try:
@@ -295,14 +183,8 @@ def main():
print "[!] Error copying file! %s" % (errormsg) print "[!] Error copying file! %s" % (errormsg)
else: else:
print "[*] ..done" print "[*] ..done"
#end try
#end if same_partition
#end if not file_exists
else: else:
print "Skipping file" print "Skipping file"
#end if ans
#end for name in files
#end main
if __name__ == '__main__': if __name__ == '__main__':
main() main()