Пример #1
0
def main(argv=None):
    # Parse command-line arguments.
    from docopt import docopt
    from . import version
    # Parse the initial options, the options_first flag must be True to for <ARGS> to act as a wildcard for options (- and --) as well
    args = docopt(usage, version=version.version, argv=argv, options_first=True)

    dispatched = False # Flag set to True if we have correctly dispatched a command.
    from . import commands # TODO: This would be clearer if we could do 'from yank import commands', but can't figure out how
    import inspect
    # Build the list of commands based on the <command>.py modules in the ./commands folder
    command_list = [module[0] for module in inspect.getmembers(commands, inspect.ismodule)]         

    # Handle simple arguments.
    if args['--cite']:
        dispatched = commands.cite.dispatch(args)

    # Handle commands.
    if args['COMMAND'] in command_list:
        # Check that command is valid:
        command = args['COMMAND']
        command_usage = getattr(commands, command).usage
        command_args  = docopt(command_usage, version=version.version, argv=argv) # This will terminate if command is invalid
        # Execute Command
        dispatched = getattr(commands, command).dispatch(command_args)
        
    # If unsuccessful, print usage and exit with an error.
    if not dispatched:
        print(usage)
        return True

    # Indicate success.
    return False
Пример #2
0
def main():
    args = docopt(__doc__)
    log = get_logger(args)

    auth_spec = validate_auth_spec_file(args['--spec-file'])
    org_client = boto3.client('organizations')
    validate_master_id(org_client, auth_spec)
    credentials = get_assume_role_credentials(
            auth_spec['auth_account_id'],
            auth_spec['org_access_role'])
    iam_client = boto3.client('iam', **credentials)
    deployed = dict(
            users = iam_client.list_users()['Users'],
            groups = iam_client.list_groups()['Groups'],
            accounts = scan_deployed_accounts(org_client))

    if args['report']:
        display_provisioned_users(log, deployed)
        display_provisioned_groups(credentials, log, deployed)
        display_roles_in_accounts(log, deployed, auth_spec)

    if args['users']:
        create_users(iam_client, args, log, deployed, auth_spec)
        create_groups(iam_client, args, log, deployed, auth_spec)
        manage_group_members(iam_client, args, log, deployed, auth_spec)
        manage_group_policies(credentials, args, log, deployed, auth_spec)

    if args['delegation']:
        manage_delegations(args, log, deployed, auth_spec)
Пример #3
0
def main(argv=None):
    # Parse command-line arguments.
    from docopt import docopt
    import version
    args = docopt(usage, version=version.version, argv=argv)

    dispatched = False  # Flag set to True if we have correctly dispatched a command.
    from . import commands  # TODO: This would be clearer if we could do 'from yank import commands', but can't figure out how

    # Handle simple arguments.
    if args['--help']:
        print usage
        dispatched = True
    if args['--cite']:
        dispatched = commands.cite.dispatch(args)

    # Handle commands.
    command_list = [
        'selftest', 'platforms', 'prepare', 'run', 'status', 'analyze',
        'cleanup'
    ]  # TODO: Build this list automagically by introspection of commands submodule.
    for command in command_list:
        if args[command]:
            dispatched = getattr(commands, command).dispatch(args)

    # If unsuccessful, print usage and exit with an error.
    if not dispatched:
        print usage
        return True

    # Indicate success.
    return False
Пример #4
0
def main(argv=None):
    # Parse command-line arguments.
    from docopt import docopt
    import version
    args = docopt(usage, version=version.version, argv=argv)

    dispatched = False # Flag set to True if we have correctly dispatched a command.
    from . import commands # TODO: This would be clearer if we could do 'from yank import commands', but can't figure out how

    # Handle simple arguments.
    if args['--help']:
        print usage
        dispatched = True
    if args['--cite']:
        dispatched = commands.cite.dispatch(args)

    # Handle commands.
    command_list = ['selftest', 'platforms', 'setup', 'run', 'status', 'analyze', 'cleanup'] # TODO: Build this list automagically by introspection of commands submodule.
    for command in command_list:
        if args[command]:
            dispatched = getattr(commands, command).dispatch(args)

    # If unsuccessful, print usage and exit with an error.
    if not dispatched:
        print usage
        return True

    # Indicate success.
    return False
Пример #5
0
 def tmp(argv):
    if len(argv)==1:
      argv.append('--help')
    try:
    	 args=docopt(func.__doc__,argv=argv)
    	 return func(args)
    except SystemExit as e:
    	print e
