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

Python lib.terse函数代码示例

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

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



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

示例1: compare

    def compare(self, _src_path, dest_stat):
        # type: (str, SyncStat) -> bool
        '''see if devs are the same'''

        if not self.exists:
            return False

        # dest_stat is a SyncStat object and it's useless here
        # I need a real, fresh statbuf that includes st_rdev field
        try:
            dest_stat = os.lstat(self.name)
        except OSError as err:
            error('error checking %s : %s' % (self.name, err.strerror))
            return False

        # Note: mypy triggers false errors here
        # Also, no luck with Union[SyncStat, posix.stat_result]
        # In any case, for VNodeChrDev and VNodeBlkDev,
        # the self.src_stat is of type posix.stat_result
        src_major = os.major(self.src_stat.st_rdev)     # type: ignore
        src_minor = os.minor(self.src_stat.st_rdev)     # type: ignore
        dest_major = os.major(dest_stat.st_rdev)        # type: ignore
        dest_minor = os.minor(dest_stat.st_rdev)        # type: ignore
        if src_major != dest_major or src_minor != dest_minor:
            stdout('%s should have major,minor %d,%d but has %d,%d' %
                   (self.name, src_major, src_minor, dest_major, dest_minor))
            unix_out('# updating major,minor %s' % self.name)
            terse(synctool.lib.TERSE_SYNC, self.name)
            return False

        return True
开发者ID:walterdejong,项目名称:synctool,代码行数:31,代码来源:object.py


示例2: check_purge_timestamp

    def check_purge_timestamp(self):
        '''check timestamp between src and dest
        Returns True if same, False if not
        '''

        # This is only used for purge/
        # check() has already determined that the files are the same
        # Now only check the timestamp ...

        if synctool.param.SYNC_TIMES:
            # this was already handled by check() and fix()
            return True

        # set times, but not for symlinks, directories
        if (not self.src_stat.is_link() and not self.src_stat.is_dir() and
                self.src_stat.mtime != self.dest_stat.mtime):
            stdout('%s mismatch (only timestamp)' % self.dest_path)
            terse(synctool.lib.TERSE_WARNING,
                  '%s (only timestamp)' % self.dest_path)

            vnode = self.vnode_obj()
            # leave the atime intact
            vnode.stat.atime = self.dest_stat.atime
            vnode.set_times()
            return False

        return True
开发者ID:afghanistanyn,项目名称:synctool,代码行数:27,代码来源:object.py


示例3: compare

    def compare(self, src_path, dest_stat):
        '''see if devs are the same'''

        if not self.exists:
            return False

        # dest_stat is a SyncStat object and it's useless here
        # I need a real, fresh statbuf that includes st_rdev field
        try:
            dest_stat = os.lstat(self.name)
        except OSError as err:
            error('error checking %s : %s' % (self.name, err.strerror))
            return False

        src_major = os.major(self.src_stat.st_rdev)
        src_minor = os.minor(self.src_stat.st_rdev)
        dest_major = os.major(dest_stat.st_rdev)
        dest_minor = os.minor(dest_stat.st_rdev)
        if src_major != dest_major or src_minor != dest_minor:
            stdout('%s should have major,minor %d,%d but has %d,%d' %
                (self.name, src_major, src_minor, dest_major, dest_minor))
            unix_out('# updating major,minor %s' % self.name)
            terse(synctool.lib.TERSE_SYNC, self.name)
            return False

        return True
开发者ID:dot-Sean,项目名称:synctool,代码行数:26,代码来源:object.py


示例4: _split_extension

