当前位置: 首页>>代码示例>>Python>>正文


Python unicode_helper.p函数代码示例

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


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


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