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


Python syncdutils.escape函数代码示例

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


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

示例1: crawl

 def crawl(self, path=".", xtr=None, done=0):
     """ generate a CHANGELOG file consumable by process_change """
     if path == ".":
         self.open()
         self.crawls += 1
     if not xtr:
         # get the root stime and use it for all comparisons
         xtr = self.xtime(".", self.slave)
         if isinstance(xtr, int):
             if xtr != ENOENT:
                 raise GsyncdError("slave is corrupt")
             xtr = self.minus_infinity
     xtl = self.xtime(path)
     if isinstance(xtl, int):
         raise GsyncdError("master is corrupt")
     if xtr == xtl:
         if path == ".":
             self.close()
         return
     self.xtime_reversion_hook(path, xtl, xtr)
     logging.debug("entering " + path)
     dem = self.master.server.entries(path)
     pargfid = self.master.server.gfid(path)
     if isinstance(pargfid, int):
         logging.warn("skipping directory %s" % (path))
     for e in dem:
         bname = e
         e = os.path.join(path, e)
         st = self.lstat(e)
         if isinstance(st, int):
             logging.warn("%s got purged in the interim.." % e)
             continue
         gfid = self.master.server.gfid(e)
         if isinstance(gfid, int):
             logging.warn("skipping entry %s.." % (e))
             continue
         xte = self.xtime(e)
         if isinstance(xte, int):
             raise GsyncdError("master is corrupt")
         if not self.need_sync(e, xte, xtr):
             continue
         mo = st.st_mode
         if stat.S_ISDIR(mo):
             self.write_entry_change("E", [gfid, "MKDIR", escape(os.path.join(pargfid, bname))])
             self.crawl(e, xtr)
         elif stat.S_ISREG(mo):
             self.write_entry_change("E", [gfid, "CREATE", escape(os.path.join(pargfid, bname))])
             self.write_entry_change("D", [gfid])
         elif stat.S_ISLNK(mo):
             self.write_entry_change("E", [gfid, "SYMLINK", escape(os.path.join(pargfid, bname))])
         else:
             logging.info("ignoring %s" % e)
     if path == ".":
         logging.info("processing xsync changelog %s" % self.fname())
         self.close()
         self.process([self.fname()], done)
         self.upd_stime(xtl)
开发者ID:csabahenk,项目名称:glusterfs,代码行数:57,代码来源:master.py

示例2: get_url

 def get_url(self, canonical=False, escaped=False):
     if canonical:
         pa = self.canonical_path()
     else:
         pa = self.path
     u = "://".join((self.scheme(), pa))
     if escaped:
         u = syncdutils.escape(u)
     return u
开发者ID:mdjunaid,项目名称:glusterfs,代码行数:9,代码来源:resource.py

示例3: get_url

 def get_url(self, canonical=False, escaped=False):
     """format self's url in various styles"""
     if canonical:
         pa = self.canonical_path()
     else:
         pa = self.path
     u = "://".join((self.scheme, pa))
     if escaped:
         u = syncdutils.escape(u)
     return u
开发者ID:rambhatm,项目名称:glusterfs,代码行数:10,代码来源:resource.py

示例4: section

 def section(self, rx=False):
     peers = self.peers
     if not peers:
         peers = ['.', '.']
         rx = True
     if rx:
         st = 'peersrx'
     else:
         st = 'peers'
     return ' '.join([st] + [escape(u) for u in peers])
开发者ID:vbellur,项目名称:glusterfs,代码行数:10,代码来源:configinterface.py

示例5: section

 def section(self, rx=False):
     """get the section name of the section representing .peers
     in .config"""
     peers = self.peers
     if not peers:
         peers = ['.', '.']
         rx = True
     if rx:
         return ' '.join(['peersrx'] + [escape(u) for u in peers])
     else:
         return ' '.join(['peers'] + [u.split(':')[-1] for u in peers])
