• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python unicode_helper.p函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中unicode_helper.p函数的典型用法代码示例。如果您正苦于以下问题:Python p函数的具体用法?Python p怎么用?Python p使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了p函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: copy_file

def copy_file(old, new):
    """Copy 'old' file to 'new'.
    """
    p("Copying %s to %s" % (old, new))
    log().debug("Copying %r to %r" % (old, new))
    shutil.copyfile(old, new)
    shutil.copystat(old, new)
开发者ID:lahwaacz,项目名称:tvnamer,代码行数:7,代码来源:renamer.py


示例2: tvnamer

def tvnamer(paths):
    """Main tvnamer function, takes an array of paths, does stuff.
    """
    # Warn about move_files function
    if Config['move_files_enable']:
        import warnings
        warnings.warn("The move_files feature is still under development. "
            "Be very careful with it.\n"
            "It has not been heavily tested, and is not recommended for "
            "general use yet.")

    if Config['force_name'] is not None:
        import warnings
        warnings.warn("The --name argument is a temporary solution, and will"
            "be removed at some point in the future. Do no depend on it")

    p("#" * 20)
    p("# Starting tvnamer")

    episodes_found = []

    for cfile in findFiles(paths):
        parser = FileParser(cfile)
        try:
            episode = parser.parse()
        except InvalidFilename, e:
            warn("Invalid filename: %s" % e)
        else:
            if episode.seriesname is None:
                warn("Parsed filename did not contain series name, skipping: %s" % cfile)
            else:
                episodes_found.append(episode)
开发者ID:oracal,项目名称:tvnamer,代码行数:32,代码来源:main.py


示例3: rename_file

def rename_file(old, new):
    """Rename 'old' file to 'new'. Both files must be on the same partition.
    Preserves access and modification time.
    """
    p("Renaming %s to %s" % (old, new))
    log().debug("Renaming %r to %r" % (old, new))
    stat = os.stat(old)
    os.rename(old, new)
    os.utime(new, (stat.st_atime, stat.st_mtime))
开发者ID:lahwaacz,项目名称:tvnamer,代码行数:9,代码来源:renamer.py


示例4: rename_file

def rename_file(old, new):
    p("rename %s to %s" % (old, new))
    stat = os.stat(old)
    os.rename(old, new)
    try:
        os.utime(new, (stat.st_atime, stat.st_mtime))
    except OSError, ex:
        if ex.errno == errno.EPERM:
            warn("WARNING: Could not preserve times for %s "
                 "(owner UID mismatch?)" % new)
        else:
            raise
开发者ID:shaleh,项目名称:tvnamer,代码行数:12,代码来源:utils.py


示例5: doMoveFile

def doMoveFile(cnamer, destDir):
    """Moves file to destDir"""
    if not Config['move_files_enable']:
        raise ValueError("move_files feature is disabled but doMoveFile was called")

    if Config['move_files_destination'] is None:
        raise ValueError("Config value for move_files_destination cannot be None if move_files_enabled is True")

    p("New directory:", destDir)
    try:
        cnamer.newPath(destDir)
    except OSError, e:
        warn(unicode(e))
开发者ID:basti1,项目名称:Sick-Beard,代码行数:13,代码来源:main.py


示例6: newPath

    def newPath(self, new_path = None, new_fullpath = None, force = False, always_copy = False, always_move = False, create_dirs = True, getPathPreview = False):
        """Moves the file to a new path.
        If it is on the same partition, it will be moved (unless always_copy is True)
        If it is on a different partition, it will be copied.
        If the target file already exists, it will raise OSError unless force is True.
        """
        old_fileinfo = self.filename
	p("self.filename: %s" % (self.filename))
	p("old_fileinfo: %s" % (old_fileinfo))

        if always_copy and always_move:
            raise ValueError("Both always_copy and always_move cannot be specified")

        if (new_path is None and new_fullpath is None) or (new_path is not None and new_fullpath is not None):
            raise ValueError("Specify only new_dir or new_fullpath")

        if new_path is not None:
            old_dir, old_filename = os.path.split(self.filename)

            # Join new filepath to old one (to handle realtive dirs)
            new_dir = os.path.abspath(os.path.join(old_dir, new_path))

            # Join new filename onto new filepath
            new_fullpath = os.path.join(new_dir, old_filename)

        else:
            old_dir, old_filename = os.path.split(self.filename)

            # Join new filepath to old one (to handle realtive dirs)
            new_fullpath = os.path.abspath(os.path.join(old_dir, new_fullpath))

            new_dir = os.path.dirname(new_fullpath)


        if len(Config['move_files_fullpath_replacements']) > 0:
            p("Before custom full path replacements: %s" % (new_fullpath))
            new_fullpath = applyCustomFullpathReplacements(new_fullpath)
            new_dir = os.path.dirname(new_fullpath)

        p("New path: %s" % new_fullpath)

        if getPathPreview:
            return new_fullpath

        if create_dirs:
            p("Creating directory %s" % new_dir)
            try:
                os.makedirs(new_dir)
            except OSError, e:
                if e.errno != 17:
                    raise