Пример #6
0
def _process_cmd_line(argv):
    """
    usage: sigpath.py [-h] -p dump [dump ...] [-n dump] [-v value [value ...]]
                  [-t {string,number}]

    Generates a list of signature paths to the data of interest

    optional arguments:
      -h, --help            show this help message and exit
      -p dump [dump ...]    list of positive memory dumps
      -n dump               negative memory dump

    value scanning:
      -v value [value ...]  memory dumps' corresponding values
      -t {string,number}    possible encodings
    """
    #    Return a 4-tuple: (positive dumps, negative dump, values, type).
    #    "argv" is a list of arguments, or "None" for "sys.argv[1:]".
    #    '''
    #    if argv is None:
    #        argv = sys.argv[1:]
    #
    #    # initializing the parser object
    #    parser = argparse.ArgumentParser(description='Generates a list of \
    #                                    signature paths to the data of interest')
    #    # defining command options
    #    parser.add_argument('-p', required=True, nargs='+', dest='pos_dumps',
    #                        metavar='dump', help='list of positive memory dumps')
    #    parser.add_argument('-n', dest='neg_dump', metavar='dump',
    #                                                help='negative memory dump')
    #    group = parser.add_argument_group('value scanning')
    #    group.add_argument('-v', nargs='+', dest='values', metavar='value',
    #                                    help="memory dumps' corresponding values")
    #    group.add_argument('-t', dest='type', choices=['string', 'number'],
    #                                                    help='possible encodings')
    #    # checking arguments
    #    args = parser.parse_args(argv)
    #    if args.values and not args.type:
    #        parser.error('Value scanning requires encoding')
    #    if args.values and len(args.pos_dumps) != len(args.values):
    #        parser.error('Different number of memory dumps and values')
    #    if len(args.pos_dumps) == 1 and not args.values:
    #        parser.error('Analysis of one memory dump requires a value')

    docopt()
Пример #7
0
Файл: gh.py Проект: ywangd/stash
 def tmp(argv):
    if len(argv)==1:
      if func.__name__ not in ['gh_list_keys']:
          argv.append('--help')
    try:
        args=docopt(func.__doc__,argv=argv)
        return func(args)
    except SystemExit as e:
        print(e)
Пример #8
0
Файл: gh.py Проект: zychen/stash
 def tmp(argv):
     if len(argv) == 1:
         if func.__name__ not in ['gh_list_keys']:
             argv.append('--help')
     try:
         args = docopt(func.__doc__, argv=argv)
         return func(args)
     except SystemExit as e:
         print(e)
Пример #9
0
def main():
   args = docopt(__doc__,version="1.0.0rc2")
   filename = args["--i"] 
  
   if "/" in filename:
     filename = filename.split("/")[-1]
     
   newFile = open(filename+".new","w")
   content = get_content(filename)
   newFile.write(content)
Пример #10
0
def main():
    args = docopt(__doc__, version='0.0.1')
    args = validate(args)

    if args['ptvsd']:
        address = ('0.0.0.0', args['ptvsd'])
        ptvsd.enable_attach(address)
        ptvsd.wait_for_attach()

    dump_text(args['dump_path'])
Пример #11
0
def main():
    arguments = docopt(__doc__)
    camera = picamera.PiCamera()
    output_dir = arguments.get('--output')
    loop_count = 0

    while True:
        c = Capture(camera=camera, output_dir=output_dir)
        c.capture_photo(loop_count)

        loop_count += 1
Пример #12
0
def main():
    arguments = docopt(__doc__)
    camera = picamera.PiCamera()
    output_dir = arguments.get('--output')
    loop_count = 0

    while True:
        c = Capture(camera=camera, output_dir=output_dir)
        c.capture_photo(loop_count)

        loop_count += 1
Пример #13
0
    def respond_to_command(self, msg: Message, arg: str):
        arg = arg or ''
        args = list(filter(None, [a.strip() for a in arg.split()]))
        try:
            arguments = docopt(self.__doc__, args)
        except DocoptExit as e:
            msg.say(e.usage, msg.thread_ts)
            return
        if arguments.get('-h') or arguments.get('--help'):
            msg.say(self.__doc__, msg.thread_ts)

        self.process_arguments(msg, arguments)
Пример #14
0
def main():
    args = docopt(__doc__)
    log = get_logger(args)
    org_client = boto3.client('organizations')
    root_id = get_root_id(org_client)
    deployed_accounts = scan_deployed_accounts(org_client)

    if args['--spec-file']:
        account_spec = validate_account_spec_file(args)
        validate_master_id(org_client, account_spec)

    if args['report']:
        display_provisioned_accounts(log, deployed_accounts)

    if args['create']:
        create_accounts(org_client, args, log, deployed_accounts, account_spec)
        unmanaged= [a
                for a in map(lambda a: a['Name'], deployed_accounts)
                if a not in map(lambda a: a['Name'], account_spec['accounts'])]
        if unmanaged:
            log.warn("Unmanaged accounts in Org: %s" % (', '.join(unmanaged)))