def _split_extension(filename, src_dir):
    '''filename in the overlay tree, without leading path
    src_dir is passed for the purpose of printing error messages
    Returns tuple: SyncObject, importance'''

    (name, ext) = os.path.splitext(filename)
    if not ext:
        return SyncObject(filename, name, OV_NO_EXT), _group_all()

    if ext == '.post':
        (name2, ext) = os.path.splitext(name)
        if ext == '._template':
            # it's a generic template generator
            return SyncObject(filename, name, OV_TEMPLATE_POST), _group_all()

        # it's a generic .post script
        return SyncObject(filename, name, OV_POST), _group_all()

    if ext[:2] != '._':
        return SyncObject(filename, filename, OV_NO_EXT), _group_all()

    ext = ext[2:]
    if not ext:
        return SyncObject(filename, filename, OV_NO_EXT), _group_all()

    if ext == 'template':
        return SyncObject(filename, name, OV_TEMPLATE), _group_all()

    try:
        importance = synctool.param.MY_GROUPS.index(ext)
    except ValueError:
        if not ext in synctool.param.ALL_GROUPS:
            src_path = os.path.join(src_dir, filename)
            if synctool.param.TERSE:
                terse(synctool.lib.TERSE_ERROR, 'invalid group on %s' %
                                                src_path)
            else:
                stderr('unknown group on %s, skipped' % prettypath(src_path))
            return None, -1

        # it is not one of my groups
        verbose('skipping %s, it is not one of my groups' %
                prettypath(os.path.join(src_dir, filename)))
        return None, -1

    (name2, ext) = os.path.splitext(name)

    if ext == '.post':
        _, ext = os.path.splitext(name2)
        if ext == '._template':
            # it's a group-specific template generator
            return (SyncObject(filename, name2, OV_TEMPLATE_POST), importance)

        # register group-specific .post script
        return SyncObject(filename, name2, OV_POST), importance

    elif ext == '._template':
        return SyncObject(filename, name2, OV_TEMPLATE), importance

    return SyncObject(filename, name), importance
开发者ID:dineshbhoopathy,项目名称:synctool,代码行数:60,代码来源:overlay.py


示例5: _compare_checksums

    def _compare_checksums(self, src_path):
        # type: (str) -> bool
        '''compare checksum of src_path and dest: self.name
        Return True if the same'''

        try:
            f1 = open(src_path, 'rb')
        except IOError as err:
            error('failed to open %s : %s' % (src_path, err.strerror))
            # return True because we can't fix an error in src_path
            return True

        sum1 = hashlib.md5()
        sum2 = hashlib.md5()

        with f1:
            try:
                f2 = open(self.name, 'rb')
            except IOError as err:
                error('failed to open %s : %s' % (self.name, err.strerror))
                return False

            with f2:
                ended = False
                while not ended and (sum1.digest() == sum2.digest()):
                    try:
                        data1 = f1.read(IO_SIZE)
                    except IOError as err:
                        error('failed to read file %s: %s' % (src_path,
                                                              err.strerror))
                        return False

                    if not data1:
                        ended = True
                    else:
                        sum1.update(data1)

                    try:
                        data2 = f2.read(IO_SIZE)
                    except IOError as err:
                        error('failed to read file %s: %s' % (self.name,
                                                              err.strerror))
                        return False

                    if not data2:
                        ended = True
                    else:
                        sum2.update(data2)

        if sum1.digest() != sum2.digest():
            if synctool.lib.DRY_RUN:
                stdout('%s mismatch (MD5 checksum)' % self.name)
            else:
                stdout('%s updated (MD5 mismatch)' % self.name)

            unix_out('# updating file %s' % self.name)
            terse(synctool.lib.TERSE_SYNC, self.name)
            return False

        return True
开发者ID:walterdejong,项目名称:synctool,代码行数:60,代码来源:object.py


示例6: _single_overlay_callback

def _single_overlay_callback(obj, post_dict, updated, *args):
    '''do overlay function for single files'''

    if obj.ov_type == synctool.overlay.OV_TEMPLATE:
        return generate_template(obj, post_dict), False

    go_on = True

    if _match_single(obj.dest_path):
        _, updated = _overlay_callback(obj, post_dict, False, *args)
        if not updated:
            stdout('%s is up to date' % obj.dest_path)
            terse(synctool.lib.TERSE_OK, obj.dest_path)
            unix_out('# %s is up to date\n' % obj.dest_path)
        else:
            # register .post on the parent dir, if it has a .post script
            obj.dest_path = os.path.dirname(obj.dest_path)
            obj.dest_stat = synctool.syncstat.SyncStat(obj.dest_path)

            if obj.dest_path in post_dict:
                changed_dict = args[0]
                changed_dict[obj.dest_path] = (obj, post_dict[obj.dest_path])

        if not SINGLE_FILES:
            return False, updated

    return go_on, updated
开发者ID:dineshbhoopathy,项目名称:synctool,代码行数:27,代码来源:client.py


示例7: _single_purge_callback