开发者ID:r0b0ticus,项目名称:tvnamer,代码行数:51,代码来源:utils.py


示例7: processFile

def processFile(tvdb_instance, episode):
    """Gets episode name, prompts user for input
    """
    p("#" * 20)
    p("# Processing file: %s" % episode.fullfilename)

    if len(Config['input_filename_replacements']) > 0:
        replaced = applyCustomInputReplacements(episode.fullfilename)
        p("# With custom replacements: %s" % (replaced))

    # Use force_name option. Done after input_filename_replacements so
    # it can be used to skip the replacements easily
    if Config['force_name'] is not None:
        episode.seriesname = Config['force_name']

    p("# Detected series: %s (%s)" % (episode.seriesname, episode.number_string()))

    try:
        episode.populateFromTvdb(tvdb_instance, force_name=Config['force_name'], series_id=Config['series_id'])
    except (DataRetrievalError, ShowNotFound), errormsg:
        if Config['always_rename'] and Config['skip_file_on_error'] is True:
            warn("Skipping file due to error: %s" % errormsg)
            return
        else:
            warn(errormsg)
开发者ID:rwycuff33,项目名称:mover,代码行数:25,代码来源:main.py


示例8: delete_file

def delete_file(fpath):
    """On OS X: Trashes a path using the Finder, via OS X's Scripting Bridge.
    On other platforms: unlinks file.
    """

    try:
        from AppKit import NSURL
        from ScriptingBridge import SBApplication
    except ImportError:
        p("Deleting %s" % fpath)
        log().debug("Deleting %r" % fpath)
        os.unlink(fpath)
    else:
        p("Trashing %s" % fpath)
        log().debug("Trashing %r" % fpath)
        targetfile = NSURL.fileURLWithPath_(fpath)
        finder = SBApplication.applicationWithBundleIdentifier_("com.apple.Finder")
        items = finder.items().objectAtLocation_(targetfile)
        items.delete()
开发者ID:lahwaacz,项目名称:tvnamer,代码行数:19,代码来源:renamer.py


示例9: newName

    def newName(self, newName, force = False):
        """Renames a file, keeping the path the same.
        """
        filepath, filename = os.path.split(self.filename)
        filename, _ = os.path.splitext(filename)
	global oldfileinfo
	oldfileinfo = self.filename
	p("self.filename: %s" % (self.filename))

        newpath = os.path.join(filepath, newName)

        if os.path.isfile(newpath):
            # If the destination exists, raise exception unless force is True
            if not force:
                raise OSError("File %s already exists, not forcefully renaming %s" % (
                    newpath, self.filename))

        os.rename(self.filename, newpath)
        self.filename = newpath
开发者ID:r0b0ticus,项目名称:tvnamer,代码行数:19,代码来源:utils.py


示例10: main

