本文整理汇总了Python中sabnzbd.misc.renamer函数的典型用法代码示例。如果您正苦于以下问题:Python renamer函数的具体用法?Python renamer怎么用?Python renamer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了renamer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: move
def move(self, workdir_complete):
ok = True
if self.type == 'movie':
move_to_parent = True
# check if we should leave the files inside an extra folder
if cfg.movie_extra_folders():
# if there is a folder in the download, leave it in an extra folder
move_to_parent = not check_for_folder(workdir_complete)
if move_to_parent:
workdir_complete, ok = move_to_parent_folder(workdir_complete)
else:
workdir_complete, ok = move_to_parent_folder(workdir_complete)
if not ok:
return workdir_complete, False
path, part = os.path.split(workdir_complete)
if '%fn' in part and self.sorter.fname:
old = workdir_complete
workdir_complete = os.path.join(path, part.replace('%fn', self.sorter.fname))
workdir_complete = get_unique_path(workdir_complete, create_dir=False)
try:
renamer(old, workdir_complete)
except:
logging.error(T('Cannot create directory %s'), clip_path(workdir_complete))
workdir_complete = old
ok = False
return workdir_complete, ok
开发者ID:sabnzbd,项目名称:sabnzbd,代码行数:27,代码来源:sorting.py
示例2: rename
def rename(self, files, current_path):
logging.debug("Renaming Date file")
renamed = None
#find the master file to rename
for file in files:
if is_full_path(file):
filepath = file.replace('_UNPACK_', '')
else:
filepath = os.path.join(current_path, file)
if os.path.exists(filepath):
size = os.stat(filepath).st_size
if size > 130000000:
if 'sample' not in file:
tmp, ext = os.path.splitext(file)
newname = "%s%s" % (self.filename_set,ext)
newname = newname.replace('%fn',tmp)
newpath = os.path.join(current_path, newname)
if not os.path.exists(newpath):
try:
logging.debug("Rename: %s to %s", filepath,newpath)
renamer(filepath,newpath)
except:
logging.error(Ta('[email protected]'), current_path, newpath)
logging.debug("Traceback: ", exc_info = True)
rename_similar(current_path, file, self.filename_set)
break
开发者ID:melfahn,项目名称:sabscripts,代码行数:27,代码来源:tvsort.py
示例3: rename_similar
def rename_similar(folder, skip_ext, name, skipped_files):
""" Rename all other files in the 'folder' hierarchy after 'name'
and move them to the root of 'folder'.
Files having extension 'skip_ext' will be moved, but not renamed.
Don't touch files in list `skipped_files`
"""
logging.debug('Give files in set "%s" matching names.', name)
folder = os.path.normpath(folder)
skip_ext = skip_ext.lower()
for root, dirs, files in os.walk(folder):
for f in files:
path = os.path.join(root, f)
if path in skipped_files:
continue
org, ext = os.path.splitext(f)
if ext.lower() == skip_ext:
# Move file, but do not rename
newpath = os.path.join(folder, f)
else:
# Move file and rename
newname = "%s%s" % (name, ext)
newname = newname.replace('%fn', org)
newpath = os.path.join(folder, newname)
if path != newpath:
newpath = get_unique_filename(newpath)
try:
logging.debug("Rename: %s to %s", path, newpath)
renamer(path, newpath)
except:
logging.error(T('Failed to rename similar file: %s to %s'), clip_path(path), clip_path(newpath))
logging.info("Traceback: ", exc_info=True)
cleanup_empty_directories(folder)
开发者ID:sabnzbd,项目名称:sabnzbd,代码行数:33,代码来源:sorting.py
示例4: rename
def rename(self, files, current_path):
""" Renaming Date file """
logging.debug("Renaming Date file")
# find the master file to rename
for file in files:
if is_full_path(file):
filepath = os.path.normpath(file)
else:
filepath = os.path.normpath(os.path.join(current_path, file))
if os.path.exists(filepath):
size = os.stat(filepath).st_size
if size > cfg.movie_rename_limit.get_int():
if 'sample' not in file:
self.fname, ext = os.path.splitext(os.path.split(file)[1])
newname = "%s%s" % (self.filename_set, ext)
newname = newname.replace('%fn', self.fname)
newpath = os.path.join(current_path, newname)
if not os.path.exists(newpath):
try:
logging.debug("Rename: %s to %s", filepath, newpath)
renamer(filepath, newpath)
except:
logging.error(T('Failed to rename: %s to %s'), clip_path(current_path), clip_path(newpath))
logging.info("Traceback: ", exc_info=True)
rename_similar(current_path, ext, self.filename_set, ())
break
开发者ID:sabnzbd,项目名称:sabnzbd,代码行数:27,代码来源:sorting.py
示例5: _assemble
def _assemble(nzf, path, dupe):
if os.path.exists(path):
unique_path = get_unique_filename(path)
if dupe:
path = unique_path
else:
renamer(path, unique_path)
fout = open(path, 'ab')
if cfg.quick_check():
md5 = new_md5()
else:
md5 = None
_type = nzf.type
decodetable = nzf.decodetable
for articlenum in decodetable:
sleep(0.001)
article = decodetable[articlenum]
data = ArticleCache.do.load_article(article)
if not data:
logging.info(T('%s missing'), article)
else:
# yenc data already decoded, flush it out
if _type == 'yenc':
fout.write(data)
if md5:
md5.update(data)
# need to decode uu data now
elif _type == 'uu':
data = data.split('\r\n')
chunks = []
for line in data:
if not line:
continue
if line == '-- ' or line.startswith('Posted via '):
continue
try:
tmpdata = binascii.a2b_uu(line)
chunks.append(tmpdata)
except binascii.Error, msg:
# Workaround for broken uuencoders by
# /Fredrik Lundh
nbytes = (((ord(line[0]) - 32) & 63) * 4 + 5) / 3
try:
tmpdata = binascii.a2b_uu(line[:nbytes])
chunks.append(tmpdata)
except binascii.Error, msg:
logging.info('Decode failed in part %s: %s', article.article, msg)
data = ''.join(chunks)
fout.write(data)
if md5:
md5.update(data)
开发者ID:FiddleCastro,项目名称:sabnzbd,代码行数:59,代码来源:assembler.py
示例6: rename_with_ext
def rename_with_ext(self, workdir_complete):
""" Special renamer for %ext """
if self.sorter.rename_or_not and '%ext' in workdir_complete and self.ext:
# Replace %ext with extension
newpath = workdir_complete.replace('%ext', self.ext)
try:
renamer(workdir_complete, newpath)
except:
return newpath, False
return newpath, True
else:
return workdir_complete, True
开发者ID:sabnzbd,项目名称:sabnzbd,代码行数:12,代码来源:sorting.py
示例7: prepare_extraction_path
def prepare_extraction_path(nzo):
""" Based on the information that we have, generate
the extraction path and create the directory.
Separated so it can be called from DirectUnpacker
"""
one_folder = False
marker_file = None
# Determine class directory
catdir = config.get_categories(nzo.cat).dir()
if catdir.endswith('*'):
catdir = catdir.strip('*')
one_folder = True
complete_dir = real_path(cfg.complete_dir.get_path(), catdir)
complete_dir = long_path(complete_dir)
# TV/Movie/Date Renaming code part 1 - detect and construct paths
if cfg.enable_meta():
file_sorter = Sorter(nzo, nzo.cat)
else:
file_sorter = Sorter(None, nzo.cat)
complete_dir = file_sorter.detect(nzo.final_name, complete_dir)
if file_sorter.sort_file:
one_folder = False
complete_dir = sanitize_and_trim_path(complete_dir)
if one_folder:
workdir_complete = create_dirs(complete_dir)
else:
workdir_complete = get_unique_path(os.path.join(complete_dir, nzo.final_name), create_dir=True)
marker_file = set_marker(workdir_complete)
if not workdir_complete or not os.path.exists(workdir_complete):
logging.error(T('Cannot create final folder %s') % unicoder(os.path.join(complete_dir, nzo.final_name)))
raise IOError
if cfg.folder_rename() and not one_folder:
prefixed_path = prefix(workdir_complete, '_UNPACK_')
tmp_workdir_complete = get_unique_path(prefix(workdir_complete, '_UNPACK_'), create_dir=False)
try:
renamer(workdir_complete, tmp_workdir_complete)
except:
pass # On failure, just use the original name
# Is the unique path different? Then we also need to modify the final path
if prefixed_path != tmp_workdir_complete:
workdir_complete = workdir_complete + os.path.splitext(tmp_workdir_complete)[1]
else:
tmp_workdir_complete = workdir_complete
return tmp_workdir_complete, workdir_complete, file_sorter, one_folder, marker_file
开发者ID:jamesstout,项目名称:sabnzbd,代码行数:52,代码来源:postproc.py
示例8: rename
def rename(self, files, current_path):
""" Rename for Series
"""
logging.debug("Renaming Series")
largest = (None, None, 0)
def to_filepath(f, current_path):
if is_full_path(f):
filepath = f.replace('_UNPACK_', '')
else:
filepath = os.path.join(current_path, f)
return filepath
# Create a generator of filepaths, ignore sample files and excluded files (vobs ect)
filepaths = ((file, to_filepath(file, current_path)) for file in files if not RE_SAMPLE.search(file) \
and get_ext(file) not in EXCLUDED_FILE_EXTS)
# Find the largest existing file
for file, fp in filepaths:
# If for some reason the file no longer exists, skip
if not os.path.exists(fp):
continue
size = os.stat(fp).st_size
f_file, f_fp, f_size = largest
if size > f_size:
largest = (file, fp, size)
file, filepath, size = largest
# >20MB
if filepath and size > 20971520:
tmp, self.ext = os.path.splitext(file)
self.fname = tmp
newname = "%s%s" % (self.filename_set, self.ext)
# Replace %fn with the original filename
newname = newname.replace('%fn', tmp)
newpath = os.path.join(current_path, newname)
# Replace %ext with extension
newpath = newpath.replace('%ext', self.ext)
if not os.path.exists(newpath):
try:
logging.debug("Rename: %s to %s", filepath, newpath)
renamer(filepath, newpath)
except:
logging.error("Failed to rename: %s to %s", current_path, newpath)
logging.info("Traceback: ", exc_info = True)
rename_similar(current_path, self.ext, self.filename_set)
else:
logging.debug('Current path already exists, skipping rename, %s', newpath)
else:
logging.debug('Nothing to rename, %s', files)
开发者ID:Adrellias,项目名称:sabnzbd,代码行数:51,代码来源:tvsort.py
示例9: collapse_folder
def collapse_folder(oldpath, newpath):
""" Rename folder, collapsing when there's just a single subfolder
oldpath --> newpath OR oldpath/subfolder --> newpath
"""
orgpath = oldpath
items = globber(oldpath)
if len(items) == 1:
folder_path = items[0]
folder = os.path.split(folder_path)[1]
if os.path.isdir(folder_path) and folder not in ('VIDEO_TS', 'AUDIO_TS'):
logging.info('Collapsing %s', os.path.join(newpath, folder))
oldpath = folder_path
renamer(oldpath, newpath)
try:
remove_dir(orgpath)
except:
pass
开发者ID:k7o,项目名称:sabnzbd,代码行数:18,代码来源:postproc.py
示例10: rename_similar
def rename_similar(path, file, name):
logging.debug('Renaming files similar to: %s to %s', file, name)
file_prefix, ext = os.path.splitext(file)
for root, dirs, files in os.walk(path):
for _file in files:
fpath = os.path.join(root, _file)
tmp, ext = os.path.splitext(_file)
if tmp == file_prefix:
newname = "%s%s" % (name,ext)
newname = newname.replace('%fn',tmp)
newpath = os.path.join(path, newname)
if not os.path.exists(newpath):
try:
logging.debug("Rename: %s to %s", fpath,newpath)
renamer(fpath,newpath)
except:
logging.error(Ta('[email protected]'), path, newpath)
logging.debug("Traceback: ", exc_info = True)
开发者ID:melfahn,项目名称:sabscripts,代码行数:18,代码来源:tvsort.py
示例11: _assemble
def _assemble(nzf, path, dupe):
if os.path.exists(path):
unique_path = get_unique_filename(path)
if dupe:
path = unique_path
else:
renamer(path, unique_path)
fout = open(path, "ab")
if cfg.quick_check():
md5 = new_md5()
else:
md5 = None
decodetable = nzf.decodetable
for articlenum in decodetable:
# Break if deleted during writing
if nzf.nzo.status is Status.DELETED:
break
# Sleep to allow decoder/assembler switching
sleep(0.001)
article = decodetable[articlenum]
data = ArticleCache.do.load_article(article)
if not data:
logging.info(T("%s missing"), article)
else:
# yenc data already decoded, flush it out
fout.write(data)
if md5:
md5.update(data)
fout.flush()
fout.close()
set_permissions(path)
if md5:
nzf.md5sum = md5.digest()
del md5
return path
开发者ID:sabnzbd,项目名称:sabnzbd,代码行数:44,代码来源:assembler.py
示例12: rename_and_collapse_folder
def rename_and_collapse_folder(oldpath, newpath, files):
""" Rename folder, collapsing when there's just a single subfolder
oldpath --> newpath OR oldpath/subfolder --> newpath
Modify list of filenames accordingly
"""
orgpath = oldpath
items = globber(oldpath)
if len(items) == 1:
folder_path = items[0]
folder = os.path.split(folder_path)[1]
if os.path.isdir(folder_path) and folder not in ('VIDEO_TS', 'AUDIO_TS'):
logging.info('Collapsing %s', os.path.join(newpath, folder))
oldpath = folder_path
oldpath = os.path.normpath(oldpath)
newpath = os.path.normpath(newpath)
files = [os.path.normpath(f).replace(oldpath, newpath) for f in files]
renamer(oldpath, newpath)
try:
remove_dir(orgpath)
except:
pass
return files
开发者ID:BigMarlin1,项目名称:sabnzbd,代码行数:24,代码来源:postproc.py
示例13: process_job
#.........这里部分代码省略.........
complete_dir = create_dirs(complete_dir)
else:
catdir = config.get_categories(cat).dir()
if catdir.endswith("*"):
catdir = catdir.strip("*")
one_folder = True
complete_dir = real_path(cfg.complete_dir.get_path(), catdir)
complete_dir = long_path(complete_dir)
# TV/Movie/Date Renaming code part 1 - detect and construct paths
if cfg.enable_meta():
file_sorter = Sorter(nzo, cat)
else:
file_sorter = Sorter(None, cat)
complete_dir = file_sorter.detect(dirname, complete_dir)
if file_sorter.sort_file:
one_folder = False
complete_dir = sanitize_and_trim_path(complete_dir)
if one_folder:
workdir_complete = create_dirs(complete_dir)
else:
workdir_complete = get_unique_path(os.path.join(complete_dir, dirname), create_dir=True)
marker_file = set_marker(workdir_complete)
if not workdir_complete or not os.path.exists(workdir_complete):
crash_msg = T("Cannot create final folder %s") % unicoder(os.path.join(complete_dir, dirname))
raise IOError
if cfg.folder_rename() and not one_folder:
tmp_workdir_complete = prefix(workdir_complete, "_UNPACK_")
try:
renamer(workdir_complete, tmp_workdir_complete)
except:
pass # On failure, just use the original name
else:
tmp_workdir_complete = workdir_complete
newfiles = []
# Run Stage 2: Unpack
if flag_unpack:
if all_ok:
# set the current nzo status to "Extracting...". Used in History
nzo.status = Status.EXTRACTING
logging.info("Running unpack_magic on %s", filename)
short_complete = short_path(tmp_workdir_complete)
unpack_error, newfiles = unpack_magic(
nzo, short_path(workdir), short_complete, flag_delete, one_folder, (), (), (), (), ()
)
if short_complete != tmp_workdir_complete:
newfiles = [f.replace(short_complete, tmp_workdir_complete) for f in newfiles]
logging.info("unpack_magic finished on %s", filename)
else:
nzo.set_unpack_info("Unpack", T("No post-processing because of failed verification"))
if cfg.safe_postproc():
all_ok = all_ok and not unpack_error
if all_ok:
# Move any (left-over) files to destination
nzo.status = Status.MOVING
nzo.set_action_line(T("Moving"), "...")
for root, _dirs, files in os.walk(workdir):
if not root.endswith(JOB_ADMIN):
for file_ in files:
开发者ID:FiddleCastro,项目名称:sabnzbd,代码行数:67,代码来源:postproc.py
示例14: process_job
#.........这里部分代码省略.........
if all_ok:
one_folder = False
## Determine class directory
if cfg.create_group_folders():
complete_dir = addPrefixes(cfg.complete_dir.get_path(), nzo.dirprefix)
complete_dir = create_dirs(complete_dir)
else:
catdir = config.get_categories(cat).dir()
if catdir.endswith('*'):
catdir = catdir.strip('*')
one_folder = True
complete_dir = real_path(cfg.complete_dir.get_path(), catdir)
## TV/Movie/Date Renaming code part 1 - detect and construct paths
file_sorter = Sorter(cat)
complete_dir = file_sorter.detect(dirname, complete_dir)
if file_sorter.sort_file:
one_folder = False
if one_folder:
workdir_complete = create_dirs(complete_dir)
else:
workdir_complete = get_unique_path(os.path.join(complete_dir, dirname), create_dir=True)
marker_file = set_marker(workdir_complete)
if not workdir_complete or not os.path.exists(workdir_complete):
crash_msg = T('Cannot create final folder %s') % unicoder(os.path.join(complete_dir, dirname))
raise IOError
if cfg.folder_rename() and not one_folder:
tmp_workdir_complete = prefix(workdir_complete, '_UNPACK_')
try:
renamer(workdir_complete, tmp_workdir_complete)
except:
pass # On failure, just use the original name
else:
tmp_workdir_complete = workdir_complete
newfiles = []
## Run Stage 2: Unpack
if flag_unpack:
if all_ok:
#set the current nzo status to "Extracting...". Used in History
nzo.status = Status.EXTRACTING
logging.info("Running unpack_magic on %s", filename)
unpack_error, newfiles = unpack_magic(nzo, workdir, tmp_workdir_complete, flag_delete, one_folder, (), (), (), ())
logging.info("unpack_magic finished on %s", filename)
else:
nzo.set_unpack_info('Unpack', T('No post-processing because of failed verification'))
if cfg.safe_postproc():
all_ok = all_ok and not unpack_error
if all_ok:
## Move any (left-over) files to destination
nzo.status = Status.MOVING
nzo.set_action_line(T('Moving'), '...')
for root, dirs, files in os.walk(workdir):
if not root.endswith(JOB_ADMIN):
for file_ in files:
path = os.path.join(root, file_)
new_path = path.replace(workdir, tmp_workdir_complete)
ok, new_path = move_to_path(path, new_path)
newfiles.append(new_path)
if not ok:
开发者ID:BigMarlin1,项目名称:sabnzbd,代码行数:67,代码来源:postproc.py
示例15: parring
def parring(nzo, workdir):
""" Perform par processing. Returns: (par_error, re_add) """
filename = nzo.final_name
notifier.send_notification(T('Post-processing'), filename, 'pp')
logging.info('Starting verification and repair of %s', filename)
# Get verification status of sets
verified = sabnzbd.load_data(VERIFIED_FILE, nzo.workpath, remove=False) or {}
repair_sets = nzo.partable.keys()
re_add = False
par_error = False
single = len(repair_sets) == 1
if repair_sets:
for setname in repair_sets:
if cfg.ignore_samples() and RE_SAMPLE.search(setname.lower()):
continue
if not verified.get(setname, False):
logging.info("Running verification and repair on set %s", setname)
parfile_nzf = nzo.partable[setname]
if os.path.exists(os.path.join(nzo.downpath, parfile_nzf.filename)) or parfile_nzf.extrapars:
need_re_add, res = par2_repair(parfile_nzf, nzo, workdir, setname, single=single)
# Was it aborted?
if not nzo.pp_active:
re_add = False
par_error = True
break
re_add = re_add or need_re_add
verified[setname] = res
else:
continue
par_error = par_error or not res
else:
# Obfuscated par2 check
logging.info('No par2 sets found, running obfuscated check on %s', filename)
# Get the NZF's and sort them based on size
nzfs_sorted = sorted(nzo.finished_files, key=lambda x: x.bytes)
# We will have to make 'fake' par files that are recognized
par2_vol = 0
par2_filename = None
for nzf_try in nzfs_sorted:
# run through list of files, looking for par2 signature..
logging.debug("Checking par2 signature of %s", nzf_try.filename)
try:
nzf_path = os.path.join(workdir, nzf_try.filename)
if(is_parfile(nzf_path)):
# We need 1 base-name so they are recognized as 1 set
if not par2_filename:
par2_filename = nzf_path
# Rename so handle_par2() picks it up
newpath = '%s.vol%d+%d.par2' % (par2_filename, par2_vol, par2_vol + 1)
renamer(nzf_path, newpath)
nzf_try.filename = os.path.split(newpath)[1]
# Let the magic happen
nzo.handle_par2(nzf_try, file_done=True)
par2_vol += 1
except:
pass
if par2_vol > 0:
# Pars found, we do it again
par_error, re_add = parring(nzo, workdir)
else:
# We must not have found any par2..
logging.info("No par2 sets for %s", filename)
nzo.set_unpack_info('Repair', T('[%s] No par2 sets') % unicoder(filename))
if cfg.sfv_check() and not verified.get('', False):
par_error = not try_sfv_check(nzo, workdir, '')
verified[''] = not par_error
# If still no success, do RAR-check
if not par_error and cfg.enable_unrar():
par_error = not try_rar_check(nzo, workdir, '')
verified[''] = not par_error
if re_add:
logging.info('Re-added %s to queue', filename)
if nzo.priority != TOP_PRIORITY:
nzo.priority = REPAIR_PRIORITY
sabnzbd.nzbqueue.add_nzo(nzo)
sabnzbd.downloader.Downloader.do.resume_from_postproc()
sabnzbd.save_data(verified, VERIFIED_FILE, nzo.workpath)
logging.info('Verification and repair finished for %s', filename)
return par_error, re_add
开发者ID:Hellowlol,项目名称:sabnzbd,代码行数:91,代码来源:postproc.py
注:本文中的sabnzbd.misc.renamer函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论