pull all remote programs to a local directory
968782
def pull(options):
    
    configuration = config.get_default()
    app_url = configuration['app_url']

    if options.deployment != None:
        deployment_name = options.deployment
    else:
        deployment_name = configuration['deployment_name']

    client_id = configuration['client_id']
    client_secret = configuration['client_secret']

    token_manager = auth.TokenManager(client_id=client_id,
                                      client_secret=client_secret,
                                      app_url=app_url)

    if options.all == True:
        account_id = None

    else:
        account_id = accounts.get_logged_in_account_id(token_manager=token_manager,
                                                       app_url=app_url)

    programs_details = programs.get_programs(deployment_name,
                                             token_manager=token_manager,
                                             created_by=account_id,
                                             app_url=app_url)

    if not os.path.exists(options.directory):
        os.mkdir(options.directory)

    account_ids = set()
    for program in programs_details:
        account_ids.add(program['createdBy'])

    accounts_details = accounts.get_accounts(account_ids,
                                             token_manager=token_manager,
                                             app_url=app_url)

    account_lookup = {}
    for account in accounts_details['accounts']:
        account_lookup[account['id']] = account

    decision = None
    for program in programs_details:
        program_name = program['name']
        juttle_filename = '%s.juttle' % escape_filename(program_name)

        if options.per_user_directory:
            username = account_lookup[program['createdBy']]['username']
            userdir = os.path.join(options.directory, username)

            if not os.path.exists(userdir):
                os.mkdir(userdir)

            juttle_filepath = os.path.join(userdir, juttle_filename)

        else:
            juttle_filepath = os.path.join(options.directory, juttle_filename)

        if os.path.exists(juttle_filepath) and decision != 'A':
            program_code = None
            with codecs.open(juttle_filepath, 'r', encoding='UTF-8') as program_file:
                program_code = program_file.read()

            local_last_edited = int(os.stat(juttle_filepath).st_mtime)
            remote_last_edited = dates.iso8601_to_epoch(program['lastEdited'])

            if local_last_edited != remote_last_edited:
                info('Juttle changed since last pull for "%s"' % program_name)
                decision = console.prompt('Would you like to '
                                          '(O - Override,'
                                          ' S - Skip,'
                                          ' R - Review Changes,'
                                          ' A - override All)?')

                if decision == 'R':
                    info('Following is what would change if we overrode using your copy:')
                    info('*'*80)
                    for line in difflib.ndiff(program['code'].split('\n'),
                                              program_code.split('\n')):
                        info(line)
                    info('*'*80)
                    decision = console.prompt('Would you like to '
                                              '(O - Override,'
                                              ' S - Skip)?')

                if decision == 'S':
                    # jump to the next file
                    continue

                elif decision == 'O':
                    pass

                elif decision == 'A':
                    pass

                else:
                    raise JutException('Unexpected option "%s"' % decision)

        info('importing program "%s" to %s' % (program['name'], juttle_filepath))
        with codecs.open(juttle_filepath, 'w', encoding='UTF-8') as program_file:
            program_file.write(program['code'])

        # update creation time to match the lastEdited field
        epoch = dates.iso8601_to_epoch(program['lastEdited'])
        os.utime(juttle_filepath, (epoch, epoch))
1048154
def _get_remote(self, cached=True):
        '''
        
        '''

        return self.m(
            'getting current remote',
            cmdd=dict(
                cmd='git remote show %s' % ('-n' if cached else ''),
                cwd=self.local
            ),
            verbose=False
        )
309594
def run_local(client):
  """"""
  webbrowser.open(client.get_auth_uri())
  code = wait_for_redirect()
  return client.get_token(code)
157361
def local_run():
  """"""
  server_software = os.environ.get('SERVER_SOFTWARE')
  if server_software is None:
    return True
  if 'remote_api' in server_software:
    return False
  if server_software.startswith(('Development', 'testutil')):
    return True
  return False
1040677
def up_by_files(to_sync, remote_dir=DEFAULT_REMOTE_DIR, remote_files=None):
    """"""
    if remote_files is None:
        remote_files = command.map_files_raw(remote_dir=remote_dir)
    for local_file in to_sync:
        _sync_local_file(local_file, remote_dir, remote_files)
631053
def remote_urls(self):
        
        cmd = 'git config -l | grep "url"'
        return self.sh(cmd,
                       shell=True,
                       ignore_error=True).strip()
963588
def cd(self, remote):
        
        try:
            self.conn.cwd(remote)
        except Exception:
            return False
        else:
            return self.pwd()
258494
def check_dependencies_remote(args):
    
    cmd = [args.python, '-m', 'depends', args.requirement]
    env = dict(PYTHONPATH=os.path.dirname(__file__))
    return subprocess.check_call(cmd, env=env)
766259
def download(cls, filename, input_dir, dl_dir=None):
        
        file_info = cls.parse_remote(filename)
        if not dl_dir:
            dl_dir = os.path.join(input_dir, file_info.bucket,
                                  os.path.dirname(file_info.key))
            utils.safe_makedir(dl_dir)

        out_file = os.path.join(dl_dir, os.path.basename(file_info.key))

        if not utils.file_exists(out_file):
            with file_transaction({}, out_file) as tx_out_file:
                command, prog = cls._download_cl(filename)
                if prog == "gof3r":
                    command.extend(["-p", tx_out_file])
                elif prog == "awscli":
                    command.extend([tx_out_file])
                else:
                    raise NotImplementedError(
                        "Unexpected download program %s" % prog)
                subprocess.check_call(command)
        return out_file
103192
def collect_local(self, path):
        
        for f in os.listdir(path):
            lpath = os.path.join(path, f)
            if not os.path.isfile(lpath):
                continue
            Artifact(self, lpath)
211019
def download(self, package_name):
        """"""
        if not package_name:
            ValueError('package_name required.')
        if self.is_dnf:
            cmd = 'dnf download {0}.{1}'.format(package_name, self.arch)
        else:
            cmd = 'yumdownloader {0}.{1}'.format(package_name, self.arch)
        try:
            Cmd.sh_e(cmd, stdout=subprocess.PIPE)
        except CmdError as e:
            for out in (e.stdout, e.stderr):
                for line in out.split('\n'):
                    if re.match(r'^No package [^ ]+ available', line) or \
                       re.match(r'^No Match for argument', line):
                        raise RemoteFileNotFoundError(
                            'Package {0} not found on remote'.format(
                                package_name
                            )
                        )
            raise e
432420
public void get(String remoteFile, String localTargetDirectory) throws IOException {
        get(new String[]{remoteFile}, localTargetDirectory);
    }
325509
def run(self):
        """"""

        # Check if remote path is present
        try:
            self.sftp.stat(self.remote_path)
        except FileNotFoundError as e:
            if self.create_remote_directory:
                self.sftp.mkdir(self.remote_path)
                self.logger.info(
                    "Created missing remote dir: '" + self.remote_path + "'")
            else:
                self.logger.error(
                    "Remote folder does not exists. "
                    "Add '-r' to create it if missing.")
                sys.exit(1)

        try:
            if self.delete:
                # First check for items to be removed
                self.check_for_deletion()

            # Now scan local for items to upload/create
            self.check_for_upload_create()
        except FileNotFoundError:
            # If this happens, probably the remote folder doesn't exist.
            self.logger.error(
                "Error while opening remote folder. Are you sure it does exist?")
            sys.exit(1)
1197244
def run_local(self, commands):
        
        process = subprocess.Popen(
            commands.get('cli_command'),
            shell=self.shell,
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )

        out, err = process.communicate()

        # display app output
        self.run_display_app_output(out)
        self.run_display_app_errors(err)

        # Exit Code
        return self.run_exit_code(process.returncode)
272950
def _sftp_walk(self, remotepath):
        """"""
        #Get all the files and folders in the current directory over SFTP.
        path = remotepath # We need this instance of path for the yield to work.
        files=[]
        folders=[]
        for f in self.ftp.listdir_attr(remotepath):
            if S_ISDIR(f.st_mode):
                folders.append(self._get_tramp_path(f.filename))
            else:
                files.append(f.filename)
        #We use yield so that if there are really large folders with 
        #complicated structures, we don't wait forever while the SFTP
        #keeps traversing down the tree.
        yield path, folders, files

        #Now call this method recursively for each of sub-directories.
        for folder in folders:
            new_path = os.path.join(remotepath, folder)
            for x in self._sftp_walk(new_path):
                yield x
7439
def git_pull(repo_dir, remote="origin", ref=None, update_head_ok=False):
    """"""
    command = ['git', 'pull']
    if update_head_ok:
        command.append('--update-head-ok')
    command.append(pipes.quote(remote))
    if ref:
        command.append(ref)
    return execute_git_command(command, repo_dir=repo_dir)
443714
def _accumulate_remotes(synapse_parent_id, syn):
    
    remotes = {}
    s_base_folder = syn.get(synapse_parent_id)
    for (s_dirpath, s_dirpath_id), _, s_filenames in synapseutils.walk(syn, synapse_parent_id):
        remotes[s_dirpath] = s_dirpath_id
        if s_filenames:
            for s_filename, s_filename_id in s_filenames:
                remotes[os.path.join(s_dirpath, s_filename)] = s_filename_id
    return s_base_folder, remotes