本文整理汇总了Python中sickbeard.encodingKludge.ek函数的典型用法代码示例。如果您正苦于以下问题:Python ek函数的具体用法?Python ek怎么用?Python ek使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ek函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: parse
def parse(self, name):
name = self._unicodify(name)
cached = name_parser_cache.get(name)
if cached:
return cached
# break it into parts if there are any (dirname, file name, extension)
dir_name, file_name = ek.ek(os.path.split, name)
if self.is_file_name:
base_file_name = helpers.remove_non_release_groups(helpers.remove_extension(file_name))
else:
base_file_name = file_name
# use only the direct parent dir
dir_name = ek.ek(os.path.basename, dir_name)
# set up a result to use
final_result = ParseResult(name)
# try parsing the file name
file_name_result = self._parse_string(base_file_name)
# parse the dirname for extra info if needed
dir_name_result = self._parse_string(dir_name)
# build the ParseResult object
final_result.air_date = self._combine_results(file_name_result, dir_name_result, 'air_date')
if not final_result.air_date:
final_result.season_number = self._combine_results(file_name_result, dir_name_result, 'season_number')
final_result.episode_numbers = self._combine_results(file_name_result, dir_name_result, 'episode_numbers')
final_result.is_proper = self._combine_results(file_name_result, dir_name_result, 'is_proper')
# if the dirname has a release group/show name I believe it over the filename
final_result.series_name = self._combine_results(dir_name_result, file_name_result, 'series_name')
final_result.extra_info = self._combine_results(dir_name_result, file_name_result, 'extra_info')
final_result.release_group = self._combine_results(dir_name_result, file_name_result, 'release_group')
final_result.which_regex = []
if final_result == file_name_result:
final_result.which_regex = file_name_result.which_regex
elif final_result == dir_name_result:
final_result.which_regex = dir_name_result.which_regex
else:
if file_name_result:
final_result.which_regex += file_name_result.which_regex
if dir_name_result:
final_result.which_regex += dir_name_result.which_regex
# if there's no useful info in it then raise an exception
if final_result.season_number is None and not final_result.episode_numbers and final_result.air_date is None and not final_result.series_name:
raise InvalidNameException("Unable to parse " + name.encode(sickbeard.SYS_ENCODING, 'xmlcharrefreplace'))
name_parser_cache.add(name, final_result)
# return it
return final_result
开发者ID:PermaNulled,项目名称:SickBeard-XG,代码行数:60,代码来源:parser.py
示例2: rename_ep_file
def rename_ep_file(cur_path, new_path):
"""
Creates all folders needed to move a file to its new location, renames it, then cleans up any folders
left that are now empty.
cur_path: The absolute path to the file you want to move/rename
new_path: The absolute path to the destination for the file WITHOUT THE EXTENSION
"""
new_dest_dir, new_dest_name = os.path.split(new_path) #@UnusedVariable
cur_file_name, cur_file_ext = os.path.splitext(cur_path) #@UnusedVariable
if cur_file_ext[1:] in subtitleExtensions:
#Extract subtitle language from filename
sublang = os.path.splitext(cur_file_name)[1][1:]
#Check if the language extracted from filename is a valid language
try:
language = subliminal.language.Language(sublang, strict=True)
cur_file_ext = '.'+sublang+cur_file_ext
except ValueError:
pass
# put the extension on the incoming file
new_path += cur_file_ext
make_dirs(os.path.dirname(new_path))
# move the file
try:
logger.log(u"Renaming file from " + cur_path + " to " + new_path)
ek.ek(os.rename, cur_path, new_path)
except (OSError, IOError), e:
logger.log(u"Failed renaming " + cur_path + " to " + new_path + ": " + ex(e), logger.ERROR)
return False
开发者ID:JMDGBE,项目名称:Sick-Beard,代码行数:35,代码来源:helpers.py
示例3: chmodAsParent
def chmodAsParent(childPath):
if os.name == 'nt' or os.name == 'ce':
return
parentPath = ek.ek(os.path.dirname, childPath)
if not parentPath:
logger.log(u"No parent path provided in "+childPath+", unable to get permissions from it", logger.DEBUG)
return
parentMode = stat.S_IMODE(os.stat(parentPath)[stat.ST_MODE])
childPathStat = ek.ek(os.stat, childPath)
childPath_mode = stat.S_IMODE(childPathStat[stat.ST_MODE])
if ek.ek(os.path.isfile, childPath):
childMode = fileBitFilter(parentMode)
else:
childMode = parentMode
if childPath_mode == childMode:
return
childPath_owner = childPathStat.st_uid
user_id = os.geteuid()
if user_id !=0 and user_id != childPath_owner:
logger.log(u"Not running as root or owner of "+childPath+", not trying to set permissions", logger.DEBUG)
return
try:
ek.ek(os.chmod, childPath, childMode)
logger.log(u"Setting permissions for %s to %o as parent directory has %o" % (childPath, childMode, parentMode), logger.DEBUG)
except OSError:
logger.log(u"Failed to set permission for %s to %o" % (childPath, childMode), logger.ERROR)
开发者ID:JMDGBE,项目名称:Sick-Beard,代码行数:35,代码来源:helpers.py
示例4: hardlinkFile
def hardlinkFile(srcFile, destFile):
try:
ek.ek(link, srcFile, destFile)
fixSetGroupID(destFile)
except:
logger.log(u"Failed to create hardlink of " + srcFile + " at " + destFile + ". Copying instead", logger.ERROR)
copyFile(srcFile, destFile)
开发者ID:Weiry,项目名称:SickRage,代码行数:7,代码来源:helpers.py
示例5: get_season_thumb_path
def get_season_thumb_path(self, show_obj, season):
"""
Season thumbs for MediaBrowser go in Show Dir/Season X/folder.jpg
If no season folder exists, None is returned
"""
dir_list = [x for x in ek.ek(os.listdir, show_obj.location) if ek.ek(os.path.isdir, ek.ek(os.path.join, show_obj.location, x))]
season_dir_regex = '^Season\s+(\d+)$'
season_dir = None
for cur_dir in dir_list:
if season == 0 and cur_dir == 'Specials':
season_dir = cur_dir
break
match = re.match(season_dir_regex, cur_dir, re.I)
if not match:
continue
cur_season = int(match.group(1))
if cur_season == season:
season_dir = cur_dir
break
if not season_dir:
logger.log(u"Unable to find a season dir for season "+str(season), logger.DEBUG)
return None
logger.log(u"Using "+str(season_dir)+"/folder.jpg as season dir for season "+str(season), logger.DEBUG)
return ek.ek(os.path.join, show_obj.location, season_dir, 'folder.jpg')
开发者ID:ShaneMcC,项目名称:Sick-Beard,代码行数:35,代码来源:mediabrowser.py
示例6: backupVersionedFile
def backupVersionedFile(old_file, version):
numTries = 0
new_file = old_file + '.' + 'v' + str(version)
while not ek.ek(os.path.isfile, new_file):
time.sleep(0.01)
if not ek.ek(os.path.isfile, old_file):
logger.log(u"Not creating backup, " + old_file + " doesn't exist", logger.DEBUG)
break
try:
logger.log(u"Trying to back up " + old_file + " to " + new_file, logger.DEBUG)
shutil.copy(old_file, new_file)
logger.log(u"Backup done", logger.DEBUG)
break
except Exception, e:
logger.log(u"Error while trying to back up " + old_file + " to " + new_file + " : " + ex(e), logger.WARNING)
numTries += 1
time.sleep(1)
logger.log(u"Trying again.", logger.DEBUG)
if numTries >= 10:
logger.log(u"Unable to back up " + old_file + " to " + new_file + " please do it manually.", logger.ERROR)
return False
开发者ID:3ne,项目名称:SickRage,代码行数:25,代码来源:helpers.py
示例7: imageName
def imageName(self):
if ek.ek(
os.path.isfile,
ek.ek(os.path.join, sickbeard.PROG_DIR, "data", "images", "providers", self.getID() + ".png"),
):
return self.getID() + ".png"
return "newznab.png"
开发者ID:WoLpH,项目名称:SickBeard-TVRage,代码行数:7,代码来源:newznab.py
示例8: __init__
def __init__(self, file_path, nzb_name=None, process_method=None, is_priority=None):
"""
Creates a new post processor with the given file path and optionally an NZB name.
file_path: The path to the file to be processed
nzb_name: The name of the NZB which resulted in this file being downloaded (optional)
"""
# absolute path to the folder that is being processed
self.folder_path = ek.ek(os.path.dirname, ek.ek(os.path.abspath, file_path))
# full path to file
self.file_path = file_path
# file name only
self.file_name = ek.ek(os.path.basename, file_path)
# the name of the folder only
self.folder_name = ek.ek(os.path.basename, self.folder_path)
# name of the NZB that resulted in this folder
self.nzb_name = nzb_name
self.process_method = process_method if process_method else sickbeard.PROCESS_METHOD
self.in_history = False
self.release_group = None
self.is_proper = False
self.is_priority = is_priority
self.good_results = {self.NZB_NAME: False,
self.FOLDER_NAME: False,
self.FILE_NAME: False}
self.log = ''
开发者ID:dhellwich,项目名称:SickBeard-SickRage,代码行数:35,代码来源:postProcessor.py
示例9: _fanart_dir
def _fanart_dir(self, indexer_id=None):
"""
Builds up the full path to the fanart image cache directory
"""
args = [os.path.join, self._cache_dir(), 'fanart'] + \
(None is not indexer_id and [str(indexer_id).split('.')[0]] or [])
return ek.ek(os.path.abspath, ek.ek(*args))
开发者ID:JackDandy,项目名称:SickGear,代码行数:7,代码来源:image_cache.py
示例10: _makeURL
def _makeURL(self, result):
urls = []
filename = u''
if result.url.startswith('magnet'):
try:
torrent_hash = re.findall('urn:btih:([\w]{32,40})', result.url)[0].upper()
torrent_name = re.findall('dn=([^&]+)', result.url)[0]
if len(torrent_hash) == 32:
torrent_hash = b16encode(b32decode(torrent_hash)).upper()
if not torrent_hash:
logger.log("Unable to extract torrent hash from link: " + ex(result.url), logger.ERROR)
return (urls, filename)
urls = [
'http://torcache.net/torrent/' + torrent_hash + '.torrent',
'http://zoink.ch/torrent/' + torrent_name + '.torrent',
'http://torrage.com/torrent/' + torrent_hash + '.torrent',
]
except:
urls = [result.url]
else:
urls = [result.url]
if self.providerType == GenericProvider.TORRENT:
filename = ek.ek(os.path.join, sickbeard.TORRENT_DIR,
helpers.sanitizeFileName(result.name) + '.' + self.providerType)
elif self.providerType == GenericProvider.NZB:
filename = ek.ek(os.path.join, sickbeard.NZB_DIR,
helpers.sanitizeFileName(result.name) + '.' + self.providerType)
return (urls, filename)
开发者ID:bckwltn,项目名称:SickRage-MAC-MASTER,代码行数:34,代码来源:generic.py
示例11: _write_image
def _write_image(self, image_data, image_path):
"""
Saves the data in image_data to the location image_path. Returns True/False
to represent success or failure.
image_data: binary image data to write to file
image_path: file location to save the image to
"""
# don't bother overwriting it
if ek.ek(os.path.isfile, image_path):
logger.log(u"Image already exists, not downloading", logger.DEBUG)
return False
if not image_data:
logger.log(u"Unable to retrieve image, skipping", logger.WARNING)
return False
try:
outFile = ek.ek(open, image_path, "wb")
outFile.write(image_data)
outFile.close()
except IOError, e:
logger.log(
u"Unable to write image to "
+ image_path
+ " - are you sure the show folder is writable? "
+ str(e).decode("utf-8"),
logger.ERROR,
)
return False
开发者ID:innernaut,项目名称:Sick-Beard,代码行数:31,代码来源:generic.py
示例12: rename_ep_file
def rename_ep_file(cur_path, new_path, old_path_length=0):
"""
Creates all folders needed to move a file to its new location, renames it, then cleans up any folders
left that are now empty.
cur_path: The absolute path to the file you want to move/rename
new_path: The absolute path to the destination for the file WITHOUT THE EXTENSION
old_path_length: The length of media file path (old name) WITHOUT THE EXTENSION
"""
new_dest_dir, new_dest_name = os.path.split(new_path) # @UnusedVariable
if old_path_length == 0 or old_path_length > len(cur_path):
# approach from the right
cur_file_name, cur_file_ext = os.path.splitext(cur_path) # @UnusedVariable
else:
# approach from the left
cur_file_ext = cur_path[old_path_length:]
# put the extension on the incoming file
new_path += cur_file_ext
make_dirs(os.path.dirname(new_path))
# move the file
try:
logger.log(u"Renaming file from " + cur_path + " to " + new_path)
ek.ek(os.rename, cur_path, new_path)
except (OSError, IOError), e:
logger.log(u"Failed renaming " + cur_path + " to " + new_path + ": " + ex(e), logger.ERROR)
return False
开发者ID:riksmith,项目名称:Sick-Beard,代码行数:30,代码来源:helpers.py
示例13: process_media
def process_media(processPath, videoFiles, nzbName, process_method, force, is_priority, result):
processor = None
for cur_video_file in videoFiles:
if already_postprocessed(processPath, cur_video_file, force, result):
result.missedfiles.append(ek.ek(os.path.join, processPath, cur_video_file) + " : Already processed")
continue
cur_video_file_path = ek.ek(os.path.join, processPath, cur_video_file)
try:
processor = postProcessor.PostProcessor(cur_video_file_path, nzbName, process_method, is_priority)
result.result = processor.process()
process_fail_message = ""
except exceptions.PostProcessingFailed, e:
result.result = False
process_fail_message = ex(e)
if processor:
result.output += processor.log
if result.result:
result.output += logHelper(u"Processing succeeded for " + cur_video_file_path)
else:
result.output += logHelper(u"Processing failed for " + cur_video_file_path + ": " + process_fail_message,
logger.WARNING)
result.missedfiles.append(cur_video_file_path + " : Processing failed: " + process_fail_message)
result.aggresult = False
开发者ID:Bonekicker,项目名称:SickRage,代码行数:29,代码来源:processTV.py
示例14: subtitlesLanguages
def subtitlesLanguages(video_path):
"""Return a list detected subtitles for the given video file"""
resultList = []
if sickbeard.SUBTITLES_DIR and ek.ek(os.path.exists, sickbeard.SUBTITLES_DIR):
video_path = ek.ek(os.path.join, sickbeard.SUBTITLES_DIR, ek.ek(os.path.basename, video_path))
# Search subtitles in the relative path
if sickbeard.SUBTITLES_DIR:
video_path = ek.ek(os.path.join, ek.ek(os.path.dirname, video_path), sickbeard.SUBTITLES_DIR, ek.ek(os.path.basename, video_path))
languages = subliminal.video.scan_subtitle_languages(video_path)
for language in languages:
if hasattr(language, 'opensubtitles') and language.opensubtitles:
resultList.append(language.opensubtitles)
elif hasattr(language, 'alpha3') and language.alpha3:
resultList.append(language.alpha3)
elif hasattr(language, 'alpha2') and language.alpha2:
resultList.append(language.alpha2)
defaultLang = wantedLanguages()
if len(resultList) is 1 and len(defaultLang) is 1:
return defaultLang
if ('pob' in defaultLang or 'pb' in defaultLang) and ('pt' not in defaultLang and 'por' not in defaultLang):
resultList = [x if not x in ['por', 'pt'] else u'pob' for x in resultList]
return sorted(resultList)
开发者ID:scorpio13,项目名称:SickRage,代码行数:28,代码来源:subtitles.py
示例15: clean_url
def clean_url(url):
"""
Returns an cleaned url starting with a scheme and folder with trailing /
or an empty string
"""
if url and url.strip():
url = url.strip()
if '://' not in url:
url = '//' + url
scheme, netloc, path, query, fragment = urlparse.urlsplit(url, 'http')
if not path.endswith('/'):
basename, ext = ek.ek(os.path.splitext, ek.ek(os.path.basename, path)) # @UnusedVariable
if not ext:
path = path + '/'
cleaned_url = urlparse.urlunsplit((scheme, netloc, path, query, fragment))
else:
cleaned_url = ''
return cleaned_url
开发者ID:BrendenCA,项目名称:SickRage,代码行数:26,代码来源:config.py
示例16: makeDir
def makeDir (dir):
if not ek.ek(os.path.isdir, dir):
try:
ek.ek(os.makedirs, dir)
except OSError:
return False
return True
开发者ID:majello,项目名称:Sick-Beard-Majello,代码行数:7,代码来源:helpers.py
示例17: _delete_files
def _delete_files(self, process_path, notwanted_files, use_trash=False):
if not self.any_vid_processed:
return
# Delete all file not needed
for cur_file in notwanted_files:
cur_file_path = ek.ek(os.path.join, process_path, cur_file)
if not ek.ek(os.path.isfile, cur_file_path):
continue # Prevent error when a notwantedfiles is an associated files
# check first the read-only attribute
file_attribute = ek.ek(os.stat, cur_file_path)[0]
if not file_attribute & stat.S_IWRITE:
# File is read-only, so make it writeable
self._log_helper(u'Changing ReadOnly flag for file ' + cur_file)
try:
ek.ek(os.chmod, cur_file_path, stat.S_IWRITE)
except OSError as e:
self._log_helper(u'Cannot change permissions of %s: %s' % (cur_file_path, str(e.strerror)))
try:
if use_trash:
ek.ek(send2trash, cur_file_path)
else:
ek.ek(os.remove, cur_file_path)
except OSError as e:
self._log_helper(u'Unable to delete file %s: %s' % (cur_file, str(e.strerror)))
if True is not ek.ek(os.path.isfile, cur_file_path):
self._log_helper(u'Deleted file ' + cur_file)
开发者ID:joshguerette,项目名称:SickGear,代码行数:32,代码来源:processTV.py
示例18: _delete_folder
def _delete_folder(self, folder, check_empty=True):
# check if it's a folder
if not ek.ek(os.path.isdir, folder):
return False
# make sure it isn't TV_DOWNLOAD_DIR
if sickbeard.TV_DOWNLOAD_DIR and helpers.real_path(sickbeard.TV_DOWNLOAD_DIR) == helpers.real_path(folder):
return False
# check if it's empty folder when wanted checked
if check_empty and ek.ek(os.listdir, folder):
return False
# try deleting folder
try:
shutil.rmtree(folder)
except (OSError, IOError) as e:
logger.log(u'Warning: unable to delete folder: %s: %s' % (folder, ex(e)), logger.WARNING)
return False
if ek.ek(os.path.isdir, folder):
logger.log(u'Warning: unable to delete folder: %s' % folder, logger.WARNING)
return False
self._log_helper(u'Deleted folder ' + folder, logger.MESSAGE)
return True
开发者ID:joshguerette,项目名称:SickGear,代码行数:27,代码来源:processTV.py
示例19: isBeingWritten
def isBeingWritten(filepath):
# Return True if file was modified within 60 seconds. it might still be being written to.
ctime = max(ek.ek(os.path.getctime, filepath), ek.ek(os.path.getmtime, filepath))
if ctime > time.time() - 60:
return True
return False
开发者ID:Weiry,项目名称:SickRage,代码行数:7,代码来源:helpers.py
示例20: _find_ep_destination_folder
def _find_ep_destination_folder(self, ep_obj):
# if we're supposed to put it in a season folder then figure out what folder to use
season_folder = ''
if ep_obj.show.seasonfolders:
# search the show dir for season folders
for curDir in ek.ek(os.listdir, ep_obj.show.location):
if not ek.ek(os.path.isdir, ek.ek(os.path.join, ep_obj.show.location, curDir)):
continue
# if it's a season folder, check if it's the one we want
match = re.match(".*season\s*(\d+)", curDir, re.IGNORECASE)
if match:
# if it's the correct season folder then stop looking
if int(match.group(1)) == int(ep_obj.season):
season_folder = curDir
break
# if we couldn't find the right one then just use the season folder defaut format
if season_folder == '':
# for air-by-date shows use the year as the season folder
if ep_obj.show.air_by_date:
season_folder = str(ep_obj.airdate.year)
else:
try:
season_folder = sickbeard.SEASON_FOLDERS_FORMAT % (ep_obj.season)
except TypeError:
logger.log(u"Error: Your season folder format is incorrect, try setting it back to the default")
dest_folder = ek.ek(os.path.join, ep_obj.show.location, season_folder)
return dest_folder
开发者ID:cytec,项目名称:pyEncoder,代码行数:34,代码来源:postProcessor.py
注:本文中的sickbeard.encodingKludge.ek函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论