开发者ID:rlugojr,项目名称:glusterfs,代码行数:11,代码来源:configinterface.py

示例6: section

 def section(self, rx=False):
     """get the section name of the section representing .peers in .config"""
     peers = self.peers
     if not peers:
         peers = ['.', '.']
         rx = True
     if rx:
         st = 'peersrx'
     else:
         st = 'peers'
     return ' '.join([st] + [escape(u) for u in peers])
开发者ID:AsherBond,项目名称:snap-shot-glusterfs,代码行数:11,代码来源:configinterface.py

示例7: _set_checkpt_param

 def _set_checkpt_param(cls, chkpt, prm, val, xtimish=True):
     """use config backend to store a parameter associated
        with checkpoint @chkpt"""
     if xtimish:
         val = cls.serialize_xtime(val)
     gconf.configinterface.set("checkpoint_" + prm, "%s:%s" % (escape(chkpt), val))
开发者ID:ngtuna,项目名称:glusterfs,代码行数:6,代码来源:master.py

示例8: monitor

    def monitor(self, w, argv, cpids):
        """the monitor loop

        Basic logic is a blantantly simple blunt heuristics:
        if spawned client survives 60 secs, it's considered OK.
        This servers us pretty well as it's not vulneralbe to
        any kind of irregular behavior of the child...

        ... well, except for one: if children is hung up on
        waiting for some event, it can survive aeons, still
        will be defunct. So we tweak the above logic to
        expect the worker to send us a signal within 60 secs
        (in the form of closing its end of a pipe). The worker
        does this when it's done with the setup stage
        ready to enter the service loop (note it's the setup
        stage which is vulnerable to hangs -- the full
        blown worker blows up on EPIPE if the net goes down,
        due to the keep-alive thread)
        """

        self.set_state(self.ST_INIT, w)
        ret = 0

        def nwait(p, o=0):
            p2, r = waitpid(p, o)
            if not p2:
                return
            return r

        def exit_signalled(s):
            """ child teminated due to receipt of SIGUSR1 """
            return (os.WIFSIGNALED(s) and (os.WTERMSIG(s) == signal.SIGUSR1))

        def exit_status(s):
            if os.WIFEXITED(s):
                return os.WEXITSTATUS(s)
            return 1
        conn_timeout = int(gconf.connection_timeout)
        while ret in (0, 1):
            logging.info('-' * conn_timeout)
            logging.info('starting gsyncd worker')
            pr, pw = os.pipe()
            cpid = os.fork()
            if cpid == 0:
                os.close(pr)
                os.execv(sys.executable, argv + ['--feedback-fd', str(pw),
                                                 '--local-path', w[0],
                                                 '--local-id',
                                                 '.' + escape(w[0]),
                                                 '--resource-remote', w[1]])
            self.lock.acquire()
            cpids.add(cpid)
            self.lock.release()
            os.close(pw)
            t0 = time.time()
            so = select((pr,), (), (), conn_timeout)[0]
            os.close(pr)
            if so:
                ret = nwait(cpid, os.WNOHANG)
                if ret is not None:
                    logging.info("worker(%s) died before establishing "
                                 "connection" % w[0])
                else:
                    logging.debug("worker(%s) connected" % w[0])
                    while time.time() < t0 + conn_timeout:
                        ret = nwait(cpid, os.WNOHANG)
                        if ret is not None:
                            logging.info("worker(%s) died in startup "
                                         "phase" % w[0])
                            break
                        time.sleep(1)
            else:
                logging.info("worker(%s) not confirmed in %d sec, "
                             "aborting it" % (w[0], conn_timeout))
                os.kill(cpid, signal.SIGKILL)
                ret = nwait(cpid)
            if ret is None:
                self.set_state(self.ST_STABLE, w)
                ret = nwait(cpid)
            if exit_signalled(ret):
                ret = 0
            else:
                ret = exit_status(ret)
                if ret in (0, 1):
                    self.set_state(self.ST_FAULTY, w)
            time.sleep(10)
        self.set_state(self.ST_INCON, w)
        return ret