def _single_purge_callback(obj, pre_dict, post_dict):
    # type: (SyncObject, Dict[str, str], Dict[str, str]) -> Tuple[bool, bool]
    '''do purge function for single files'''

    # The same as _single_overlay_callback(), except that
    # purge entries may differ in timestamp. synctool has to report
    # this because pure rsync will as well (which is bloody annoying)
    #
    # For normal synctool overlay/, it's regarded as not important
    # and synctool will not complain about it
    #
    # This actually leaves a final wart; synctool --single may create
    # purge entries that rsync will complain about and sync again
    # Anyway, I don't think it's a big deal, and that's what you get
    # when you mix up synctool and rsync

    go_on = True
    updated = False

    if _match_single(obj.dest_path):
        _, updated = _overlay_callback(obj, pre_dict, post_dict)
        if not updated:
            if obj.check_purge_timestamp():
                stdout('%s is up to date' % obj.dest_path)
                terse(synctool.lib.TERSE_OK, obj.dest_path)
                unix_out('# %s is up to date\n' % obj.dest_path)
            # else: pass

        if not SINGLE_FILES:
            return False, updated

    return go_on, updated
开发者ID:walterdejong,项目名称:synctool,代码行数:32,代码来源:client.py


示例8: copy_stat

    def copy_stat(self):
        '''set access and mod times'''

        if not synctool.lib.DRY_RUN and synctool.param.SYNC_TIMES:
            try:
                verbose('copystat: %s => %s' % (self.src_path, self.name))
                shutil.copystat(self.src_path, self.name)
            except OSError as err:
                error('failed to set utime on %s : %s' % (self.name,
                                                          err.strerror))
                terse(synctool.lib.TERSE_FAIL, 'utime %s' % self.name)
开发者ID:dl4ner,项目名称:synctool,代码行数:11,代码来源:object.py


示例9: set_times

    def set_times(self, atime, mtime):
        '''set access and mod times'''

        # only used for purge --single

        if not synctool.lib.DRY_RUN:
            try:
                os.utime(self.name, (atime, mtime))
            except OSError as err:
                error('failed to set utime on %s : %s' % (self.name,
                                                          err.strerror))
                terse(synctool.lib.TERSE_FAIL, 'utime %s' % self.name)
开发者ID:Linuxtester,项目名称:synctool,代码行数:12,代码来源:object.py


示例10: set_permissions

    def set_permissions(self):
        '''set access permission bits equal to source'''

        verbose(dryrun_msg('  os.chmod(%s, %04o)' %
                           (self.name, self.stat.mode & 07777)))
        unix_out('chmod 0%o %s' % (self.stat.mode & 07777, self.name))
        if not synctool.lib.DRY_RUN:
            try:
                os.chmod(self.name, self.stat.mode & 07777)
            except OSError as err:
                error('failed to chmod %04o %s : %s' %
                      (self.stat.mode & 07777, self.name, err.strerror))
                terse(synctool.lib.TERSE_FAIL, 'mode %s' % self.name)
开发者ID:dot-Sean,项目名称:synctool,代码行数:13,代码来源:object.py


示例11: create

    def create(self):
        '''make a fifo'''

        verbose(dryrun_msg('  os.mkfifo(%s)' % self.name))
        unix_out('mkfifo %s' % self.name)
        terse(synctool.lib.TERSE_NEW, self.name)
        if not synctool.lib.DRY_RUN:
            try:
                os.mkfifo(self.name, self.stat.mode & 0777)
            except OSError as err:
                error('failed to create fifo %s : %s' % (self.name,
                                                         err.strerror))
                terse(TERSE_FAIL, 'fifo %s' % self.name)
开发者ID:afghanistanyn,项目名称:synctool,代码行数:13,代码来源:object.py


示例12: compare

    def compare(self, src_path, dest_stat):
        '''see if files are the same
        Return True if the same'''

        if self.stat.size != dest_stat.size:
            if synctool.lib.DRY_RUN:
                stdout('%s mismatch (file size)' % self.name)
            else:
                stdout('%s updated (file size mismatch)' % self.name)
            terse(synctool.lib.TERSE_SYNC, self.name)
            unix_out('# updating file %s' % self.name)
            return False

        return self._compare_checksums(src_path)
开发者ID:dineshbhoopathy,项目名称:synctool,代码行数:14,代码来源:object.py


示例13: upload