Пример #15
0
Файл: gh.py Проект: ywangd/stash
		raise Exception('Public Key file not found!')
	g,u=setup_gh()
	with open(args['<public_key_path>']) as pubkey:
		u.create_key(title,pubkey.read())
		
	

def setup_gh():
	keychainservice='stash.git.github.com'
	user = dict(keychain.get_services())[keychainservice]
	pw = keychain.get_password(keychainservice, user)
	g=Github(user,pw)
	u=g.get_user()
	
	return g, u

if __name__=='__main__':
	import sys
	if len(sys.argv)==1:
		sys.argv.append('--help')
		
	args=docopt(__doc__, version='0.1', options_first=True)
	cmd=args['<command>']
	argv=[cmd]+args['<args>']
	try:
		func=locals()['gh_%s'%cmd]
	except KeyError:
		print ('No such cmd')
		print (__doc__)
		raise
	func(argv)
Пример #16
0
    codec = codec_mapping.get(detected_encoding, detected_encoding)
    encoding = opts.get('encoding') or codec
    decoding = opts.get('decoding')
    if verbose:
        print('File encoding: {}'.format(encoding))
        print('File output: {}'.format(decoding))
    with open(opts.get('filepath'), 'r') as fd:
        for idx, line in enumerate(fd):
            try:
                print(line.strip().decode(encoding).encode(decoding))
            except Exception:
                print('Error on line: {} of file "{}".'.format(idx, filepath))
                try:
                    print('         line: {}.'.format(line))
                except:
                    print('         line: ***could not display line***')
                print('Entering pdb.')
                import pdb
                pdb.set_trace()


if __name__ == '__main__':
    from docopt import docopt

    def fix(k):
        return k.lstrip('-<').rstrip('>').replace('-', '_')

    opts = {fix(k): v for k, v in docopt(__doc__).items()}

    main(**opts)
Пример #17
0
#!/usr/bin/env python

"""csv_to_xlsx

Usage:
    csv_to_xlsx --format=xlsx <file>...

"""

import tablib
import docopt
import os
from docopt import docopt

if __name__ == '__main__':
    arguments = docopt(__doc__, version='csv_to_xlsx 0.1')

    
    for arg in [arg for arg in arguments['<file>'] if os.path.isfile(arg)]:
        data = tablib.Dataset()
        with open(arg,'r') as f_:
            data.csv = f_.read(-1)
            if arguments['--format'] in ('xls', 'xlsx'):
                f_ext = arguments['--format']
            else:
                f_ext = 'xlsx'

            output = eval('data' + '.' + f_ext)
        
        
            with open(arg[:-3]+f_ext,'wb') as f_out:
Пример #18
0
def main():
    arguments = docopt(__doc__)
    file_path = arguments["<file_path>"]
    with open(file_path) as json_file:
        data = json.load(json_file)
        read_data(data)
Пример #19
0
                          name will be appended with the current date with 
                          "%Y-%m-%d" format.
'''

## use docopt for command line parsing and displaying help message
try:
    import docopt
except ImportError:
    try: ## for command line showerror does not work
        showerror('Import Error','docopt package was not found on your system.\nPlease install it using the command:\
                                \n"pip install docopt"')
    except:
        print('Import errror. docopt package was not found on your system. Please install it using the command: "pip install docopt"')
from docopt import docopt
if __name__ == '__main__':
    arguments = docopt(__doc__, version='PyModMon 1.0')

## use pymodbus for the Modbus communication
try:
    from pymodbus import *
except ImportError:
    try: ## for command line showerror does not work
        showerror('Import Error','pymodbus package was not found on your system.\nPlease install it using the command:\
                                \n"pip install pymodbus"')
    except:
        print('Import errror. pymodbus package was not found on your system. Please install it using the command: "pip install pymodbus"')

## enable execution of functions on program exit    
import atexit

## enable timed execution of the data polling
Пример #20
0
  --debug              enable debugging output (stdout)
"""

import docopt

__version__ = '0.0.1'
__package__ = 'kaudit'
__status__ = 'alpha'
__license__ = 'MIT'
__author__ = u'matthew marchese'
__email__ = '*****@*****.**'
__maintainer__ = u'matthew marchese'
__contributors__ = ''
__copyright__ = '2015-2017'
__description__ = 'a cross-platform desktop screenshot boasting tool'
__url__ = 'https://github.com/digitalsurvival/kaudit'
__source__ = 'https://github.com/digitalsurvival/kaudit'

stager_version = version.get_version()

# Python 3 validator
if sys.version_info < (3, 0):
    print(__name__ + " requires Python 3.0 and up. Exiting...\n")
    sys.exit(1)

if __name__ == '__main__':
    arguments = docopt(__doc__, version=__version__)

    if arguments['--debug'] == True:
        print('Passed arguments:\n' + arguments)
Пример #21
0
    df.to_csv(save_path + '/class_stats.csv')

    # Print for each tissue
    all_tissue_mPQ = []
    all_tissue_bPQ = []
    for tissue_name in tissue_types:
        indices = [i for i, x in enumerate(types) if x == tissue_name]
        tissue_PQ = [mPQ_each_image[i] for i in indices]
        print('{} PQ: {} '.format(tissue_name, np.nanmean(tissue_PQ)))
        tissue_PQ_bin = [bPQ_each_image[i] for i in indices]
        print('{} PQ binary: {} '.format(tissue_name, np.nanmean(tissue_PQ_bin)))
        all_tissue_mPQ.append(np.nanmean(tissue_PQ))
        all_tissue_bPQ.append(np.nanmean(tissue_PQ_bin))

    # Save per-tissue metrics as a csv file
    for_dataframe = {'Tissue name': tissue_types + ['mean'],
                        'PQ': all_tissue_mPQ + [np.nanmean(all_tissue_mPQ)] , 'PQ bin': all_tissue_bPQ + [np.nanmean(all_tissue_bPQ)]}
    df = pd.DataFrame(for_dataframe, columns=['Tissue name', 'PQ', 'PQ bin'])
    df.to_csv(save_path + '/tissue_stats.csv')

    # Show overall metrics - mPQ is average PQ over the classes and the tissues, bPQ is average binary PQ over the tissues
    print('-' * 40)
    print('Average mPQ:{}'.format(np.nanmean(all_tissue_mPQ)))
    print('Average bPQ:{}'.format(np.nanmean(all_tissue_bPQ)))

#####
if __name__ == '__main__':
    args = docopt(__doc__, version='PanNuke Evaluation v1.0')
    main(args)

Пример #22
0
def main(argv=None):
    args = docopt(__doc__, argv)
    for f in files:
        text = Path(f).read_text()
        ssam(args["script"], text, echo_input=args["-n"])
"""
from docopt import docopt
import os

# from schema import Schema, And, Optional, Or, Use, SchemaError


class Sim:
    def get_options(self):
        args = docopt(__doc__)
        print(args)
        # schema = Schema(
        #     {
        #         "PARAMFILE": Use(open, error="PARAMFILE should be readable"),
        #         "SPICEDECK": os.path.isfile,
        #         object: object,
        #     }
        # )
        # try:
        #     args = schema.validate(args)
        # except SchemaError as e:
        #     exit(e)


if __name__ == "__main__":
    arguments = docopt(__doc__, version="Naval Fate 2.0")
    # print(arguments)
    # prog = Sim()
    # prog.get_options()
            *dataset: (String) Dataset folder to used
            *ckpt: (String) [Optional] Path to the ckpt file to restore
    """

    # Get Test dataset
    X_test, y_test = get_testimages(dataset)
    X_test = X_test / 255

    # Evaluate all the dataset
    loss, acc, predicted_class = model.evaluate_dataset(X_test, y_test)

    print("Accuracy = ", acc)
    print("Loss = ", loss)

    stracc = str(acc)
    strloss = str(loss)
    csvdata = testset + ',' + stracc + ',' + strloss
    return csvdata


def write_csv(data, filename):
    with open('testresults/') as folder:
        with open(folder + filename + '.csv', 'w') as f:
            for line in data:
                f.write(line)
                f.write('\n')


if __name__ == '__main__':
    arguments = docopt(__doc__)
    test_all(arguments["<dataset>"], arguments["<ckpt>"])
 def get_options(self):
     args = docopt(__doc__)
     print(args)
Пример #26
0
import docopt

usage = '''
Genome Transcriptome File Comparator

Usage:
    BAMComparison.py <genome> <transcriptome> <result>
    BAMComparison.py -h | --help
    
Arguments:
    genome  Name of file or path to file containing genome reads
    transcriptome   Name of file or path to file containing transcriptome reads
    result  Name of file or path to new file containing reads found in genome but not in transcriptome
'''

args = docopt(usage)

# Open transcriptome file for reading
transcriptome = pysam.AlignmentFile('<transcriptome>', "rb")

# Create dictionary and store all query names from transcriptome file into dictionary as keys with value 0
t_qname = {}
for x in transcriptome:
    query = x.query_name
    t_qname[query] = 0
transcriptome.close()

# Check each genome query name to verify if it is in the transcriptome; if not found, write read to output file
genome = pysam.AlignmentFile('<genome>', "rb")
result = pysam.AlignmentFile('<result>', "wb", template=genome)
for read in genome:
Пример #27
0
    plt.tight_layout()
    SaveFig("disease_comparison{0}.pdf".format(name), md)


def plot_disease(filenames, runcnt, md):
    ds0 = dataformat.disease_states(filenames[0], 21, runcnt)
    ds1 = dataformat.disease_states(filenames[1], 21, runcnt)

    disease_comparison(ds0["latclin"], ds1["latclin"], "Latent to Clinical",
                       md)
    disease_comparison(ds0["clinrec"], ds1["clinrec"], "Clinical to Recovered",
                       md)


if __name__ == "__main__":
    arguments = docopt(__doc__, version="pyfarms.plot 1.0")
    if arguments["-v"]:
        logging.basicConfig(level=logging.DEBUG)
    elif arguments["-q"]:
        logging.basicConfig(level=logging.ERROR)
    else:
        logging.basicConfig(level=logging.INFO)

    md = {"script": __file__, "arguments": str(arguments), "date": util.when()}

    if arguments["infect"]:
        plot_infect([arguments["<filename1>"], arguments["<filename2>"]], md)

    if arguments["detect"]:
        plot_detect(arguments["<filename1>"], "First Detection", 10, md)
Пример #28
0
    --audio     only list audio ports
    --midi      only list midi
    --inputs    only list inputs
    --outputs   only list outputs
    -n          make output grepeable (remove all output made for humans)
"""

from pathlib import Path

import docopt
import itertoolz
import jack
from docopt import docopt

# Parse args
args = docopt(__doc__.format(self_filename=Path(__file__).name))

# Main loop
client = jack.Client('')
ports_list = client.get_ports()

# Filter
# TODO: use get_ports() function
filter_str = None  # Used for display
if args["--audio"]:
    ports_list = filter(lambda p: p.is_audio, ports_list)
    filter_str = "AUDIO"
if args["--midi"]:
    ports_list = filter(lambda p: p.is_midi, ports_list)
    filter_str = "MIDI"
if args["--inputs"]:
Пример #29
0
def main():
    arguments = docopt(shell_command_pbs.__doc__)
    shell_command_pbs(arguments)
Пример #30
0
MLNM-ONE

Usage:
    mlnmone (<game>...|<map>) [--debug|--editor] [-w -c -v]

Options:
    --debug  Enter the editor in debug mode
    --editor Use the editor instead of playing a game
    -w       Windowed, don't play the game in fullscreen
    -c       Console, open the Python console when ` is pressed
    -v       Display current version and copyright notice
'''

#Arguments check
if __name__ == '__main__':
    args = docopt(__doc__)

if args['-v']:
    print('''
MLNM-ONE Alpha
Copyright (c) 2013, Unincorporated Media

  MLNM-ONE is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  MLNM-ONE is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
Пример #31
0

def main(argv=None):

    argv = sys.argv

    path = os.path.abspath(os.path.dirname(__file__))

    if len(argv) == 1 or argv[1] == "--help" or argv[1] == "-h":
        print(globals()["__doc__"])

        return

    command = argv[1]

    (file, pathname, description) = imp.find_module(command, [
        path,
    ])
    module = imp.load_module(command, file, pathname, description)
    # remove 'umi-tools' from sys.argv


#    del sys.argv[0]
#    module.main(sys.argv)

# Finish and exit with docopt arguments:
if __name__ == '__main__':
    arguments = docopt(__doc__, version='xxx 0.1')
    print(arguments)
    sys.exit(main())
Пример #32
0
    kmf.fit(times1, P1, label="NAADSM")
    kmf.plot(ax=ax)
    plt.tight_layout()
    SaveFig("disease_comparison{0}.pdf".format(name), md)


def plot_disease(filenames, runcnt, md):
    ds0=dataformat.disease_states(filenames[0], 21, runcnt)
    ds1=dataformat.disease_states(filenames[1], 21, runcnt)

    disease_comparison(ds0["latclin"], ds1["latclin"], "Latent to Clinical", md)
    disease_comparison(ds0["clinrec"], ds1["clinrec"], "Clinical to Recovered", md)


if __name__ == "__main__":
    arguments = docopt(__doc__, version="pyfarms.plot 1.0")
    if arguments["-v"]:
        logging.basicConfig(level=logging.DEBUG)
    elif arguments["-q"]:
        logging.basicConfig(level=logging.ERROR)
    else:
        logging.basicConfig(level=logging.INFO)

    md={
        "script" : __file__, "arguments" : str(arguments),
        "date" : util.when()
    }

    if arguments["infect"]:
        plot_infect([arguments["<filename1>"], arguments["<filename2>"]], md)
Пример #33
0
def evolRate(tree):
    """Function that returns evol rate for a dendropy.Tree object."""
    tree_length = tree.length()
    numberOfTaxa = len(tree.leaf_nodes())
    return(tree_length/numberOfTaxa)


def main(infiles, outfile, reverse=False):
    """Goes through each tree and calculates its evolutionary rate, sorts trees
    by rate and outputs a table of trees and ratesself."""
    ratesDict = {}

    # Read all tree rates
    for infile in infiles:
        with open(infile) as tfh:
            myTree = dendropy.Tree.get(file=tfh, schema="newick")
        ratesDict[infile] = evolRate(myTree)

    ratesList = sorted(ratesDict.items(), key=lambda x: x[1], reverse=reverse)

    with open(outfile, "w") as outf:
        # Old file will be overwritten if it exists
        for aln, rate in ratesList:
            print(aln, rate, sep='\t', file=outf)


if __name__ == "__main__":
    from docopt import docopt
    opts = docopt(CLI)
    main(opts['<trees>'], opts['-o'], opts['-r'])
Пример #34
0
#!/usr/bin/env python3
# (c) B. Kerler 2017-2020, licensed under MIT license
"""
Usage:
    ozipdecrypt.py --help
    ozipdecrypt.py <filename>

Options:
    Mode 1 for regular ozip, Mode 2 for CPH1803/CPH1909 [default: 1]
"""

from docopt import *
args = docopt(__doc__, version='1.2')


import os
import sys, stat
import shutil
import binascii
from Crypto.Cipher import AES
from zipfile import ZipFile

keys = [
    "D6EECF0AE5ACD4E0E9FE522DE7CE381E",  # mnkey
    "D6ECCF0AE5ACD4E0E92E522DE7C1381E",  # mkey
    "D6DCCF0AD5ACD4E0292E522DB7C1381E",  # realkey, R9s CPH1607 MSM8953, Plus, R11, RMX1921 Realme XT, RMX1851EX Realme Android 10, RMX1992EX_11_OTA_1050
    "D7DCCE1AD4AFDCE2393E5161CBDC4321",  # testkey
    "D7DBCE2AD4ADDCE1393E5521CBDC4321",  # utilkey
    "D7DBCE1AD4AFDCE1393E5121CBDC4321",  # R11s CPH1719 MSM8976, Plus
    "D4D2CD61D4AFDCE13B5E01221BD14D20",  # FindX CPH1871 SDM845
    "261CC7131D7C1481294E532DB752381E",  # FindX
Пример #35
0
        if channel_frequencies[i] == 0:
            counter_value = 62071
        else:
            counter_value = frequency_to_counter(channel_frequencies[i])

        print("Setting channel %d counter to %d" % (i, counter_value))
        CTR_8254ModeLoad(indices[0], i, 1, 2, counter_value)
        CTR_8254ModeLoad(indices[0], i, 2, 3, counter_value)

    if args["--rapiddisplay"] or args["-D"]:
        counts = ushortarray(15)
        count = 0
        print("Printing out counters")
        while count < 100000:
            CTR_8254ReadAll(indices[0], counts.cast())
            print(
                "\r%5.5hu,%5.5hu,%5.5hu   %5.5hu,%5.5hu,%5.5hu   %5.5hu,%5.5hu,%5.5hu   %5.5hu,%5.5hu,%5.5hu    %5.5hu,%5.5hu,%5.5hu"
                % (counts[0], counts[1], counts[2], counts[3], counts[4],
                   counts[5], counts[6], counts[7], counts[8], counts[9],
                   counts[10], counts[11], counts[12], counts[13], counts[14]),
                end="")
            count += 1
        print("")


if __name__ == "__main__":

    from docopt import *
    arguments = docopt(usage)
    main(arguments)
Пример #36
0
Usage:
    s3-file-upload.py <bucket> <filename>

Options:
    -h --help     Show this screen.
"""

from boto.s3.connection import S3Connection
from boto.s3.key import Key

import docopt

def s3_upload_from_file(bucket, filename):
    conn = S3Connection()

    bucket = conn.get_bucket(bucket)

    k = Key(bucket)
    k.key = filename

    print 'Uplaading %s to bucket %s' % (filename, bucket)
    return k.set_contents_from_filename(filename)

if __name__ == '__main__':
    from docopt import docopt
    arguments = docopt(__doc__, version='s3-file-upload.py 0.1')
    bucket = arguments['<bucket>']
    filename = arguments['<filename>']
    print s3_upload_from_file(bucket, filename)

Пример #37
0
'''
Usage:
    deploy_at_sims_batch.py <data_dir>
                            [rec_list=<rl>]
    deploy_at_sims_batch.py -h | --help

Options:
    -h --help               Show this documentation
'''

import docopt
import os
import glob

import pdb


def main(args):

    header_files = [
        x for x in os.listdir(data_dir) if os.path.splitext(x)[1] == '.hea'
    ]

    # loop all header files
    for hf in header_files:
        pdb.set_trace()


if __name__ == "__main__":
    main(docopt(__doc__))
def main():
    '''"Usage: songkickscraper.py [options]

    Options:
    -h --help      Show this
    -d <path>      The full path to the directory containing folders named after artists you want to track
    -u <username>  Your SongKick username
    -p <password>  Your SongKick password
    -f <file>      A file with a list of artists to track, one per line.
    -o <file>      The file to contain the results of the operation. [default: results.txt]

    '''

    # option parsing
    options, arguments = docopt(main.__doc__, help=True)

    if not options.u:
        print 'Please provide a SongKick username using -u'
        exit()
    if not options.p:
        print "Please provide a SongKick password using -p (this is not stored anywhere)"
        exit()
    if not options.d and not options.f:
        print 'Please provide a source of artists\n ' \
              'either a file (one per line) with the -f option\n ' \
              'or a directory containing artists folders with the -d option'
        exit()


    # Browser
    br = mechanize.Browser()



    # Cookie Jar
    cj = cookielib.LWPCookieJar()
    br.set_cookiejar(cj)

    # Browser options
    br.set_handle_equiv(True)
    br.set_handle_redirect(True)
    br.set_handle_referer(True)
    br.set_handle_robots(False)

    # To not get blocked
    br.addheaders = [('User-agent',
                      'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]

    br.open('http://www.songkick.com/session/new')

    # This is the login form
    br.select_form(nr=1)

    br.form['username_or_email'] = options.u
    br.form['password'] = options.p
    br.find_control(name="persist").value = ["y"]
    br.submit()

    # error checking
    if 'Sorry, that username or password is incorrect' in br.response().read():
        print 'Sorry, that username or password is incorrect'
        exit()

    # Get all of the users so far tracked artists
    trackedArtistsByNumber = set()
    trackedArtistsByName = set()
    morePages = True
    i = 1

    # so that we run off the end of the artist pages
    br.set_handle_redirect(False)
    print 'Getting currently tracked artists. This may take a while if you have many...\n'

    while morePages:
        try:
            br.open('http://www.songkick.com/tracker/artists?page=' + str(i))
        except mechanize.HTTPError:
            morePages = False
        soup = BeautifulSoup.BeautifulSoup(br.response().read())

        # find the artist link
        links = soup.findAll(attrs={'href': BeautifulSoup.re.compile('/artists/*[^?]')})
        for link in links:
            # find the unique artist number
            trackedArtistsByNumber.add(BeautifulSoup.re.findall(r'/artists/([0-9]+)*[^?]', link.attrMap['href'])[0])
            #find the artists name
            trackedArtistsByName.add(link.text)
        i += 1

        # display progress to user
        sys.stdout.write('\rFound ' + str(len(trackedArtistsByNumber)) + ' artists so far')
        sys.stdout.flush()

        if trackedArtistsByNumber.issubset(set()):
            morePages = False

    # get the artists to track, if there was a previously tracked directory, just get the new artists.
    artistsToGet = []
    try:
        unp = pickle.Unpickler(open('.tracked'))
        prevArtistsDict = unp.load()
    except:
        prevArtistsDict = {}

    if options.d:
        artistsToGet = set([unicode(name) for name in os.listdir(options.d)])
        placeToLoadFrom = options.d
    else:
        artistsToGet = set([unicode(line[:-2]) for line in open(options.f).readlines()])
        placeToLoadFrom = options.f

    if prevArtistsDict.has_key(placeToLoadFrom):
        artistsToGet = artistsToGet - prevArtistsDict[placeToLoadFrom]
        prevArtistsDict[placeToLoadFrom] = artistsToGet.union(prevArtistsDict[placeToLoadFrom])
    else:
        prevArtistsDict[placeToLoadFrom] = artistsToGet

    # hopefully remove all the artists that have been just found on the users
    artistsToGet = artistsToGet - trackedArtistsByName



    print '\n\nNow tracking artists\n'

    # track the artists the user gives us

    unfoundArtists = []
    sucessArtists = []
    alreadyTrackedArtists = []
    br.set_handle_redirect(True)
    try:
        for i, artist in enumerate(artistsToGet):
            sys.stdout.write('\rTracking '+ str(i+1) + ' of ' + str(len(artistsToGet)))
            sys.stdout.flush()
            # search for artist
            br.open('http://www.songkick.com/search?query=' + '+'.join(artist.split()))
            soup = BeautifulSoup.BeautifulSoup(br.response().read())

            # if there is no artist by that name
            if soup.findAll(attrs={'href': BeautifulSoup.re.compile('/artists/*[^?]')}) == []:
                unfoundArtists.append(artist)
            else:

                # take the first artists result
                link = soup.findAll(attrs={'href': BeautifulSoup.re.compile('/artists/*[^?]')})[1]

                # check that the user is not already following this artist
                if not BeautifulSoup.re.findall(r'/artists/([0-9]+)*[^?]', link.attrMap['href'])[0] in trackedArtistsByNumber:
                    br.open('http://www.songkick.com/search?query=' + '+'.join(artist.split()))
                    br.select_form(nr=2)
                    br.submit()
                    sucessArtists.append(link.text)
                else:
                    alreadyTrackedArtists.append(link.text)
    except:
        print '\nsomething went wrong, but what did get done is written out to', options.o

    # save the artist that were tracked so next time they wont be tracked again.
    p = pickle.Pickler(open('.tracked', 'w'))

    # if in directory mode dump dir records
    if options.d:
        p.dump(prevArtistsDict)

    # write out the results
    results = open(options.o, 'w')
    results.write('Artists that were successfully tracked:\n')
    for artist in sucessArtists:
        results.write(artist + '\n')

    results.write('\nArtists that could not be found on SongKick:\n')
    for artist in unfoundArtists:
        results.write(artist + '\n')

    results.write('\nArtists we tried to track but were already tracked:\n')
    for artist in alreadyTrackedArtists:
        results.write(artist + '\n')

    print '\n\nDone, results written to', options.o
Пример #39
0
        
    for i in range(0,5):
        if channel_frequencies[i] == 0:
            counter_value = 62071
        else:
            counter_value = frequency_to_counter( channel_frequencies[i] )

        print("Setting channel %d counter to %d" % (i , counter_value ))
        CTR_8254ModeLoad( indices[0], i, 1, 2, counter_value )
        CTR_8254ModeLoad( indices[0], i, 2, 3, counter_value )

    if args["--rapiddisplay"] or args["-D"]:
        counts = ushortarray(15)
        count = 0
        print("Printing out counters")
        while count < 100000:
            CTR_8254ReadAll( indices[0] , counts.cast() );
            print("\r%5.5hu,%5.5hu,%5.5hu   %5.5hu,%5.5hu,%5.5hu   %5.5hu,%5.5hu,%5.5hu   %5.5hu,%5.5hu,%5.5hu    %5.5hu,%5.5hu,%5.5hu" % (counts[0], counts[1], counts[2], counts[3], counts[4], counts[5], counts[6], counts[7], counts[8], counts[9], counts[10], counts[11], counts[12], counts[13], counts[14] ), end="")
            count += 1
        print("")
        
   

if __name__ == "__main__":
    

    from docopt import *
    arguments = docopt(usage )
    main(arguments)

Пример #40
0
Файл: gh.py Проект: zychen/stash
        raise Exception('Public Key file not found!')
    g, u = setup_gh()
    with open(args['<public_key_path>']) as pubkey:
        u.create_key(title, pubkey.read())


def setup_gh():
    keychainservice = 'stash.git.github.com'
    user = dict(keychain.get_services())[keychainservice]
    pw = keychain.get_password(keychainservice, user)
    g = Github(user, pw)
    u = g.get_user()

    return g, u


if __name__ == '__main__':
    import sys
    if len(sys.argv) == 1:
        sys.argv.append('--help')

    args = docopt(__doc__, version='0.1', options_first=True)
    cmd = args['<command>']
    argv = [cmd] + args['<args>']
    try:
        func = locals()['gh_%s' % cmd]
    except KeyError:
        print('No such cmd')
        print(__doc__)
        raise
    func(argv)