def autosync(ui, repo, other="default", **opts): """commit, fetch and push at regular intervals Commit changes in the working copy, fetch (pull, merge and commit) changes from another repository and push local changes back to the other repository - either continuously (default) or once only. The idea of this command is to use Mercurial as a synchronization engine to keep files in sync across work stations. Think of configuration files or to-do lists as examples for things to synchronize. On a higher level this command not only synchronizes repositories but working copies. A central repository (usually without a working copy) must be used as synchronization hub: repo1 <--sync--> hub <--sync--> repo2 Running this command in repo1 and repo2 ensures the working copies (!) of both repositories stay in sync (as long as they are no conflicting changes). HGRC configruation: [autosync] merge = <merger> alert = <alert-tool> By default Mercurial's internal non-interactive merge is used when fetching from another repository. This can be changed with the `merge` option. Errors and merge conflicts which cannot be resolved automatically are highlighted in the output. Additionally, if option `alert` is defined, the corresponding tool is called. This tool is supposed to notify problems to a human. The repository path and an error message are passed as arguments to the alert tool. Independent of these options, autosync keeps running when there are problems and retries after the next interval, hoping things get fixed externally. When running in daemon mode, any output gets logged into the file `autosync.log` within the repository's `.hg` directory (use --daemon-log to set a different file). This command denies to run in a virgin repository as this may unrelate repositories which were supposed to get synchronized. Before running autosync, pull or commit something first manually. """ runfn = lambda: _sync(ui, repo, other, opts) if not opts["daemon"]: logfile = None elif opts["daemon_log"] == LOGFILE: logfile = os.path.join(repo.root, LOGFILE) else: logfile = opts["daemon_log"] cmdutil.service(opts, runfn=runfn, logfile=logfile)
def serve(ui, repo, **opts): '''start an inotify server for this repository''' timeout = opts.get('timeout') if timeout: timeout = float(timeout) * 1e3 class service: def init(self): self.master = server.Master(ui, repo, timeout) def run(self): try: self.master.run() finally: self.master.shutdown() service = service() cmdutil.service(opts, initfn=service.init, runfn=service.run)
def main(): op = optparse.OptionParser() op.add_option('-d', '--daemon', action='store_true') op.add_option('--daemon-postexec', action='append') op.add_option('-p', '--port', type=int, default=8025) op.add_option('-a', '--address', default='localhost') op.add_option('--pid-file', metavar='FILE') op.add_option('--tls', choices=['none', 'smtps'], default='none') op.add_option('--certificate', metavar='FILE') opts, args = op.parse_args() if opts.tls == 'smtps' and not opts.certificate: op.error('--certificate must be specified') addr = (opts.address, opts.port) def init(): if opts.tls == 'none': dummysmtpserver(addr) else: dummysmtpsecureserver(addr, opts.certificate) log('listening at %s:%d\n' % addr) cmdutil.service(vars(opts), initfn=init, runfn=run, runargs=[sys.executable, __file__] + sys.argv[1:])
addr = '%s:%d' % (self.httpd.fqaddr, self.httpd.port) conn = httplib.HTTPConnection(addr) conn.request("GET", "/") res = conn.getresponse() res.read() conn.close() def run(self): self.stopped = False while not self.stopped: self.httpd.handle_request() self.httpd.server_close() # release port global gservice gservice = service() cmdutil.service(opts, initfn=gservice.init, runfn=gservice.run) thg_serve_cmd = {"^serve": (thg_serve, [('A', 'accesslog', '', _('name of access log file to write to')), ('d', 'daemon', None, _('run server in background')), ('', 'daemon-pipefds', '', _('used internally by daemon mode')), ('E', 'errorlog', '', _('name of error log file to write to')), ('p', 'port', 0, _('port to use (default: 8000)')), ('a', 'address', '', _('address to use')), ('', 'prefix', '', _('prefix path to serve from (default: server root)')), ('n', 'name', '', _('name to show in web pages (default: working dir)')), ('', 'webdir-conf', '', _('name of the webdir config file' ' (serve more than one repo)')), ('', 'pid-file', '', _('name of file to write process ID to')),
try: self.master = master(ui, dirstate, root, timeout) except AlreadyStartedException, inst: raise util.Abort("inotify-server: %s" % inst) def run(self): try: try: self.master.run() except TimeoutException: pass finally: self.master.shutdown() if 'inserve' not in sys.argv: runargs = util.hgcmd() + ['inserve', '-R', root] else: runargs = util.hgcmd() + sys.argv[1:] pidfile = ui.config('inotify', 'pidfile') if opts['daemon'] and pidfile is not None and 'pid-file' not in runargs: runargs.append("--pid-file=%s" % pidfile) service = service() logfile = ui.config('inotify', 'log') appendpid = ui.configbool('inotify', 'appendpid', False) cmdutil.service(opts, initfn=service.init, runfn=service.run, logfile=logfile, runargs=runargs, appendpid=appendpid)
def run(self): try: try: self.master.run() except TimeoutException: pass finally: self.master.shutdown() if 'inserve' not in sys.argv: runargs = util.hgcmd() + ['inserve', '-R', root] else: runargs = util.hgcmd() + sys.argv[1:] pidfile = ui.config('inotify', 'pidfile') if opts['daemon'] and pidfile is not None and 'pid-file' not in runargs: runargs.append("--pid-file=%s" % pidfile) service = service() logfile = ui.config('inotify', 'log') appendpid = ui.configbool('inotify', 'appendpid', False) ui.debug('starting inotify server: %s\n' % ' '.join(runargs)) cmdutil.service(opts, initfn=service.init, runfn=service.run, logfile=logfile, runargs=runargs, appendpid=appendpid)
default='localhost', help='hostname or IP to listen on', metavar='HOST') parser.add_option('--pid', dest='pid', help='file name where the PID of the server is stored') parser.add_option('-f', '--foreground', dest='foreground', action='store_true', help='do not start the HTTP server in the background') parser.add_option('--daemon-pipefds') (options, args) = parser.parse_args() signal.signal(signal.SIGTERM, lambda x, y: sys.exit(0)) if options.foreground and options.pid: parser.error("options --pid and --foreground are mutually exclusive") opts = { 'pid_file': options.pid, 'daemon': not options.foreground, 'daemon_pipefds': options.daemon_pipefds } service = simplehttpservice(options.host, options.port) cmdutil.service(opts, initfn=service.init, runfn=service.run, runargs=[sys.executable, __file__] + sys.argv[1:])
class service(object): def init(self): try: self.master = server.master(ui, repo, timeout) except server.AlreadyStartedException, inst: raise util.Abort(str(inst)) def run(self): try: self.master.run() finally: self.master.shutdown() service = service() logfile = ui.config('inotify', 'log') cmdutil.service(opts, initfn=service.init, runfn=service.run, logfile=logfile) def debuginotify(ui, repo, **opts): '''debugging information for inotify extension Prints the list of directories being watched by the inotify server. ''' cli = client(ui, repo) response = cli.debugquery() ui.write(_('directories being watched:\n')) for path in response: ui.write((' %s/\n') % path) def reposetup(ui, repo): if not hasattr(repo, 'dirstate'):
try: self.master = server.master(ui, repo.dirstate, repo.root, timeout) except server.AlreadyStartedException, inst: raise util.Abort(str(inst)) def run(self): try: self.master.run() finally: self.master.shutdown() service = service() logfile = ui.config('inotify', 'log') cmdutil.service(opts, initfn=service.init, runfn=service.run, logfile=logfile) def debuginotify(ui, repo, **opts): '''debugging information for inotify extension Prints the list of directories being watched by the inotify server. ''' cli = client(ui, repo) response = cli.debugquery() ui.write(_('directories being watched:\n')) for path in response: ui.write((' %s/\n') % path)
self.address, SimpleHTTPServer.SimpleHTTPRequestHandler) def run(self): self.httpd.serve_forever() if __name__ == '__main__': parser = OptionParser() parser.add_option('-p', '--port', dest='port', type='int', default=8000, help='TCP port to listen on', metavar='PORT') parser.add_option('-H', '--host', dest='host', default='localhost', help='hostname or IP to listen on', metavar='HOST') parser.add_option('--pid', dest='pid', help='file name where the PID of the server is stored') parser.add_option('-f', '--foreground', dest='foreground', action='store_true', help='do not start the HTTP server in the background') parser.add_option('--daemon-pipefds') (options, args) = parser.parse_args() signal.signal(signal.SIGTERM, lambda x, y: sys.exit(0)) if options.foreground and options.pid: parser.error("options --pid and --foreground are mutually exclusive") opts = {'pid_file': options.pid, 'daemon': not options.foreground, 'daemon_pipefds': options.daemon_pipefds} service = simplehttpservice(options.host, options.port) cmdutil.service(opts, initfn=service.init, runfn=service.run, runargs=[sys.executable, __file__] + sys.argv[1:])