def upload(up):
    '''copy a file from a node into the overlay/ tree'''

    # Note: this global is only needed because of callback fn ...
    global GLOBAL_UPLOAD_FILE

    if up.filename[0] != os.sep:
        error('the filename to upload must be an absolute path')
        sys.exit(-1)

    if up.suffix and up.suffix not in synctool.param.ALL_GROUPS:
        error("no such group '%s'" % up.suffix)
        sys.exit(-1)

    if up.overlay and up.overlay not in synctool.param.ALL_GROUPS:
        error("no such group '%s'" % up.overlay)
        sys.exit(-1)

    if up.purge and up.purge not in synctool.param.ALL_GROUPS:
        error("no such group '%s'" % up.purge)
        sys.exit(-1)

    if synctool.lib.DRY_RUN and not synctool.lib.QUIET:
        stdout('DRY RUN, not uploading any files')
        terse(synctool.lib.TERSE_DRYRUN, 'not uploading any files')

    if up.purge != None:
        rsync_upload(up)
        return

    # pretend that the current node is now the given node;
    # this is needed for find() to find the best reference for the file
    orig_nodename = synctool.param.NODENAME
    synctool.param.NODENAME = up.node
    synctool.config.insert_group(up.node, up.node)

    orig_my_groups = synctool.param.MY_GROUPS[:]
    synctool.param.MY_GROUPS = synctool.config.get_my_groups()

    # see if file is already in the repository
    # Note: ugly global is needed because of callback function
    GLOBAL_UPLOAD_FILE = up
    synctool.overlay.visit(synctool.param.OVERLAY_DIR, _upload_callback)
    up = GLOBAL_UPLOAD_FILE

    synctool.param.NODENAME = orig_nodename
    synctool.param.MY_GROUPS = orig_my_groups

    rsync_upload(up)
开发者ID:afghanistanyn,项目名称:synctool,代码行数:49,代码来源:upload.py


示例14: set_owner

    def set_owner(self):
        '''set ownership equal to source'''

        verbose(dryrun_msg('  os.chown(%s, %d, %d)' %
                           (self.name, self.stat.uid, self.stat.gid)))
        unix_out('chown %s.%s %s' % (self.stat.ascii_uid(),
                                     self.stat.ascii_gid(), self.name))
        if not synctool.lib.DRY_RUN:
            try:
                os.chown(self.name, self.stat.uid, self.stat.gid)
            except OSError as err:
                error('failed to chown %s.%s %s : %s' %
                      (self.stat.ascii_uid(), self.stat.ascii_gid(),
                       self.name, err.strerror))
                terse(synctool.lib.TERSE_FAIL, 'owner %s' % self.name)
开发者ID:dot-Sean,项目名称:synctool,代码行数:15,代码来源:object.py


示例15: move_saved

    def move_saved(self):
        '''move existing entry to .saved'''

        verbose(dryrun_msg('saving %s as %s.saved' % (self.name, self.name)))
        unix_out('mv %s %s.saved' % (self.name, self.name))

        if not synctool.lib.DRY_RUN:
            verbose('  os.rename(%s, %s.saved)' % (self.name, self.name))
            try:
                os.rename(self.name, '%s.saved' % self.name)
            except OSError as err:
                stderr('failed to save %s as %s.saved : %s' % (self.name,
                                                               self.name,
                                                               err.strerror))
                terse(synctool.lib.TERSE_FAIL, 'save %s.saved' % self.name)
开发者ID:dineshbhoopathy,项目名称:synctool,代码行数:15,代码来源:object.py


示例16: set_times

    def set_times(self):
        '''set access and modification times'''

        # only mtime is shown
        verbose(dryrun_msg('  os.utime(%s, %s)' %
                           (self.name, print_timestamp(self.stat.mtime))))
        # print timestamp in other format
        dt = datetime.datetime.fromtimestamp(self.stat.mtime)
        time_str = dt.strftime('%Y%m%d%H%M.%S')
        unix_out('touch -t %s %s' % (time_str, self.name))
        if not synctool.lib.DRY_RUN:
            try:
                os.utime(self.name, (self.stat.atime, self.stat.mtime))
            except OSError as err:
                error('failed to set utime on %s : %s' % (self.name,
                                                          err.strerror))
                terse(TERSE_FAIL, 'utime %s' % self.name)
开发者ID:afghanistanyn,项目名称:synctool,代码行数:17,代码来源:object.py


