How to use the plumbum.cli function in plumbum

To help you get started, we’ve selected a few plumbum examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tomerfiliba / plumbum / build.py View on Github external
#!/usr/bin/env python
from plumbum import local, cli, FG
from plumbum.path.utils import delete

try:
    from plumbum.cmd import twine
except ImportError:
    twine = None

class BuildProject(cli.Application):
    'Build and optionally upload. For help, see https://packaging.python.org/en/latest/distributing/#uploading-your-project-to-pypi'
    upload = cli.Flag("upload", help = "If given, the artifacts will be uploaded to PyPI")

    def main(self):
        delete(local.cwd // "*.egg-info", "build", "dist")

        local.python("setup.py", "sdist", "bdist_wheel")

        delete(local.cwd // "*.egg-info", "build")

        if self.upload:
            if twine is None:
                print("Twine not installed, cannot securely upload. Install twine.")
            else:
                twine['upload', 'dist/*tar.gz', 'dist/*.whl'] & FG
        else:
            print("Built. To upload, run:")
            print("  twine upload dist/*tar.gz dist/*.whl")
github ASMfreaK / habitipy / habitipy / cli.py View on Github external
if config['show_style'] not in CHECK_MARK_STYLES:
            config['show_style'] = 'wide'
    return config


class ConfiguredApplication(cli.Application):
    """Application with config"""
    config_filename = cli.SwitchAttr(
        ['-c', '--config'], argtype=local.path, default=DEFAULT_CONF,
        argname='CONFIG',
        help=_("Use file CONFIG for config"))  # noqa: Q000
    verbose = cli.Flag(
        ['-v', '--verbose'],
        help=_("Verbose output - log everything."),  # noqa: Q000
        excludes=['-s', '--silent'])
    silence_level = cli.CountOf(
        ['-s', '--silent'],
        help=_("Make program more silent"),  # noqa: Q000
        excludes=['-v', '--verbose'])

    def main(self):
        self.config = load_conf(self.config_filename)
        self.log = logging.getLogger(str(self.__class__).split("'")[1])
        self.log.addHandler(logging.StreamHandler())
        if self.verbose:
            self.log.setLevel(logging.DEBUG)
        else:
            base_level = logging.INFO
            self.log.setLevel(base_level + 10 * self.silence_level)


class Content(Mapping):
github GooFit / GooFit / examples / RunAll.py View on Github external
test('chisquare'),
            ]

    if (LOCAL_DIR / 'zachFit/dataFiles/dstwidth_kpi_data.dat').exists():
        results.append(test('zachFit', 1, 0))
    if (LOCAL_DIR / 'pipipi0DPFit/dataFiles/toyPipipi0/dalitz_toyMC_000.txt').exists():
        results.append(test('pipipi0DPFit', 'toy', 0, 1))
        if(profile):
            results.append(test('pipipi0DPFit', 'canonical', 'dataFiles/cocktail_pp_0.txt', '--blindSeed=0'))
    return results


MIN_TIME = re.compile(r'The minimization took: (.*?)$', re.MULTILINE)

class RunAll(cli.Application):
    profile = cli.Flag(["-p", "--profile"], help = "Profile (longer) output")

    @cli.positional(int)
    def main(self, threads=None):
        env = local.env(OMP_NUM_THREADS=threads) if threads else local.env()
        with env:
            results = make_results(self.profile)
        failed = [result for result in results if result['code'] != 0]
        successes = [result for result in results if result['code'] == 0]

        if failed:
            colors.fatal.print("Failed:")
            for result in failed:
                colors.fatal.print(result['name'], result['code'])
        else:
            colors.success.print("All programs completed.")
github GooFit / GooFit / scripts / UpdateCLI.py View on Github external
from __future__ import print_function, division

from plumbum import local, cli, FG
from plumbum.cmd import curl

FILES = [
        'https://github.com/henryiii/CLI11/releases/download/v0.6/CLI11.hpp',
]

DIR = local.path(__file__).dirname

def download_file(path):
    name = path.split('/')[-1]
    (curl['-L',path] > name) & FG

class UpdateCLI(cli.Application):
    def main(self):
        with local.cwd(DIR / '../include/goofit/detail'):
            for f in FILES:
                download_file(f)

if __name__ == "__main__":
    UpdateCLI()
github da-x / git-search-replace / bin / gsr-branch.py View on Github external
# 'git commit -F' doesn't actually ignore the '#' lines, so we remove them ourselves
    lines = [l for l in open(commit_msg_file, "r").readlines() if not l.startswith('#')]
    with open(commit_msg_file, "w") as f:
        f.write('\n'.join(lines))
    return commit_msg_file

class MyApp(cli.Application):
    MODE_INSERT = 'insert'
    MODE_EDIT = 'edit'

    git_editor = git("var", "GIT_EDITOR").strip()
    force_filter_branch = cli.Flag(["-f", "--force"], help = "Pass -f to git-filter-branch")
    internal_edit_todo = cli.Flag(["-i", "--internal-edit-todo"], requires = ["-t"],
                                  help = "Edit the git-rebase todo file. FOR INTERNAL USE ONLY")
    rebase_todo_filename = cli.SwitchAttr(["-t", "--internal-todo-filename"], requires = ["-i"],
                                          argtype = cli.ExistingFile, argname = "",
                                          help = "Full path of the git-rebase todo file. FOR INTERNAL USE ONLY")
    gsr_cmd = cli.SwitchAttr(["-g", "--gsr-cmd"], argtype = str, argname = "",
                             default = os.path.dirname(sys.argv[0]) + "/git-search-replace.py",
                             help = "Path to git-search-replace.py")
    commit_msg = cli.SwitchAttr(["-c", "--commit-msg"], argtype = str, argname = "",
                                excludes = ["-F"],
                                help = "Provide the git log message for insert mode")
    commit_msg_file = cli.SwitchAttr(["-F", "--commit-msg-file"],
                                     argtype = cli.ExistingFile, argname = "",
                                     excludes = ["-c"],
                                     help = "Provide the git log message for insert mode (as filename)")
    mode = cli.SwitchAttr(["-m", "--mode"], argtype = cli.Set(MODE_INSERT, MODE_EDIT), argname = "mode",
                          default = MODE_EDIT,
                          help = '''Whether to insert a new commit at base, or edit the base commit.
                                    Use insert when renaming something that's already in upstream,
                                    and edit when renaming something that was only added in the current branch.''')
github tomerfiliba / rpyc / bin / rpyc_registry.py View on Github external
#!/usr/bin/env python
"""
The registry server listens to broadcasts on UDP port 18812, answering to
discovery queries by clients and registering keepalives from all running
servers. In order for clients to use discovery, a registry service must
be running somewhere on their local network.
"""
from plumbum import cli
from rpyc.utils.registry import REGISTRY_PORT, DEFAULT_PRUNING_TIMEOUT
from rpyc.utils.registry import UDPRegistryServer, TCPRegistryServer
from rpyc.lib import setup_logger


class RegistryServer(cli.Application):
    mode = cli.SwitchAttr(["-m", "--mode"], cli.Set("UDP", "TCP"), default="UDP",
                          help="Serving mode")

    ipv6 = cli.Flag(["-6", "--ipv6"], help="use ipv6 instead of ipv4")

    port = cli.SwitchAttr(["-p", "--port"], cli.Range(0, 65535), default=REGISTRY_PORT,
                          help="The UDP/TCP listener port")

    logfile = cli.SwitchAttr(["--logfile"], str, default=None,
                             help="The log file to use; the default is stderr")

    quiet = cli.SwitchAttr(["-q", "--quiet"], help="Quiet mode (only errors are logged)")

    pruning_timeout = cli.SwitchAttr(["-t", "--timeout"], int,
                                     default=DEFAULT_PRUNING_TIMEOUT, help="Set a custom pruning timeout (in seconds)")
github tomerfiliba / plumbum / examples / simple_cli.py View on Github external
$ python simple_cli.py -v -Ifoo/bar -Ispam/eggs
Verbose: True
Include dirs: ['foo/bar', 'spam/eggs']
Compiling: ()

$ python simple_cli.py -v -I foo/bar -Ispam/eggs x.cpp y.cpp z.cpp
Verbose: True
Include dirs: ['foo/bar', 'spam/eggs']
Compiling: ('x.cpp', 'y.cpp', 'z.cpp')
"""
from __future__ import print_function
import logging
from plumbum import cli


class MyCompiler(cli.Application):
    verbose = cli.Flag(["-v", "--verbose"], help = "Enable verbose mode")
    include_dirs = cli.SwitchAttr("-I", list = True, help = "Specify include directories")

    @cli.switch("-loglevel", int)
    def set_log_level(self, level):
        """Sets the log-level of the logger"""
        logging.root.setLevel(level)

    def main(self, *srcfiles):
        print("Verbose:", self.verbose)
        print("Include dirs:", self.include_dirs)
        print("Compiling:", srcfiles)


if __name__ == "__main__":
    MyCompiler()
github changyuheng / winwifi.py / src / winwifi / __main__.py View on Github external
    @plumbum.cli.switch(['--oneshot'], help='Do not remember the connection')
    def one_shot(self):
        self._one_shot = True
github crowdrec / idomaar / datastreammanager / orchestrator / main / orchestrator_cli.py View on Github external
import json
import logging
import os
import colorlog
from plumbum import cli
import sys
from local_executor import LocalExecutor
from orchestrator import Orchestrator
from vagrant_executor import VagrantExecutor
from urlparse import urlparse

logger = logging.getLogger("orchestrator")

class OrchestratorCli(cli.Application):

    PROGNAME = "orchestrator"
    VERSION = "0.0.1"

    host_orchestrator = cli.Flag(["--host-orchestrator"], help = "If given, the orchestrator assumes to be running on the host OS, and execute all datastream commands via vagrant."+
        " The default assumption is that the orchestrator is running on the same (virtual) box as the datastream components (hence doesn't have to go via vagrant)." )

    new_topic = cli.Flag(["--new-topic"], help = "If given, new Kafka topics will be created for data and recommendations feeds.", excludes = ['--data-topic', '--recommendations-topic'] )
    
    skip_training_cycle = cli.Flag(["--skip-training"], help = "If given, the training phase in the orchestrator lifecycle is skipped.")
    
    no_control_messages = cli.Flag(["--no-control-messages", '-n'], help = "If given, the orchestrator won't send control messages to the computing environment.")
    
    comp_env = None
    data_source = None
    recommendation_target = 'fs:/tmp/recommendations'