def __init__(self, repository): self.repopath = repository.path if self.repopath[-1] == '/': self.repopath = self.repopath[:-1] SCMTool.__init__(self, repository) import pysvn self.client = pysvn.Client() if repository.username: self.client.set_default_username(str(repository.username)) if repository.password: self.client.set_default_password(str(repository.password)) # svnlook uses 'rev 0', while svn diff uses 'revision 0' self.revision_re = re.compile(""" ^(\(([^\)]+)\)\s)? # creating diffs between two branches # of a remote repository will insert # extra "relocation information" into # the diff. (?:\d+-\d+-\d+\ + # svnlook-style diffs contain a \d+:\d+:\d+\ + # timestamp on each line before the [A-Z]+\ +)? # revision number. This here is # probably a really crappy way to # express that, but oh well. \ *\([Rr]ev(?:ision)?\ (\d+)\)$ # svnlook uses 'rev 0' while svn diff # uses 'revision 0' """, re.VERBOSE)
def __init__(self, repository): self.repopath = repository.path SCMTool.__init__(self, repository) self.client = ClearCaseClient(self.repopath) self.uses_atomic_revisions = False
def __init__(self, repository): self.repopath = repository.path if self.repopath[-1] == '/': self.repopath = self.repopath[:-1] SCMTool.__init__(self, repository)
def __init__(self, repository): SCMTool.__init__(self, repository) self.client = self._create_client( str(repository.mirror_path or repository.path), str(repository.username), str(repository.password), str(repository.encoding))
def __init__(self, repository): self.repopath = repository.path if self.repopath[-1] == '/': self.repopath = self.repopath[:-1] SCMTool.__init__(self, repository) import pysvn self.client = pysvn.Client() if repository.username: self.client.set_default_username(str(repository.username)) if repository.password: self.client.set_default_password(str(repository.password)) self.uses_atomic_revisions = True # svnlook uses 'rev 0', while svn diff uses 'revision 0' self.revision_re = re.compile(""" ^(\(([^\)]+)\)\s)? # creating diffs between two branches # of a remote repository will insert # extra "relocation information" into # the diff. (?:\d+-\d+-\d+\ + # svnlook-style diffs contain a \d+:\d+:\d+\ + # timestamp on each line before the [A-Z]+\ +)? # revision number. This here is # probably a really crappy way to # express that, but oh well. \ *\([Rr]ev(?:ision)?\ (\d+)\)$ # svnlook uses 'rev 0' while svn diff # uses 'revision 0' """, re.VERBOSE)
def __init__(self, repository): SCMTool.__init__(self, repository) self.client = self._create_client( str(repository.mirror_path or repository.path), str(repository.username), str(repository.password))
def __init__(self, repository): SCMTool.__init__(self, repository) self.cvsroot, self.repopath = \ self.build_cvsroot(self.repository.path, self.repository.username, self.repository.password) self.client = CVSClient(self.cvsroot, self.repopath)
def __init__(self, repository): SCMTool.__init__(self, repository) self.client = self._create_client( str(repository.mirror_path or repository.path), str(repository.username), str(repository.password), str(repository.encoding), repository.extra_data.get('use_ticket_auth', False))
def __init__(self, repository): SCMTool.__init__(self, repository) self.client = self._create_client( six.text_type(repository.mirror_path or repository.path), six.text_type(repository.username), six.text_type(repository.password), six.text_type(repository.encoding), repository.extra_data.get('use_ticket_auth', False))
def __init__(self, repository): SCMTool.__init__(self, repository) if repository.path.startswith("http"): self.client = HgWebClient(repository.path, repository.username, repository.password) else: self.client = HgClient(repository.path, repository.local_site) self.uses_atomic_revisions = True self.diff_uses_changeset_ids = True
def __init__(self, repository): SCMTool.__init__(self, repository) import P4 self.p4 = P4.P4() self.p4.port = str(repository.mirror_path or repository.path) self.p4.user = str(repository.username) self.p4.password = str(repository.password) self.p4.exception_level = 1
def __init__(self, repository): SCMTool.__init__(self, repository) if repository.path.startswith('http'): self.client = HgWebClient(repository.path, repository.username, repository.password) else: self.client = HgClient(repository.path, repository.local_site) self.uses_atomic_revisions = True
def __init__(self, repository): SCMTool.__init__(self, repository) if repository.path.startswith('http'): self.client = HgWebClient(repository.path, repository.username, repository.password) else: self.client = HgClient(repository.path) self.uses_atomic_revisions = True self.diff_uses_changeset_ids = True
def __init__(self, repository): SCMTool.__init__(self, repository) credentials = repository.get_credentials() self.client = self._create_client( six.text_type(repository.mirror_path or repository.path), six.text_type(credentials['username']), six.text_type(credentials['password'] or ''), six.text_type(repository.encoding), repository.extra_data.get('use_ticket_auth', False))
def __init__(self, repository): SCMTool.__init__(self, repository) if repository.path.startswith('http'): credentials = repository.get_credentials() self.client = HgWebClient(repository.path, credentials['username'], credentials['password']) else: self.client = HgClient(repository.path, repository.local_site) self.uses_atomic_revisions = True
def __init__(self, repository): self.repopath = repository.path SCMTool.__init__(self, repository) self.viewtype = self._get_view_type(self.repopath) if self.viewtype == self.VIEW_SNAPSHOT: self.client = ClearCaseSnapshotViewClient(self.repopath) elif self.viewtype == self.VIEW_DYNAMIC: self.client = ClearCaseDynamicViewClient(self.repopath) else: raise SCMError('Unsupported view type.')
def __init__(self, repository): SCMTool.__init__(self, repository) import P4 self.p4 = P4.P4() self.p4.port = str(repository.mirror_path or repository.path) self.p4.user = str(repository.username) self.p4.password = str(repository.password) self.p4.exception_level = 1 # We defer actually connecting until just before we do some operation # that requires an active connection to the perforce depot. This # connection is then left open as long as possible. self.uses_atomic_revisions = True
def _run_bzr(self, args): """Run a Bazaar command. This will run :command:`bzr` with the specified arguments, and sets up the environment to work with :command:`rbssh`. Args: args (list of unicode): The list of arguments to pass to :command:`bzr`. Returns: subprocess.Popen: The handle for the process. """ if not BZRClient._bzr_plugin_path: BZRClient._bzr_plugin_path = ( '%s:%s' % ( os.path.join(os.path.dirname(__file__), 'plugins', 'bzrlib', 'plugins'), os.environ.get(str('BZR_PLUGIN_PATH'), str(''))) ).encode('utf-8') return SCMTool.popen( ['bzr'] + args, local_site_name=self.local_site_name, env={ b'BZR_PLUGIN_PATH': BZRClient._bzr_plugin_path, b'BZR_SSH': b'rbssh', b'TZ': b'UTC', })
def _run_hg(self, args): """Runs the Mercurial command, returning a subprocess.Popen.""" if not self.default_args: self._calculate_default_args() return SCMTool.popen(['hg'] + self.default_args + args, local_site_name=self.local_site_name)
def _run_bzr(self, args): """Run a Bazaar command. This will run :command:`bzr` with the specified arguments, and sets up the environment to work with :command:`rbssh`. Args: args (list of unicode): The list of arguments to pass to :command:`bzr`. Returns: subprocess.Popen: The handle for the process. """ bzr_exe = get_bzr_exe() plugin_path_envvar = _env_vars['PLUGIN_PATH'][bzr_exe] ssh_envvar = _env_vars['SSH'][bzr_exe] if not BZRClient._plugin_path: BZRClient._plugin_path = ('%s:%s' % (os.path.join( os.path.dirname(__file__), 'plugins', 'bzrlib', 'plugins'), os.environ.get(str(plugin_path_envvar), str('')))).encode('utf-8') return SCMTool.popen([bzr_exe] + args, local_site_name=self.local_site_name, env={ plugin_path_envvar: BZRClient._plugin_path, ssh_envvar: 'rbssh', 'TZ': 'UTC', })
def _run_bzr(self, args): """Run a Bazaar command. This will run :command:`bzr` with the specified arguments, and sets up the environment to work with :command:`rbssh`. Args: args (list of unicode): The list of arguments to pass to :command:`bzr`. Returns: subprocess.Popen: The handle for the process. """ if not BZRClient._bzr_plugin_path: BZRClient._bzr_plugin_path = ( '%s:%s' % (os.path.join(os.path.dirname(__file__), 'plugins', 'bzrlib', 'plugins'), os.environ.get( b'BZR_PLUGIN_PATH', ''))).encode('utf-8') return SCMTool.popen(['bzr'] + args, local_site_name=self.local_site_name, env={ b'BZR_PLUGIN_PATH': BZRClient._bzr_plugin_path, b'BZR_SSH': b'rbssh', })
def _run_hg(self, args): """Runs the Mercurial command, returning a subprocess.Popen.""" if not self.default_args: self._calculate_default_args() return SCMTool.popen( ['hg'] + self.default_args + args, local_site_name=self.local_site_name)
def __init__(self, repository): """Initialize the tool. Args: repository (reviewboard.scmtools.models.Repository): The associated repository object. """ self.repopath = repository.path SCMTool.__init__(self, repository) self.viewtype = self._get_view_type(self.repopath) if self.viewtype == self.VIEW_SNAPSHOT: self.client = ClearCaseSnapshotViewClient(self.repopath) elif self.viewtype == self.VIEW_DYNAMIC: self.client = ClearCaseDynamicViewClient(self.repopath) else: raise SCMError('Unsupported view type.')
def check_repository(self): # Running 'cvs version' and specifying a CVSROOT will bail out if said # CVSROOT is invalid, which is perfect for us. This used to use # 'cvs rls' which is maybe slightly more correct, but rls is only # available in CVS 1.12+ p = SCMTool.popen(['cvs', '-f', '-d', self.cvsroot, 'version'], self.local_site_name) errmsg = six.text_type(p.stderr.read()) if p.wait() != 0: raise SCMError(errmsg)
def main(): if DEBUG: logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)-18s %(levelname)-8s ' '%(message)s', datefmt='%m-%d %H:%M', filename='rbssh.log', filemode='w') logging.debug('%s' % sys.argv) logging.debug('PID %s' % os.getpid()) ch = logging.StreamHandler() ch.setLevel(logging.INFO) ch.setFormatter(logging.Formatter('%(message)s')) ch.addFilter(logging.Filter('root')) logging.getLogger('').addHandler(ch) path, command = parse_options(sys.argv[1:]) if '://' not in path: path = 'ssh://' + path username, hostname = SCMTool.get_auth_from_uri(path, options.username) if username is None: username = getpass.getuser() logging.debug('!!! %s, %s, %s' % (hostname, username, command)) client = sshutils.get_ssh_client(options.local_site_name) client.set_missing_host_key_policy(paramiko.WarningPolicy()) attempts = 0 password = None key = sshutils.get_user_key(options.local_site_name) while True: try: client.connect(hostname, username=username, password=password, pkey=key, allow_agent=options.allow_agent) break except paramiko.AuthenticationException, e: if attempts == 3 or not sys.stdin.isatty(): logging.error('Too many authentication failures for %s' % username) sys.exit(1) attempts += 1 password = getpass.getpass("%s@%s's password: " % (username, hostname)) except paramiko.SSHException, e: logging.error('Error connecting to server: %s' % e) sys.exit(1)
def main(): if DEBUG: logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)-18s %(levelname)-8s ' '%(message)s', datefmt='%m-%d %H:%M', filename='rbssh.log', filemode='w') logging.debug('%s' % sys.argv) logging.debug('PID %s' % os.getpid()) ch = logging.StreamHandler() ch.setLevel(logging.INFO) ch.setFormatter(logging.Formatter('%(message)s')) ch.addFilter(logging.Filter('root')) logging.getLogger('').addHandler(ch) path, command = parse_options(sys.argv[1:]) if '://' not in path: path = 'ssh://' + path username, hostname = SCMTool.get_auth_from_uri(path, options.username) if username is None: username = getpass.getuser() logging.debug('!!! %s, %s, %s' % (hostname, username, command)) client = sshutils.get_ssh_client() client.set_missing_host_key_policy(paramiko.WarningPolicy()) attempts = 0 password = None success = False while True: try: client.connect(hostname, username=username, password=password) break except paramiko.AuthenticationException, e: if attempts == 3 or not sys.stdin.isatty(): logging.error('Too many authentication failures for %s' % username) sys.exit(1) attempts += 1 password = getpass.getpass("%s@%s's password: " % (username, hostname)) except paramiko.SSHException, e: logging.error('Error connecting to server: %s' % e) sys.exit(1)
def _cat_specific_file(self, filename, revision): # Somehow CVS sometimes seems to write .cvsignore files to current # working directory even though we force stdout with -p. self.tempdir = tempfile.mkdtemp() os.chdir(self.tempdir) p = SCMTool.popen([ 'cvs', '-f', '-d', self.cvsroot, 'checkout', '-r', str(revision), '-p', filename ], self.local_site_name) contents = p.stdout.read() errmsg = p.stderr.read() failure = p.wait() # Unfortunately, CVS is not consistent about exiting non-zero on # errors. If the file is not found at all, then CVS will print an # error message on stderr, but it doesn't set an exit code with # pservers. If the file is found but an invalid revision is requested, # then cvs exits zero and nothing is printed at all. (!) # # But, when it is successful, cvs will print a header on stderr like # so: # # =================================================================== # Checking out foobar # RCS: /path/to/repo/foobar,v # VERS: 1.1 # *************** # So, if nothing is in errmsg, or errmsg has a specific recognized # message, call it FileNotFound. if not errmsg or \ errmsg.startswith('cvs checkout: cannot find module') or \ errmsg.startswith('cvs checkout: could not read RCS file'): self.cleanup() raise FileNotFoundError(filename, revision) # Otherwise, if there's an exit code, or errmsg doesn't look like # successful header, then call it a generic SCMError. # # If the .cvspass file doesn't exist, CVS will return an error message # stating this. This is safe to ignore. if (failure and not errmsg.startswith('==========')) and \ not ".cvspass does not exist - creating new file" in errmsg: self.cleanup() raise SCMError(errmsg) self.cleanup() return contents
def _cat_specific_file(self, filename, revision): # Somehow CVS sometimes seems to write .cvsignore files to current # working directory even though we force stdout with -p. self.tempdir = tempfile.mkdtemp() os.chdir(self.tempdir) p = SCMTool.popen(['cvs', '-f', '-d', self.cvsroot, 'checkout', '-r', six.text_type(revision), '-p', filename], self.local_site_name) contents = p.stdout.read() errmsg = six.text_type(p.stderr.read()) failure = p.wait() # Unfortunately, CVS is not consistent about exiting non-zero on # errors. If the file is not found at all, then CVS will print an # error message on stderr, but it doesn't set an exit code with # pservers. If the file is found but an invalid revision is requested, # then cvs exits zero and nothing is printed at all. (!) # # But, when it is successful, cvs will print a header on stderr like # so: # # =================================================================== # Checking out foobar # RCS: /path/to/repo/foobar,v # VERS: 1.1 # *************** # So, if nothing is in errmsg, or errmsg has a specific recognized # message, call it FileNotFound. if (not errmsg or errmsg.startswith('cvs checkout: cannot find module') or errmsg.startswith('cvs checkout: could not read RCS file')): self.cleanup() raise FileNotFoundError(filename, revision) # Otherwise, if there's an exit code, or errmsg doesn't look like # successful header, then call it a generic SCMError. # # If the .cvspass file doesn't exist, CVS will return an error message # stating this. This is safe to ignore. if ((failure and not errmsg.startswith('==========')) and not '.cvspass does not exist - creating new file' in errmsg): self.cleanup() raise SCMError(errmsg) self.cleanup() return contents
def main(): if DEBUG: global debug_fp fd, name = tempfile.mkstemp(prefix='rbssh', suffix='.log') debug_fp = os.fdopen(fd, "w+b") fp.write('%s\n' % sys.argv) fp.write('PID %s\n' % os.getpid()) path, command = parse_options(sys.argv[1:]) if '://' not in path: path = 'ssh://' + path username, hostname = SCMTool.get_auth_from_uri(path, None) debug('%s, %s, %s\n' % (hostname, username, command)) client = sshutils.get_ssh_client() client.connect(hostname, username=username) transport = client.get_transport() channel = transport.open_session() channel.exec_command(' '.join(command)) if os.name == 'posix': begin_posix(channel) else: begin_windows(channel) status = channel.recv_exit_status() client.close() if debug_fp: fp.close() return status
def check_repository(self): # Running 'cvs version' and specifying a CVSROOT will bail out if said # CVSROOT is invalid, which is perfect for us. This used to use # 'cvs rls' which is maybe slightly more correct, but rls is only # available in CVS 1.12+ p = SCMTool.popen(['cvs', '-f', '-d', self.cvsroot, 'version'], self.local_site_name) errmsg = six.text_type(p.stderr.read()) if p.wait() != 0: logging.error('CVS repository validation failed for ' 'CVSROOT %s: %s', self.cvsroot, errmsg) auth_failed_prefix = 'cvs version: authorization failed: ' # See if there's an "authorization failed" anywhere in here. If so, # we want to raise AuthenticationError with that error message. for line in errmsg.splitlines(): if line.startswith(auth_failed_prefix): raise AuthenticationError( msg=line[len(auth_failed_prefix):].strip()) raise SCMError(errmsg)
def check_repository(self): # Running 'cvs version' and specifying a CVSROOT will bail out if said # CVSROOT is invalid, which is perfect for us. This used to use # 'cvs rls' which is maybe slightly more correct, but rls is only # available in CVS 1.12+ p = SCMTool.popen(['cvs', '-f', '-d', self.cvsroot, 'version'], self.local_site_name) errmsg = six.text_type(p.stderr.read()) if p.wait() != 0: logging.error( 'CVS repository validation failed for ' 'CVSROOT %s: %s', self.cvsroot, errmsg) auth_failed_prefix = 'cvs version: authorization failed: ' # See if there's an "authorization failed" anywhere in here. If so, # we want to raise AuthenticationError with that error message. for line in errmsg.splitlines(): if line.startswith(auth_failed_prefix): raise AuthenticationError( msg=line[len(auth_failed_prefix):].strip()) raise SCMError(errmsg)
def __init__(self, repository): SCMTool.__init__(self, repository) self.client = GitClient(repository.path, repository.raw_file_url)
def __init__(self, repository): SCMTool.__init__(self, repository)
def __init__(self, repository): SCMTool.__init__(self, repository) self.cvsroot, self.repopath = self.build_cvsroot() self.client = CVSClient(self.cvsroot, self.repopath)
def __init__(self, repository): SCMTool.__init__(self, repository) self.client = MonotoneClient(repository.path)
def main(): """Run the application.""" os.environ.setdefault(str('DJANGO_SETTINGS_MODULE'), str('reviewboard.settings')) if DEBUG: pid = os.getpid() log_filename = 'rbssh-%s.log' % pid if DEBUG_LOGDIR: log_path = os.path.join(DEBUG_LOGDIR, log_filename) else: log_path = log_filename logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)-18s %(levelname)-8s ' '%(message)s', datefmt='%m-%d %H:%M', filename=log_path, filemode='w') logging.debug('%s' % sys.argv) logging.debug('PID %s' % pid) initialize() ch = logging.StreamHandler() ch.setLevel(logging.INFO) ch.setFormatter(logging.Formatter('%(message)s')) ch.addFilter(logging.Filter('root')) logging.getLogger('').addHandler(ch) path, port, command = parse_options(sys.argv[1:]) if '://' not in path: path = 'ssh://' + path username, hostname = SCMTool.get_auth_from_uri(path, options.username) if username is None: username = getpass.getuser() logging.debug('!!! %s, %s, %s' % (hostname, username, command)) client = SSHClient(namespace=options.local_site_name) client.set_missing_host_key_policy(paramiko.WarningPolicy()) attempts = 0 password = None key = client.get_user_key() while True: try: client.connect(hostname, port, username=username, password=password, pkey=key, allow_agent=options.allow_agent) break except paramiko.AuthenticationException as e: if attempts == 3 or not sys.stdin.isatty(): logging.error('Too many authentication failures for %s' % username) sys.exit(1) attempts += 1 password = getpass.getpass("%s@%s's password: " % (username, hostname)) except paramiko.SSHException as e: logging.error('Error connecting to server: %s' % e) sys.exit(1) except Exception as e: logging.error('Unknown exception during connect: %s (%s)' % (e, type(e))) sys.exit(1) transport = client.get_transport() channel = transport.open_session() if sys.platform in ('cygwin', 'win32'): logging.debug('!!! Using WindowsHandler') handler = WindowsHandler(channel) else: logging.debug('!!! Using PosixHandler') handler = PosixHandler(channel) if options.subsystem == 'sftp': logging.debug('!!! Invoking sftp subsystem') channel.invoke_subsystem('sftp') handler.transfer() elif command: logging.debug('!!! Sending command %s' % command) channel.exec_command(' '.join(command)) handler.transfer() else: logging.debug('!!! Opening shell') channel.get_pty() channel.invoke_shell() handler.shell() logging.debug('!!! Done') status = channel.recv_exit_status() client.close() return status
def main(): """Run the application.""" # We don't want any warnings to end up impacting output. warnings.simplefilter('ignore') if DEBUG: pid = os.getpid() log_filename = 'rbssh-%s.log' % pid if DEBUG_LOGDIR: log_path = os.path.join(DEBUG_LOGDIR, log_filename) else: log_path = log_filename logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)-18s %(levelname)-8s ' '%(message)s', datefmt='%m-%d %H:%M', filename=log_path, filemode='w') debug('%s', sys.argv) debug('PID %s', pid) # Perform the bare minimum to initialize the Django/Review Board # environment. We're not calling Review Board's initialize() because # we want to completely minimize what we import and set up. if hasattr(django, 'setup'): django.setup() from reviewboard.scmtools.core import SCMTool from reviewboard.ssh.client import SSHClient ch = logging.StreamHandler() ch.setLevel(logging.INFO) ch.setFormatter(logging.Formatter('%(message)s')) ch.addFilter(logging.Filter('root')) logging.getLogger('').addHandler(ch) path, port, command = parse_options(sys.argv[1:]) if '://' not in path: path = 'ssh://' + path username, hostname = SCMTool.get_auth_from_uri(path, options.username) if username is None: username = getpass.getuser() client = SSHClient(namespace=options.local_site_name) client.set_missing_host_key_policy(paramiko.WarningPolicy()) if command: purpose = command else: purpose = 'interactive shell' debug('!!! SSH backend = %s', type(client.storage)) debug('!!! Preparing to connect to %s@%s for %s', username, hostname, purpose) attempts = 0 password = None key = client.get_user_key() while True: try: client.connect(hostname, port, username=username, password=password, pkey=key, allow_agent=options.allow_agent) break except paramiko.AuthenticationException as e: if attempts == 3 or not sys.stdin.isatty(): logging.error('Too many authentication failures for %s' % username) sys.exit(1) attempts += 1 password = getpass.getpass("%s@%s's password: " % (username, hostname)) except paramiko.SSHException as e: logging.error('Error connecting to server: %s' % e) sys.exit(1) except Exception as e: logging.error('Unknown exception during connect: %s (%s)' % (e, type(e))) sys.exit(1) transport = client.get_transport() channel = transport.open_session() if sys.platform in ('cygwin', 'win32'): debug('!!! Using WindowsHandler') handler = WindowsHandler(channel) else: debug('!!! Using PosixHandler') handler = PosixHandler(channel) if options.subsystem == 'sftp': debug('!!! Invoking sftp subsystem') channel.invoke_subsystem('sftp') handler.transfer() elif command: debug('!!! Sending command %s', command) channel.exec_command(' '.join(command)) handler.transfer() else: debug('!!! Opening shell') channel.get_pty() channel.invoke_shell() handler.shell() debug('!!! Done') status = channel.recv_exit_status() client.close() return status
def main(): """Run the application.""" if DEBUG: pid = os.getpid() log_filename = 'rbssh-%s.log' % pid if DEBUG_LOGDIR: log_path = os.path.join(DEBUG_LOGDIR, log_filename) else: log_path = log_filename logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)-18s %(levelname)-8s ' '%(message)s', datefmt='%m-%d %H:%M', filename=log_path, filemode='w') logging.debug('%s' % sys.argv) logging.debug('PID %s' % pid) ch = logging.StreamHandler() ch.setLevel(logging.INFO) ch.setFormatter(logging.Formatter('%(message)s')) ch.addFilter(logging.Filter('root')) logging.getLogger('').addHandler(ch) path, port, command = parse_options(sys.argv[1:]) if '://' not in path: path = 'ssh://' + path username, hostname = SCMTool.get_auth_from_uri(path, options.username) if username is None: username = getpass.getuser() logging.debug('!!! %s, %s, %s' % (hostname, username, command)) client = SSHClient(namespace=options.local_site_name) client.set_missing_host_key_policy(paramiko.WarningPolicy()) attempts = 0 password = None key = client.get_user_key() while True: try: client.connect(hostname, port, username=username, password=password, pkey=key, allow_agent=options.allow_agent) break except paramiko.AuthenticationException as e: if attempts == 3 or not sys.stdin.isatty(): logging.error('Too many authentication failures for %s' % username) sys.exit(1) attempts += 1 password = getpass.getpass("%s@%s's password: " % (username, hostname)) except paramiko.SSHException as e: logging.error('Error connecting to server: %s' % e) sys.exit(1) except Exception as e: logging.error('Unknown exception during connect: %s (%s)' % (e, type(e))) sys.exit(1) transport = client.get_transport() channel = transport.open_session() if sys.platform in ('cygwin', 'win32'): logging.debug('!!! Using WindowsHandler') handler = WindowsHandler(channel) else: logging.debug('!!! Using PosixHandler') handler = PosixHandler(channel) if options.subsystem == 'sftp': logging.debug('!!! Invoking sftp subsystem') channel.invoke_subsystem('sftp') handler.transfer() elif command: logging.debug('!!! Sending command %s' % command) channel.exec_command(' '.join(command)) handler.transfer() else: logging.debug('!!! Opening shell') channel.get_pty() channel.invoke_shell() handler.shell() logging.debug('!!! Done') status = channel.recv_exit_status() client.close() return status
def check_repository(self): p = SCMTool.popen(['cvs', '-f', '-d', self.cvsroot, 'rls'], self.local_site_name) errmsg = six.text_type(p.stderr.read()) if p.wait() != 0: raise SCMError(errmsg)
def __init__(self, repository): self.repopath = repository.path SCMTool.__init__(self, repository) self.client = ClearCaseClient(self.repopath)
def _run_git(self, args): """Runs a git command, returning a subprocess.Popen.""" return SCMTool.popen(['git'] + args, local_site_name=self.local_site_name)
def __init__(self, repository): SCMTool.__init__(self, repository) self.client = GitClient(repository.path, repository.raw_file_url, repository.username, repository.password)