Python click.echo() Examples
The following are 30
code examples of click.echo().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
click
, or try the search function
.
Example #1
Source File: commands.py From drydock with Apache License 2.0 | 8 votes |
def task_builddata(ctx, task_id=None, output='yaml'): """Show builddata assoicated with ``task_id``.""" if not task_id: ctx.fail('The task id must be specified by --task-id') task_bd = TaskBuildData(ctx.obj['CLIENT'], task_id=task_id).invoke() if output == 'json': click.echo(json.dumps(task_bd)) else: if output != 'yaml': click.echo( 'Invalid output format {}, defaulting to YAML.'.format(output)) click.echo( yaml.safe_dump( task_bd, allow_unicode=True, default_flow_style=False))
Example #2
Source File: adapter.py From django-click with MIT License | 8 votes |
def get_params(self, name): def show_help(ctx, param, value): if value and not ctx.resilient_parsing: click.echo(ctx.get_help(), color=ctx.color) ctx.exit() return [ click.version_option(version=self.version, message="%(version)s"), click.option( "-h", "--help", is_flag=True, is_eager=True, expose_value=False, callback=show_help, help="Show this message and exit.", ), ] + self.common_options
Example #3
Source File: cloud.py From Paradrop with Apache License 2.0 | 6 votes |
def rename_node(ctx, name, new_name): """ Change the name of a node. NAME must be the name of a node that you control. NEW_NAME is the desired new name. It must adhere to the same naming rules as for the create-node command, namely, it must begin with a letter and consist of only lowercase letters, numbers, and hyphen. """ client = ControllerClient() node = client.find_node(name) if node is None: click.echo("Node {} was not found.".format(name)) return node['name'] = new_name result = client.save_node(node) click.echo(util.format_result(result)) return result
Example #4
Source File: cloud.py From Paradrop with Apache License 2.0 | 6 votes |
def claim_node(ctx, token, name): """ Take ownership of a node by using a claim token. TOKEN is a hard-to-guess string that the previous owner would have configured when setting the node's status as orphaned. """ client = ControllerClient() result = client.claim_node(token, name=name) if result is not None and 'name' in result: click.echo("Claimed node with name {}".format(result['name'])) elif result is not None and 'message' in result: click.echo(result['message']) else: click.echo("No node was found with that claim token.") return result
Example #5
Source File: chute.py From Paradrop with Apache License 2.0 | 6 votes |
def validate(ctx): """ Validate the paradrop.yaml file. A note about versions: this command validates the chute configuration against the current rules for the installed version of pdtools. If the chute is to be installed on a Paradrop node running a different version, then this command may not be reliable for determining compatibility. """ with open('paradrop.yaml', 'r') as source: chute = yaml.safe_load(source) schema_path = pkg_resources.resource_filename('pdtools', 'schemas/chute.json') with open(schema_path, 'r') as source: schema = json.load(source) validator = jsonschema.Draft4Validator(schema) for error in sorted(validator.iter_errors(chute), key=str): click.echo(error.message)
Example #6
Source File: store.py From Paradrop with Apache License 2.0 | 6 votes |
def list_versions(ctx, name): """ List versions of a chute in the store. NAME must be the name of a chute in the store. """ client = ControllerClient() result = client.list_versions(name) if len(result) > 0: click.echo("Version GitCheckout") for version in sorted(result, key=operator.itemgetter('version')): try: code = version['config']['download']['checkout'] except: code = "N/A" click.echo("{:7s} {}".format(str(version['version']), code)) return result
Example #7
Source File: store.py From Paradrop with Apache License 2.0 | 6 votes |
def list_chutes(ctx): """ List chutes in the store that you own or have access to. """ client = ControllerClient() result = client.list_chutes() if len(result) > 0: click.echo("Name Ver Description") for chute in sorted(result, key=operator.itemgetter('name')): # Show the summary if available. This is intended to be # a shorter description than the description field. summary = chute.get('summary', None) if summary is None: summary = chute.get('description', '') click.echo("{:32s} {:3d} {}".format(chute['name'], chute['current_version'], summary)) return result
Example #8
Source File: cloud.py From Paradrop with Apache License 2.0 | 6 votes |
def edit_node_description(ctx, name): """ Interactively edit the node description and save. NAME must be the name of a node that you own. Open the text editor specified by the EDITOR environment variable with the current node description. If you save and exit, the changes will be applied to the node. """ client = ControllerClient() node = client.find_node(name) if node is None: click.echo("Node {} was not found.".format(name)) return description = click.edit(node.get('description', '')) if description is None: click.echo("No change made.") else: node['description'] = description result = client.save_node(node) click.echo(util.format_result(result)) return result
Example #9
Source File: store.py From Paradrop with Apache License 2.0 | 6 votes |
def install_chute(ctx, chute, node, follow, version): """ Install a chute from the store. CHUTE must be the name of a chute in the store. NODE must be the name of a node that you control. """ client = ControllerClient() result = client.install_chute(chute, node, select_version=version) click.echo(util.format_result(result)) if follow: result2 = client.follow_chute(chute, node) click.echo(util.format_result(result2)) click.echo("Streaming messages until the update has completed.") click.echo("Ending output with Ctrl+C will not cancel the update.\n") ctx.invoke(watch_update_messages, node_id=result['router_id'], update_id=result['_id']) return result
Example #10
Source File: store.py From Paradrop with Apache License 2.0 | 6 votes |
def create_version(ctx): """ Push a new version of the chute to the store. """ if not os.path.exists("paradrop.yaml"): raise Exception("No paradrop.yaml file found in working directory.") with open('paradrop.yaml', 'r') as source: chute = yaml.safe_load(source) name = chute_find_field(chute, 'name') source = chute_find_field(chute, 'source') config = chute.get('config', {}) chute_resolve_source(source, config) client = ControllerClient() result = client.find_chute(name) if result is None: raise Exception("Could not find ID for chute {} - is it registered?".format(name)) result = client.create_version(name, config) click.echo(util.format_result(result)) return result
Example #11
Source File: make_TestOnlineData_from_nc.py From Deep_Learning_Weather_Forecasting with Apache License 2.0 | 6 votes |
def main(raw_filepath, process_phase, interim_filepath, datetime, processed_path): """ Runs data processing scripts to turn raw data from (../raw) into cleaned data ready to be analyzed (saved in ../processed). """ logger = logging.getLogger(__name__) if process_phase == 'testA': file_name='ai_challenger_wf2018_testa1_20180829-20180924.nc' elif process_phase == 'testB': file_name='ai_challenger_weather_testingsetB_20180829-20181015.nc' elif process_phase == 'OnlineEveryDay': file_name='ai_challenger_wf2018_testb1_20180829-20181028.nc' #click.echo('Error! process_phase must be (testA, testB or OnlineEveryDay)') interim_file_name = netCDF2TheLastDay(raw_filepath+file_name, process_phase, interim_filepath, datetime) process_outlier_and_stack(interim_filepath, interim_file_name, process_phase, datetime, processed_path)
Example #12
Source File: cloud.py From Paradrop with Apache License 2.0 | 6 votes |
def login(ctx): """ Interactively login to your user account on the controller. Authenticate with the controller using account credentials that you created either through the website or with the register command. Typically, the username will be your email address. """ client = ControllerClient() token = client.login() if token is None: click.echo("Login attempt failed.") return False else: click.echo("Login successful.") return True
Example #13
Source File: node.py From Paradrop with Apache License 2.0 | 6 votes |
def watch_chute_logs(ctx, chute): """ Stream log messages from a running chute. CHUTE must be the name of a running chute. """ url = "ws://{}/sockjs/logs/{}".format(ctx.obj['target'], chute) def on_message(ws, message): data = json.loads(message) time = arrow.get(data['timestamp']).to('local').datetime msg = data['message'].rstrip() service = data.get("service", chute) click.echo("[{}] {}: {}".format(service, time, msg)) client = ctx.obj['client'] client.ws_request(url, on_message=on_message)
Example #14
Source File: node.py From Paradrop with Apache License 2.0 | 6 votes |
def generate_configuration(ctx, format): """ Generate a new node configuration based on detected hardware. The new configuration is not automatically applied. Rather, you can save it to file and use the import-configuration command to apply it. """ client = ctx.obj['client'] result = client.generate_config() format = format.lower() if format == 'json': click.echo(json.dumps(result, indent=4)) elif format == 'yaml': click.echo(yaml.safe_dump(result, default_flow_style=False)) else: click.echo("Unrecognized format: {}".format(format)) return result
Example #15
Source File: node.py From Paradrop with Apache License 2.0 | 6 votes |
def update_chute(ctx, directory): """ Install a new version of the chute from the working directory. Install the files in the current directory as a chute on the node. The directory must contain a paradrop.yaml file. The entire directory will be copied to the node for installation. """ os.chdir(directory) if not os.path.exists("paradrop.yaml"): raise Exception("No paradrop.yaml file found in chute directory.") with open('paradrop.yaml', 'r') as source: config = yaml.safe_load(source) if 'name' not in config: click.echo('Chute name is not defined in paradrop.yaml.') return client = ctx.obj['client'] with tempfile.TemporaryFile() as temp: tar = tarfile.open(fileobj=temp, mode="w") for dirName, subdirList, fileList in os.walk("."): for fname in fileList: path = os.path.join(dirName, fname) arcname = os.path.normpath(path) tar.add(path, arcname=arcname) tar.close() temp.seek(0) result = client.install_tar(temp, name=config['name']) ctx.invoke(watch_change_logs, change_id=result['change_id'])
Example #16
Source File: node.py From Paradrop with Apache License 2.0 | 6 votes |
def set_password(ctx): """ Change the local admin password. Set the password required by `pdtools node login` and the local web-based administration page. """ username = builtins.input("Username: ") while True: password = getpass.getpass("New password: ") confirm = getpass.getpass("Confirm password: ") if password == confirm: break else: print("Passwords do not match.") click.echo("Next, if prompted, you should enter the current username and password.") client = ctx.obj['client'] result = client.set_password(username, password) click.echo(util.format_result(result)) return result
Example #17
Source File: node.py From Paradrop with Apache License 2.0 | 6 votes |
def set_source_volume(ctx, source, volume): """ Configure audio source volume. SOURCE must be the name of a PulseAudio source. VOLUME should be one (applied to all channels) or multiple (one for each channel) floating point values between 0 and 1. """ client = ctx.obj['client'] # Convert to a list of floats. Be aware: the obvious approach # list(volume) behaves strangely. data = [float(vol) for vol in volume] result = client.set_source_volume(source, data) click.echo(util.format_result(result)) return result
Example #18
Source File: node.py From Paradrop with Apache License 2.0 | 6 votes |
def remove_chute_network_client(ctx, chute, network, client): """ Remove a connected client from the chute's network. CHUTE must be the name of an installed chute. NETWORK must be the name of one of the chute's configured networks. Typically, this will be "wifi". CLIENT identifies the network client, such as a MAC address. Only implemented for wireless clients, this effectively kicks the client off the network. """ pdclient = ctx.obj['client'] result = pdclient.remove_chute_client(chute, network, client) click.echo(util.format_result(result)) return result
Example #19
Source File: cli.py From tldr.py with MIT License | 6 votes |
def update(): """Update to the latest pages.""" repo_directory = get_config()['repo_directory'] os.chdir(repo_directory) click.echo("Check for updates...") local = subprocess.check_output('git rev-parse master'.split()).strip() remote = subprocess.check_output( 'git ls-remote https://github.com/tldr-pages/tldr/ HEAD'.split() ).split()[0] if local != remote: click.echo("Updating...") subprocess.check_call('git checkout master'.split()) subprocess.check_call('git pull --rebase'.split()) build_index() click.echo("Update to the latest and rebuild the index.") else: click.echo("No need for updates.")
Example #20
Source File: node.py From Paradrop with Apache License 2.0 | 6 votes |
def login(ctx): """ Interactively log in using the local admin password. Authenticate with the node using the local username and password. Typically, the username will be "paradrop". The password can be set with the set-password command. """ client = ctx.obj['client'] token = client.login() if token is None: click.echo("Login attempt failed.") return False else: click.echo("Login successful.") return True
Example #21
Source File: __main__.py From mindustry-modding with GNU General Public License v3.0 | 5 votes |
def defaults(): """ Converts Mindustry attribute decelleration into a Markdown table. """ import parser import pyperclip i = pyperclip.paste() o = parser.build_defaults_table(i) pyperclip.copy(o) click.echo(o)
Example #22
Source File: __main__.py From mindustry-modding with GNU General Public License v3.0 | 5 votes |
def msch(msch_text, old, new): """ Replaces one block with another within a schematic. """ import msch as msch_ from msch import Schematic, Schematics schems = msch_.load(msch_text) schems = Schematics(schems.width, schems.height, schems.tags, [ Schematic(new, *s[1:]) if s.name == old else s for s in schems.tiles ]) click.echo(msch_.dump(schems, True))
Example #23
Source File: cli.py From tldr.py with MIT License | 5 votes |
def find(command, on): """Find the command usage.""" output_lines = parse_man_page(command, on) click.echo(''.join(output_lines))
Example #24
Source File: cli.py From tldr.py with MIT License | 5 votes |
def init(): """Init config file.""" default_config_path = path.join( (os.environ.get('TLDR_CONFIG_DIR') or path.expanduser('~')), '.tldrrc') if path.exists(default_config_path): click.echo("There is already a config file exists, " "skip initializing it.") else: repo_path = click.prompt("Input the tldr repo path") repo_path = os.path.abspath(os.path.expanduser(repo_path)) if not path.exists(repo_path): sys.exit("Repo path not exist, clone it first.") platform = click.prompt("Input your platform(linux, osx or sunos)") if platform not in ['linux', 'osx', 'sunos']: sys.exit("Platform should be linux, osx or sunos.") colors = { "description": "blue", "usage": "green", "command": "cyan" } config = { "repo_directory": repo_path, "colors": colors, "platform": platform } with open(default_config_path, 'w') as f: f.write(yaml.safe_dump(config, default_flow_style=False)) click.echo("Initializing the config file at {0}".format( default_config_path))
Example #25
Source File: cloud.py From Paradrop with Apache License 2.0 | 5 votes |
def describe_node(ctx, name): """ Get detailed information about an existing node. NAME must be the name of a node that you own. """ client = ControllerClient() result = client.find_node(name) click.echo(util.format_result(result)) return result
Example #26
Source File: store.py From Paradrop with Apache License 2.0 | 5 votes |
def register(ctx, public): """ Register a chute with the store. The chute information including name will be taken from the paradrop.yaml file in the current working directory. If you receive an error, it may be that a chute with the same name is already registered. """ if not os.path.exists("paradrop.yaml"): raise Exception("No paradrop.yaml file found in working directory.") with open('paradrop.yaml', 'r') as source: chute = yaml.safe_load(source) name = chute_find_field(chute, 'name') description = chute_find_field(chute, 'description') click.echo("Name: {}".format(name)) click.echo("Description: {}".format(description)) click.echo("Public: {}".format(public)) click.echo("") prompt = "Ready to send this information to {} (Y/N)? ".format( ctx.obj['pdserver_url']) if click.confirm(prompt): client = ControllerClient() result = client.create_chute(name, description, public=public) click.echo(util.format_result(result)) else: click.echo("Operation cancelled.")
Example #27
Source File: store.py From Paradrop with Apache License 2.0 | 5 votes |
def help(ctx): """ Show this message and exit. """ click.echo(ctx.parent.get_help())
Example #28
Source File: node.py From Paradrop with Apache License 2.0 | 5 votes |
def provision(ctx, id, key, controller, wamp): """ Associate the node with a cloud controller. ID and KEY are credentials that can be found when creating a node on the controller, either through the website or through `pdtools cloud create-node`. They may also be referred to as the Router ID and the Router Password. """ client = ctx.obj['client'] result = client.provision(id, key, controller=controller, wamp=wamp) click.echo(util.format_result(result)) return result
Example #29
Source File: node.py From Paradrop with Apache License 2.0 | 5 votes |
def logout(ctx): """ Log out and remove stored credentials. """ client = ctx.obj['client'] removed = client.logout() click.echo("Removed {} token(s).".format(removed)) return removed
Example #30
Source File: node.py From Paradrop with Apache License 2.0 | 5 votes |
def load_audio_module(ctx, module): """ Load a module into the audio subsystem. MODULE must be the name of a PulseAudio module such as "module-loopback". """ client = ctx.obj['client'] result = client.load_audio_module(module) click.echo(util.format_result(result)) return result