开发者ID:humblec,项目名称:glusterfs,代码行数:88,代码来源:monitor.py

示例9: monitor


#.........这里部分代码省略.........
            # Spawn the worker and agent in lock to avoid fd leak
            self.lock.acquire()

            logging.info('-' * conn_timeout)
            logging.info('starting gsyncd worker')

            # Couple of pipe pairs for RPC communication b/w
            # worker and changelog agent.

            # read/write end for agent
            (ra, ww) = os.pipe()
            # read/write end for worker
            (rw, wa) = os.pipe()

            # spawn the agent process
            apid = os.fork()
            if apid == 0:
                os.close(rw)
                os.close(ww)
                os.execv(sys.executable, argv + ['--local-path', w[0],
                                                 '--agent',
                                                 '--rpc-fd',
                                                 ','.join([str(ra), str(wa),
                                                           str(rw), str(ww)])])
            pr, pw = os.pipe()
            cpid = os.fork()
            if cpid == 0:
                os.close(pr)
                os.close(ra)
                os.close(wa)
                os.execv(sys.executable, argv + ['--feedback-fd', str(pw),
                                                 '--local-path', w[0],
                                                 '--local-id',
                                                 '.' + escape(w[0]),
                                                 '--rpc-fd',
                                                 ','.join([str(rw), str(ww),
                                                           str(ra), str(wa)]),
                                                 '--subvol-num', str(w[2])] +
                         (['--is-hottier'] if w[3] else []) +
                         ['--resource-remote', remote_host])

            cpids.add(cpid)
            agents.add(apid)
            os.close(pw)

            # close all RPC pipes in monitor
            os.close(ra)
            os.close(wa)
            os.close(rw)
            os.close(ww)
            self.lock.release()

            t0 = time.time()
            so = select((pr,), (), (), conn_timeout)[0]
            os.close(pr)

            if so:
                ret = nwait(cpid, os.WNOHANG)
                ret_agent = nwait(apid, os.WNOHANG)

                if ret_agent is not None:
                    # Agent is died Kill Worker
                    logging.info("Changelog Agent died, "
                                 "Aborting Worker(%s)" % w[0])
                    errno_wrap(os.kill, [cpid, signal.SIGKILL], [ESRCH])
                    nwait(cpid)
开发者ID:Byreddys,项目名称:glusterfs,代码行数:67,代码来源:monitor.py

示例10: crawl

    def crawl(self, path='.', xtr=None, done=0):
        """ generate a CHANGELOG file consumable by process_change """
        if path == '.':
            self.open()
            self.crawls += 1
        if not xtr:
            # get the root stime and use it for all comparisons
            xtr = self.xtime('.', self.slave)
            if isinstance(xtr, int):
                if xtr != ENOENT:
                    raise GsyncdError('slave is corrupt')
                xtr = self.minus_infinity
        xtl = self.xtime(path)
        if isinstance(xtl, int):
            raise GsyncdError('master is corrupt')
        if xtr == xtl:
            if path == '.':
                self.close()
            return
        self.xtime_reversion_hook(path, xtl, xtr)
        logging.debug("entering " + path)
        dem = self.master.server.entries(path)
        pargfid = self.master.server.gfid(path)
        if isinstance(pargfid, int):
            logging.warn('skipping directory %s' % (path))
        for e in dem:
            bname = e
            e = os.path.join(path, e)
            st = lstat(e)
            if isinstance(st, int):
                logging.warn('%s got purged in the interim..' % e)
                continue
            gfid = self.master.server.gfid(e)
            if isinstance(gfid, int):
                logging.warn('skipping entry %s..' % (e))
                continue
            xte = self.xtime(e)
            if isinstance(xte, int):
                raise GsyncdError('master is corrupt')
            if not self.need_sync(e, xte, xtr):
                continue
            mo = st.st_mode
            if stat.S_ISDIR(mo):
                self.write_entry_change("E", [gfid, 'MKDIR', escape(os.path.join(pargfid, bname))])
                self.crawl(e, xtr)
            elif stat.S_ISLNK(mo):
                rl = errno_wrap(os.readlink, [en], [ENOENT])
                if isinstance(rl, int):
                    continue
                self.write_entry_change("E", [gfid, 'SYMLINK', escape(os.path.join(pargfid, bname)), rl])
            else:
                # if a file has a hardlink, create a Changelog entry as 'LINK' so the slave
                # side will decide if to create the new entry, or to create link.
                if st.st_nlink == 1:
                    self.write_entry_change("E", [gfid, 'MKNOD', escape(os.path.join(pargfid, bname))])
                else:
                    self.write_entry_change("E", [gfid, 'LINK', escape(os.path.join(pargfid, bname))])
                if stat.S_ISREG(mo):
                    self.write_entry_change("D", [gfid])

        if path == '.':
            logging.info('processing xsync changelog %s' % self.fname())
            self.close()
            self.process([self.fname()], done)
            self.upd_stime(xtl)
