mirror of
https://github.com/nikdoof/tvorganise.git
synced 2026-01-30 17:48:20 +00:00
Wrap functions in a class.
This commit is contained in:
@@ -14,12 +14,14 @@ import shutil
|
|||||||
import ConfigParser
|
import ConfigParser
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
def getLogger():
|
class TvOrganiser():
|
||||||
|
|
||||||
|
def _getLogger(self):
|
||||||
lgr = logging.getLogger('tvorganise')
|
lgr = logging.getLogger('tvorganise')
|
||||||
lgr.addHandler(logging.StreamHandler())
|
lgr.addHandler(logging.StreamHandler())
|
||||||
return lgr
|
return lgr
|
||||||
|
|
||||||
def getConfig(file):
|
def _getConfig(self, file):
|
||||||
|
|
||||||
config = {}
|
config = {}
|
||||||
|
|
||||||
@@ -46,10 +48,11 @@ def getConfig(file):
|
|||||||
|
|
||||||
config['regex'] = regex
|
config['regex'] = regex
|
||||||
|
|
||||||
|
self._config = config
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
def findFiles(args):
|
def _findFiles(self, 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
|
||||||
more than one level (if a folder is supplied, it will list files within)
|
more than one level (if a folder is supplied, it will list files within)
|
||||||
@@ -65,7 +68,7 @@ def findFiles(args):
|
|||||||
allfiles.append(cfile)
|
allfiles.append(cfile)
|
||||||
return allfiles
|
return allfiles
|
||||||
|
|
||||||
def processNames(names, verbose=False):
|
def processNames(self, names, verbose=False):
|
||||||
"""
|
"""
|
||||||
Takes list of names, runs them though the regexs
|
Takes list of names, runs them though the regexs
|
||||||
"""
|
"""
|
||||||
@@ -109,28 +112,12 @@ def processNames(names, verbose=False):
|
|||||||
|
|
||||||
return allEps
|
return allEps
|
||||||
|
|
||||||
def make_path(path):
|
def _same_partition(f1, f2):
|
||||||
try:
|
|
||||||
os.makedirs(path)
|
|
||||||
except OSError:
|
|
||||||
#print "Couldn't make path"
|
|
||||||
pass
|
|
||||||
|
|
||||||
def does_file_exist(path):
|
|
||||||
try:
|
|
||||||
os.stat(path)
|
|
||||||
except OSError:
|
|
||||||
file_exists = False
|
|
||||||
else:
|
|
||||||
file_exists = True
|
|
||||||
return file_exists
|
|
||||||
|
|
||||||
def same_partition(f1, f2):
|
|
||||||
return os.stat(f1).st_dev == os.stat(f2).st_dev
|
return os.stat(f1).st_dev == os.stat(f2).st_dev
|
||||||
|
|
||||||
###########################
|
###########################
|
||||||
|
|
||||||
def main():
|
def main(self):
|
||||||
parser = OptionParser(usage="%prog [options] <file or directories>")
|
parser = OptionParser(usage="%prog [options] <file or directories>")
|
||||||
parser.add_option("-a", "--always", dest = "always",
|
parser.add_option("-a", "--always", dest = "always",
|
||||||
action="store_true", default = False,
|
action="store_true", default = False,
|
||||||
@@ -170,15 +157,14 @@ def main():
|
|||||||
print "Old path:", oldfile
|
print "Old path:", oldfile
|
||||||
print "New path:", newfile
|
print "New path:", newfile
|
||||||
ans= "always"
|
ans= "always"
|
||||||
if ans == "always": opts.always = True
|
|
||||||
|
|
||||||
if ans or opts.always:
|
if opts.always:
|
||||||
make_path(newpath)
|
if not os.path.exists(newpath):
|
||||||
file_exists = does_file_exist(newfile)
|
os.mkdirs(newpath)
|
||||||
if file_exists:
|
if os.path.exists(newfile):
|
||||||
print "[!] File already exists, not copying"
|
print "[!] File already exists, not copying"
|
||||||
else:
|
else:
|
||||||
if same_partition(oldfile, newpath):
|
if self._same_partition(oldfile, newpath):
|
||||||
print "[*] Moving file"
|
print "[*] Moving file"
|
||||||
try:
|
try:
|
||||||
os.rename(oldfile, newfile)
|
os.rename(oldfile, newfile)
|
||||||
@@ -196,4 +182,6 @@ def main():
|
|||||||
print "Skipping file"
|
print "Skipping file"
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
|
||||||
|
t = TvOrganiser()
|
||||||
|
t.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user