示例17: check_purge_timestamp

    def check_purge_timestamp(self):
        '''check timestamp between src and dest
        Returns True if same, False if not
        '''

        # This is only used for purge/
        # check() has already determined that the files are the same
        # Now only check the timestamp ...
        # FIXME have SyncStat time fields
        # Note that SyncStat objects do not know the timestamps;
        # they are not cached only to save memory
        # So now we have to os.stat() again to get the times; it is
        # not a big problem because this func is used for purge_single only

        # src_path is under $purge/
        # dest_path is in the filesystem

        try:
            src_stat = os.lstat(self.src_path)
        except OSError as err:
            error('stat(%s) failed: %s' % (self.src_path, err.strerror))
            return False

        try:
            dest_stat = os.lstat(self.dest_path)
        except OSError as err:
            error('stat(%s) failed: %s' % (self.dest_path, err.strerror))
            return False

        # FIXME set_times() should not be called for symlinks
        if src_stat.st_mtime > dest_stat.st_mtime:
            stdout('%s mismatch (only timestamp)' % self.dest_path)
            terse(synctool.lib.TERSE_WARNING,
                  '%s (only timestamp)' % self.dest_path)

            verbose(dryrun_msg('  os.utime(%s, %s)'
                               '' % (self.dest_path,
                                     time.ctime(src_stat.st_mtime))))
            unix_out('touch -r %s %s' % (self.src_path, self.dest_path))

            vnode = self.vnode_obj()
            vnode.set_times(src_stat.st_atime, src_stat.st_mtime)
            return False

        return True
开发者ID:dot-Sean,项目名称:synctool,代码行数:45,代码来源:object.py


示例18: create

    def create(self):
        # type: () -> None
        '''make a character device file'''

        major = os.major(self.src_stat.st_rdev)         # type: ignore
        minor = os.minor(self.src_stat.st_rdev)         # type: ignore
        verbose(dryrun_msg('  os.mknod(%s, CHR %d,%d)' % (self.name, major,
                                                          minor)))
        unix_out('mknod %s c %d %d' % (self.name, major, minor))
        terse(synctool.lib.TERSE_NEW, self.name)
        if not synctool.lib.DRY_RUN:
            try:
                os.mknod(self.name,
                         (self.src_stat.st_mode & 0777) | stat.S_IFCHR,
                         os.makedev(major, minor))
            except OSError as err:
                error('failed to create device %s : %s' % (self.name,
                                                           err.strerror))
                terse(TERSE_FAIL, 'device %s' % self.name)
开发者ID:walterdejong,项目名称:synctool,代码行数:19,代码来源:object.py


示例19: move_saved

    def move_saved(self):
        '''move existing entry to .saved'''

        # do not save files that already are .saved
        _, ext = os.path.splitext(self.name)
        if ext == '.saved':
            return

        verbose(dryrun_msg('saving %s as %s.saved' % (self.name, self.name)))
        unix_out('mv %s %s.saved' % (self.name, self.name))

        if not synctool.lib.DRY_RUN:
            verbose('  os.rename(%s, %s.saved)' % (self.name, self.name))
            try:
                os.rename(self.name, '%s.saved' % self.name)
            except OSError as err:
                error('failed to save %s as %s.saved : %s' % (self.name,
                                                              self.name,
                                                              err.strerror))
                terse(synctool.lib.TERSE_FAIL, 'save %s.saved' % self.name)
开发者ID:dot-Sean,项目名称:synctool,代码行数:20,代码来源:object.py


示例20: harddelete

    def harddelete(self):
        '''delete directory'''

        if synctool.lib.DRY_RUN:
            not_str = 'not '
        else:
            not_str = ''

        stdout('%sremoving %s' % (not_str, self.name + os.sep))
        unix_out('rmdir %s' % self.name)
        terse(synctool.lib.TERSE_DELETE, self.name + os.sep)
        if not synctool.lib.DRY_RUN:
            verbose('  os.rmdir(%s)' % self.name)
            try:
                os.rmdir(self.name)
            except OSError:
                # probably directory not empty
                # refuse to delete dir, just move it aside
                verbose('refusing to delete directory %s' % self.name)
                self.move_saved()
开发者ID:afghanistanyn,项目名称:synctool,代码行数:20,代码来源:object.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python lib.unix_out函数代码示例发布时间:2022-05-27
下一篇:
Python lib.stdout函数代码示例发布时间: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