开发者ID:AsherBond,项目名称:snap-shot-glusterfs,代码行数:65,代码来源:master.py

示例11: main


#.........这里部分代码省略.........
    p.add_argument("--debug", action="store_true")

    # Delete
    p = sp.add_parser("delete")
    p.add_argument("master", help="Master Volume Name")
    p.add_argument("slave", help="Slave")
    p.add_argument("-c", "--config-file", help="Config File")
    p.add_argument('--path', dest='paths', action="append")
    p.add_argument("--reset-sync-time", action="store_true",
                   help="Reset Sync Time")
    p.add_argument("--debug", action="store_true")

    # Parse arguments
    args = parser.parse_args()

    # Extra template values, All arguments are already part of template
    # variables, use this for adding extra variables
    extra_tmpl_args = {}

    # Add First/Primary Slave host, user and volume
    if getattr(args, "slave", None) is not None:
        hostdata, slavevol = args.slave.split("::")
        hostdata = hostdata.split("@")
        slavehost = hostdata[-1]
        slaveuser = "root"
        if len(hostdata) == 2:
            slaveuser = hostdata[0]
        extra_tmpl_args["primary_slave_host"] = slavehost
        extra_tmpl_args["slaveuser"] = slaveuser
        extra_tmpl_args["slavevol"] = slavevol

    # Add Bricks encoded path
    if getattr(args, "local_path", None) is not None:
        extra_tmpl_args["local_id"] = escape(args.local_path)

    # Add Master Bricks encoded path(For Slave)
    if getattr(args, "master_brick", None) is not None:
        extra_tmpl_args["master_brick_id"] = escape(args.master_brick)

    # Load configurations
    config_file = getattr(args, "config_file", None)

    # Subcmd accepts config file argument but not passed
    # Set default path for config file in that case
    # If an subcmd accepts config file then it also accepts
    # master and Slave arguments.
    if config_file is None and hasattr(args, "config_file"):
        config_file = "%s/geo-replication/%s_%s_%s/gsyncd.conf" % (
            GLUSTERD_WORKDIR,
            args.master,
            extra_tmpl_args["primary_slave_host"],
            extra_tmpl_args["slavevol"])

    # If Config file path not exists, log error and continue using default conf
    config_file_error_msg = None
    if config_file is not None and not os.path.exists(config_file):
        # Logging not yet initialized, create the error message to
        # log later and reset the config_file to None
        config_file_error_msg = lf(
            "Session config file not exists, using the default config",
            path=config_file)
        config_file = None

    rconf.config_file = config_file

    # Override gconf values from argument values only if it is slave gsyncd
开发者ID:gluster,项目名称:glusterfs,代码行数:67,代码来源:gsyncd.py


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