def main():
    """Parses command line arguments, displays errors from tvnamer in terminal
    """
    opter = cliarg_parser.getCommandlineParser(defaults)

    opts, args = opter.parse_args()

    args = [x.decode("utf-8") for x in args]

    if opts.verbose:
        logging.basicConfig(
            level = logging.DEBUG,
            format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
    else:
        logging.basicConfig()

    # If a config is specified, load it, update the defaults using the loaded
    # values, then reparse the options with the updated defaults.
    default_configuration = os.path.expanduser("~/.tvnamer.json")

    if opts.loadconfig is not None:
        # Command line overrides loading ~/.tvnamer.json
        configToLoad = opts.loadconfig
    elif os.path.isfile(default_configuration):
        # No --config arg, so load default config if it exists
        configToLoad = default_configuration
    else:
        # No arg, nothing at default config location, don't load anything
        configToLoad = None

    if configToLoad is not None:
        p("Loading config: %s" % (configToLoad))
        try:
            loadedConfig = json.load(open(configToLoad))
        except ValueError, e:
            p("Error loading config: %s" % e)
            opter.exit(1)
        else:
            # Config loaded, update optparser's defaults and reparse
            defaults.update(loadedConfig)
            opter = cliarg_parser.getCommandlineParser(defaults)
            opts, args = opter.parse_args()
开发者ID:chainsawbike,项目名称:tvnamer,代码行数:42,代码来源:main.py


示例11: rename

    def rename(self, new_fullpath, force=False, always_copy=False, always_move=False, leave_symlink=False, create_dirs=True):
        """Moves the file to a new path.

        If it is on the same partition, it will be moved (unless always_copy is True)
        If it is on a different partition, it will be copied, and the original
        only deleted if always_move is True.
        If the target file already exists, it will raise OSError unless force is True.
        If it was moved, a symlink will be left behind with the original name
        pointing to the file's new destination if leave_symlink is True.
        """

        new_dir = os.path.dirname(new_fullpath)

        if create_dirs:
            p("Creating directory %s" % new_dir)
            try:
                os.makedirs(new_dir)
            except OSError, e:
                if e.errno != 17:
                    raise
开发者ID:lahwaacz,项目名称:tvnamer,代码行数:20,代码来源:renamer.py


示例12: tvnamer

def tvnamer(paths):
    """Main tvnamer function, takes an array of paths, does stuff.
    """

    p("#" * 20)
    p("# Starting tvnamer")

    episodes_found = []

    for cfile in findFiles(paths):
        parser = FileParser(cfile)
        try:
            episode = parser.parse()
        except InvalidFilename, e:
            warn("Invalid filename: %s" % e)
        else:
            if episode.seriesname is None and Config['force_name'] is None:
                warn("Parsed filename did not contain series name (and --name not specified), skipping: %s" % cfile)
            else:
                episodes_found.append(episode)
开发者ID:rwycuff33,项目名称:mover,代码行数:20,代码来源:main.py


示例13: newName

    def newName(self, newName, force = False):
        """Renames a file, keeping the path the same.
        """
        filepath, filename = os.path.split(self.filename)
        filename, _ = os.path.splitext(filename)

        newpath = os.path.join(filepath, newName)

        if os.path.isfile(newpath):
            # If the destination exists, raise exception unless force is True
            if not force:
                raise OSError("File %s already exists, not forcefully renaming %s" % (
                    newpath, self.filename))

        if Config['link_files_enable']:
            p("Creating hard link")
            os.link(self.filename, newpath)
        else:
            os.rename(self.filename, newpath)
        self.filename = newpath
开发者ID:dtreichler,项目名称:tvnamer,代码行数:20,代码来源:utils.py


示例14: linkPath

 def linkPath(self, new_path = None, new_fullpath = None, force = False, always_copy = False, always_move = False, create_dirs = True, getPathPreview = False):
     # Implement getPathPreview, just to respect the API
     if getPathPreview:
         return self.newPath(new_path, new_fullpath, force, always_copy, always_move, create_dirs, getPathPreview)
     
     # Grab the pathPreview from newPath to determine where we need to link to
     new_fullpath = self.newPath(new_path, new_fullpath, force, always_copy, always_move, create_dirs, True)
     new_dir = os.path.dirname(new_fullpath)
     # And then restore our faked filename, if one exists
     if self.srcFilename is not None:
         self.filename = self.srcFilename
         self.srcFilename = None
     
     if create_dirs:
         p("Creating directory %s" % new_dir)
         try:
             os.makedirs(new_dir)
         except OSError, e:
             if e.errno != 17:
                 raise
开发者ID:predakanga,项目名称:tvnamer,代码行数:20,代码来源:utils.py


示例15: confirm

def confirm(question, options, default = "y"):
    """Takes a question (string), list of options and a default value (used
    when user simply hits enter).
    Asks until valid option is entered.
    """
    # Highlight default option with [ ]
    options_str = []
    for x in options:
        if x == default:
            x = "[%s]" % x
        if x != '':
            options_str.append(x)
    options_str = "/".join(options_str)

    while True:
        p(question)
        p("(%s) " % (options_str), end="")
        try:
            ans = raw_input().strip()
        except KeyboardInterrupt, errormsg:
            p("\n", errormsg)
            raise UserAbort(errormsg)

        if ans in options:
            return ans
        elif ans == '':
            return default
开发者ID:chainsawbike,项目名称:tvnamer,代码行数:27,代码来源:main.py


示例16: newName

    def newName(self, newName, force = False, leave_symlink = False):
        """Renames a file, keeping the path the same.
        """
        filepath, filename = os.path.split(self.filename)
        filename, _ = os.path.splitext(filename)

        newpath = os.path.join(filepath, newName)

        if os.path.isfile(newpath):
            # If the destination exists, raise exception unless force is True
            if not force:
                raise OSError("File %s already exists, not forcefully renaming %s" % (
                    newpath, self.filename))

        os.rename(self.filename, newpath)

        # Leave a symlink behind if configured to do so
        if leave_symlink:
            p("symlink %s to %s" % (self.filename, newpath))
            os.symlink(newpath, self.filename)

        self.filename = newpath
开发者ID:tremby,项目名称:tvnamer,代码行数:22,代码来源:utils.py


示例17: processFile

def processFile(tvdb_instance, episode):
    """Gets episode name, prompts user for input
    """
    p("#" * 20)
    p("# Processing file: %s" % episode.fullfilename)

    if len(Config['input_filename_replacements']) > 0:
        replaced = applyCustomInputReplacements(episode.fullfilename)
        p("# With custom replacements: %s" % (replaced))

    p("# Detected series: %s (%s)" % (episode.seriesname, episode.number_string()))

    try:
        correctedSeriesName, epName = getEpisodeName(tvdb_instance, episode)
    except (DataRetrievalError, ShowNotFound), errormsg:
        if Config['always_rename'] and Config['skip_file_on_error'] is True:
            warn("Skipping file due to error: %s" % errormsg)
            return
        else:
            warn(errormsg)
开发者ID:chainsawbike,项目名称:tvnamer,代码行数:20,代码来源:main.py


示例18: processFile

def processFile(comicvine_instance, issue):
    """Gets issue name, prompts user for input
    """
    p("#" * 20)
    p("# Processing file: %s" % issue.fullfilename)

    if len(Config['input_filename_replacements']) > 0:
        replaced = applyCustomInputReplacements(issue.fullfilename)
        p("# With custom replacements: %s" % (replaced))

    p("# Detected volume: %s (issue: %s)" % (
        issue.volumename,
        ", ".join([str(x) for x in issue.issuenumbers])))

    try:
        correctedvolumeName, issName = getIssueName(comicvine_instance, issue)
    except (DataRetrievalError, volumeNotFound), errormsg:
        if Config['always_rename'] and Config['skip_file_on_error'] is True:
            warn("Skipping file due to error: %s" % errormsg)
            return
        else:
            warn(errormsg)
开发者ID:swc,项目名称:comicnamer,代码行数:22,代码来源:main.py


示例19: newPath

    def newPath(self, new_path, force = False, always_copy = False, always_move = False, create_dirs = True, getPathPreview = False):
        """Moves the file to a new path.

        If it is on the same partition, it will be moved (unless always_copy is True)
        If it is on a different partition, it will be copied.
        If the target file already exists, it will raise OSError unless force is True.
        """

        if always_copy and always_move:
            raise ValueError("Both always_copy and always_move cannot be specified")

        if Config["link_files_enable"] and always_copy:
            warn("WARNING: having link_files_enable and always_copy both True can lead to 3 copies of a file: the original, a hard link and a copy")

        old_dir, old_filename = os.path.split(self.filename)

        # Join new filepath to old one (to handle realtive dirs)
        new_dir = os.path.abspath(os.path.join(old_dir, new_path))

        # Join new filename onto new filepath
        new_fullpath = os.path.join(new_dir, old_filename)

        if len(Config['move_files_fullpath_replacements']) > 0:
            p("Before custom full path replacements: %s" % (new_fullpath))
            new_fullpath = applyCustomFullpathReplacements(new_fullpath)
            new_dir = os.path.dirname(new_fullpath)

        p("New path: %s" % new_fullpath)

        if getPathPreview:
            return new_fullpath

        if create_dirs:
            p("Creating %s" % new_dir)
            try:
                os.makedirs(new_dir)
            except OSError, e:
                if e.errno != 17:
                    raise
开发者ID:dtreichler,项目名称:tvnamer,代码行数:39,代码来源:utils.py


示例20: getNewFullPath

    def getNewFullPath(self):
        """ Generates final fullPath, with all replacements, formatting etc.
            It's ready to pass it to Renamer.rename().
        """

        epdata = self.getepdata()
        newName = self.getFormatString() % epdata

        if len(Config['output_filename_replacements']) > 0:
            p("Before custom output replacements: '%s'" % newName)
            newName = applyCustomOutputReplacements(newName)
            p("After custom output replacements:  '%s'" % newName)

        if self.eptype == 'dated':
            newPath = Config['move_files_destination_date'] % epdata
        else:
            newPath = Config['move_files_destination'] % epdata
        if Config['move_files_destination_is_filepath']:
            newPath, newName = os.path.split(newPath)

        # make newName lowercase if specified in config
        if Config['lowercase_filename']:
            newName = newName.lower()

        # make sure the filename is valid
        newName = makeValidFilename(newName)

        # Join new filepath to old one (to handle realtive dirs)
        oldPath = os.path.dirname(self.fullpath)
        newFullPath = os.path.abspath(os.path.join(oldPath, newPath, newName))

        # apply full-path replacements
        if len(Config['move_files_fullpath_replacements']) > 0:
            p("Before custom full path replacements: '%s'" % (newFullPath))
            newFullPath = applyCustomFullpathReplacements(newFullPath)

        return newFullPath
开发者ID:lahwaacz,项目名称:tvnamer,代码行数:37,代码来源:utils.py



注:本文中的unicode_helper.p函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python unicodecsv.reader函数代码示例发布时间:2022-05-27
下一篇:
Python helpers.FormHelper类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap