Upload the napp from the current directory to the napps server.
19327
def upload_napp(self, metadata, package):
        """"""
        endpoint = os.path.join(self._config.get('napps', 'api'), 'napps', '')
        metadata['token'] = self._config.get('auth', 'token')
        request = self.make_request(endpoint, json=metadata, package=package,
                                    method="POST")
        if request.status_code != 201:
            KytosConfig().clear_token()
            LOG.error("%s: %s", request.status_code, request.reason)
            sys.exit(1)

        # WARNING: this will change in future versions, when 'author' will get
        # removed.
        username = metadata.get('username', metadata.get('author'))
        name = metadata.get('name')

        print("SUCCESS: NApp {}/{} uploaded.".format(username, name))
1369825
def upload_current_script():
    """"""
    current_editor = get_workbench().get_editor_notebook().get_current_editor()
    code = current_editor.get_text_widget().get("1.0", "end")
    try:
        filename= current_editor.get_filename()
        if (not filename) or (not filename.endswith(".py")):
            return

        ast.parse(code)

        if not code.startswith('#!'):
            if tkMessageBox.askokcancel("Shebang", "To make a python file on the EV3 executable Thonny prepends the shebang line:\n\n      !#/usr/bin/env python3\n"):
                current_editor.get_text_widget().direct_insert("1.0", "#!/usr/bin/env python3\n")
            else:
               return

        # automatically save file (without confirm dialog, nor dialog for asking filename )
        # save_file does return None, if script is not saved and user closed file saving window, otherwise return file name.
        py_file = current_editor.save_file(False)
        if py_file is None:
            return

        upload(py_file)
    except Exception:
        error_msg = traceback.format_exc(0)+'\n'
        showerror("Error", error_msg)
141912
def upload_release(self):
        """"""
        self.before_upload_release()

        with settings(user=self.user):
            with app_bundle():
                local_bundle = env.local_bundle
                env.bundle = '/tmp/' + os.path.basename(local_bundle)
                file_upload(env.bundle, local_bundle)

            # Extract the bundle into a release folder
            current_release_link = self.releases_dir + '/current'
            previous_release_link = self.releases_dir + '/previous'
            release_dir = self.releases_dir + '/' + env.release

            dir_ensure(release_dir)
            with cd(release_dir):
                run('tar -xvf ' + env.bundle)

            # Delete the remote bundle
            run('rm ' + env.bundle)

            # Remove previous release link
            if file_exists(previous_release_link):
                run('rm ' + previous_release_link)

            # Move current to previous
            if file_exists(current_release_link):
                run('mv %s %s' % (current_release_link, previous_release_link))

            # Link the current release
            file_link(release_dir, self.releases_dir + "/current")

            # Install app dependencies
            with cd(current_release_link):
                with prefix('workon ' + self.name):
                    run('pip install -r requirements.txt')

        self.after_upload_release()
555108
def upload(self, local_path, remote_url):
        """"""
        bucket, key = _parse_url(remote_url)

        with open(local_path, 'rb') as fp:
            return self.call("PutObject", bucket=bucket, key=key, body=fp)
126150
def reload_napps(self, napps=None):
        
        if napps is None:
            napps = []
            api = self._config.get('kytos', 'api')
            endpoint = os.path.join(api, 'api', 'kytos', 'core', 'reload',
                                    'all')
            response = self.make_request(endpoint)

        for napp in napps:
            api = self._config.get('kytos', 'api')
            endpoint = os.path.join(api, 'api', 'kytos', 'core', 'reload',
                                    napp[0], napp[1])
            response = self.make_request(endpoint)

        if response.status_code != 200:
            raise KytosException('Error reloading the napp: Module not founded'
                                 ' or could not be imported')

        return response.content
595082
def upload(self, src_file_path, dst_file_name=None):
        """"""
        self._check_session()
        status, data = self._rest.upload_file(
            'files', src_file_path, dst_file_name)
        return data
875084
def upload(self):
        ''''''
        info = pcs.upload(self.cookie, self.row[SOURCEPATH_COL],
                          self.row[PATH_COL], self.upload_mode)
        if info:
            self.emit('uploaded', self.row[FID_COL])
        else:
            self.emit('network-error', self.row[FID_COL])
534950
def reload(self, napps=None):
        
        client = NAppsClient(self._config)
        client.reload_napps(napps)
651161
def execute(self):
        """"""
        try:
            if self.upstream:
                if self.options['listings'] is True:
                    listing.upload(self.client, self.source_directory)
                    self.client.commit()
                if self.options['images'] is True:
                    image.upload(self.client, self.source_directory)
                    self.client.commit()
                if self.options['inapp'] is True:
                    inapp_product.upload(self.client, self.source_directory)
            else:
                if self.options['listings'] is True:
                    listing.download(self.client, self.source_directory)
                if self.options['images'] is True:
                    image.download(self.client, self.source_directory)
                if self.options['inapp'] is True:
                    inapp_product.download(self.client, self.source_directory)

        except client.AccessTokenRefreshError:
            print(
                'The credentials have been revoked or expired, please re-run'
                'the application to re-authorize')
828070
def make_request(endpoint, **kwargs):
        """"""
        data = kwargs.get('json', [])
        package = kwargs.get('package', None)
        method = kwargs.get('method', 'GET')

        function = getattr(requests, method.lower())

        try:
            if package:
                response = function(endpoint, data=data,
                                    files={'file': package})
            else:
                response = function(endpoint, json=data)
        except requests.exceptions.ConnectionError:
            LOG.error("Couldn't connect to NApps server %s.", endpoint)
            sys.exit(1)

        return response
640241
public void goUpDir() throws IOException, ServerException {
        try {
            controlChannel.execute(Command.CDUP);
            // alternative: changeDir("..");
        } catch (FTPReplyParseException rpe) {
            throw ServerException.embedFTPReplyParseException(rpe);
        } catch (UnexpectedReplyCodeException urce) {
            throw ServerException.embedUnexpectedReplyCodeException(
                                urce,
                                "Server refused changing current directory");
        }
    }
773424
def file_upload(self, local_path, remote_path, l_st):
        """"""
        self.sftp.put(local_path, remote_path)
        self._match_modes(remote_path, l_st)
331183
def enable_napp(cls, mgr):
        """"""
        try:
            if not mgr.is_enabled():
                LOG.info('    Enabling...')
                mgr.enable()
            LOG.info('    Enabled.')
        except (FileNotFoundError, PermissionError) as exception:
            LOG.error('  %s', exception)
1129657
def upload(self):
        '''
        
        '''
        if not self.exists():
            self.create()

        data = self.stage().json()
        self.file_upload(data['post_url'], data)
        res = self.commit(data['dist_id'])
        data = res.json()
        return data
171095
def upload(self,project, inputtemplate, sourcefile, **kwargs):
        """"""
        return self.addinputfile(project, inputtemplate,sourcefile, **kwargs)
73316
def do_put(self, from_path, to_path):
        
        from_file = open(os.path.expanduser(from_path), "rb")

        self.n.put(self.current_path + "/" + from_path, to_path)
1066872
def upload(
    ctx, files, max_threads, prompt, forward, reverse, tags, metadata, project_id, coerce_ascii
):
    """"""

    appendables = {}
    if tags:
        appendables["tags"] = []
        for tag in tags:
            appendables["tags"].append(tag)

    if metadata:
        appendables["metadata"] = {}
        for metadata_kv in metadata:
            split_metadata = metadata_kv.split("=", 1)
            if len(split_metadata) > 1:
                metadata_value = split_metadata[1]
                appendables["metadata"][split_metadata[0]] = metadata_value

    appendables = validate_appendables(appendables, ctx.obj["API"])

    if (forward or reverse) and not (forward and reverse):
        click.echo("You must specify both forward and reverse files", err=True)
        ctx.exit(1)

    if forward and reverse:
        if len(files) > 0:
            click.echo(
                "You may not pass a FILES argument when using the "
                " --forward and --reverse options.",
                err=True,
            )
            ctx.exit(1)
        files = [(forward, reverse)]
    elif len(files) == 0:
        click.echo(ctx.get_help())
        return
    else:
        files = list(files)

        # "intelligently" find paired files and tuple them
        paired_files = []
        single_files = set(files)

        for filename in files:
            # convert "read 1" filenames into "read 2" and check that they exist; if they do
            # upload the files as a pair, autointerleaving them
            pair = re.sub("[._][Rr]1[._]", lambda x: x.group().replace("1", "2"), filename)

            # we don't necessary need the R2 to have been passed in; we infer it anyways
            if pair != filename and os.path.exists(pair):
                if not prompt and pair not in single_files:
                    # if we're not prompting, don't automatically pull in files
                    # not in the list the user passed in
                    continue

                paired_files.append((filename, pair))

                if pair in single_files:
                    single_files.remove(pair)

                single_files.remove(filename)

        auto_pair = True

        if prompt and len(paired_files) > 0:
            pair_list = ""
            for p in paired_files:
                pair_list += "\n  {}  &  {}".format(os.path.basename(p[0]), os.path.basename(p[1]))

            answer = click.confirm(
                "It appears there are paired files:{}\nInterleave them after upload?".format(
                    pair_list
                ),
                default="Y",
            )

            if not answer:
                auto_pair = False

        if auto_pair:
            files = paired_files + list(single_files)

    total_size = sum(
        [
            (_file_size(x[0], uncompressed=True) + _file_size(x[1], uncompressed=True))
            if isinstance(x, tuple)
            else _file_size(x, uncompressed=False)
            for x in files
        ]
    )

    upload_kwargs = {
        "metadata": appendables["valid_metadata"],
        "tags": appendables["valid_tags"],
        "project": project_id,
        "coerce_ascii": coerce_ascii,
        "progressbar": progressbar(length=total_size, label="Uploading..."),
    }

    run_via_threadpool(
        ctx.obj["API"].Samples.upload,
        files,
        upload_kwargs,
        max_threads=max_threads,
        graceful_exit=False,
    )