Python config.CONFIG Examples

The following are 30 code examples of config.CONFIG(). 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 config , or try the search function .
Example #1
Source File: exodus_download.py    From exodus-standalone with GNU Affero General Public License v3.0 6 votes vote down vote up
def main():
    if len(sys.argv) != 3:
        print('Usage:')
        print('python exodus_download.py <report id> <destination folder>')
        sys.exit(1)

    uri = '/api/report/{}/'.format(sys.argv[1])
    destination = sys.argv[2]

    try:
        ec = ExodusConnector(config.CONFIG['host'], uri)
        ec.login(config.CONFIG['username'], config.CONFIG['password'])
        print('Successfully logged in')
        ec.get_report_info()
        print('Downloading the APK ...')
        apk_path = ec.download_apk(destination)
        print('APK successfully downloaded: {}'.format(apk_path))
    except Exception as e:
        print('ERROR: {}'.format(e))
        sys.exit(1) 
Example #2
Source File: fetch.py    From cheat.sh with MIT License 6 votes vote down vote up
def main(args):
    """
    function for the initial repositories fetch and manual repositories updates
    """

    if not args:
        _show_usage()
        sys.exit(0)

    logging.basicConfig(
        filename=CONFIG["path.log.fetch"],
        level=logging.DEBUG,
        format='%(asctime)s %(message)s')

    if args[0] == 'fetch-all':
        fetch_all()
    elif args[0] == 'update':
        update_by_name(sys.argv[1])
    elif args[0] == 'update-all':
        update_all()
    else:
        _show_usage()
        sys.exit(0) 
Example #3
Source File: routing.py    From cheat.sh with MIT License 6 votes vote down vote up
def get_topic_type(self, topic):
        """
        Return topic type for `topic` or "unknown" if topic can't be determined.
        """

        def __get_topic_type(topic):
            for regexp, route in self.routing_table:
                if re.search(regexp, topic):
                    if route in self._adapter:
                        if self._adapter[route].is_found(topic):
                            return route
                    else:
                        return route
            return CONFIG["routing.default"]

        if topic not in self._cached_topic_type:
            self._cached_topic_type[topic] = __get_topic_type(topic)
        return self._cached_topic_type[topic] 
Example #4
Source File: messenger.py    From Briefly with MIT License 6 votes vote down vote up
def send_generic(recipient):
    page.send(recipient, Template.Generic([
        Template.GenericElement("rift",
                                subtitle="Next-generation virtual reality",
                                item_url="https://www.oculus.com/en-us/rift/",
                                image_url=CONFIG['SERVER_URL'] + "/assets/rift.png",
                                buttons=[
                                    Template.ButtonWeb("Open Web URL", "https://www.oculus.com/en-us/rift/"),
                                    Template.ButtonPostBack("tigger Postback", "DEVELOPED_DEFINED_PAYLOAD"),
                                    Template.ButtonPhoneNumber("Call Phone Number", "+16505551234")
                                ]),
        Template.GenericElement("touch",
                                subtitle="Your Hands, Now in VR",
                                item_url="https://www.oculus.com/en-us/touch/",
                                image_url=CONFIG['SERVER_URL'] + "/assets/touch.png",
                                buttons=[
                                    {'type': 'web_url', 'title': 'Open Web URL',
                                     'value': 'https://www.oculus.com/en-us/rift/'},
                                    {'type': 'postback', 'title': 'tigger Postback',
                                     'value': 'DEVELOPED_DEFINED_PAYLOAD'},
                                    {'type': 'phone_number', 'title': 'Call Phone Number', 'value': '+16505551234'},
                                ])
    ])) 
Example #5
Source File: app.py    From Pix2Depth with GNU General Public License v3.0 6 votes vote down vote up
def main():
    if request.method == 'POST':
        file = request.files['image']
        model_name = request.form['model']
        model =  CONFIG['pix2depth'][model_name]
        input_path = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
        file.save(input_path)
        if not development:
            result_path = pix2depth(input_path,model)
        else:
            result_path = str(input_path)
        img_left = str(input_path)
        img_right = str(result_path)
    else:
        img_left = os.path.join(app.config['UPLOAD_FOLDER'], 'pix.jpg')
        img_right = os.path.join(app.config['UPLOAD_FOLDER'], 'depth.jpg')
        
    return render_template('client/index.html',image_left=img_left,image_right=img_right,options = CONFIG['pix2depth']) 
Example #6
Source File: collector.py    From lakh-pianoroll-dataset with MIT License 6 votes vote down vote up
def main():
    """Main function."""
    src, dst, id_list_path = parse_args()
    make_sure_path_exists(dst)

    with open(id_list_path) as f:
        id_list = [line.split() for line in f]

    if CONFIG['multicore'] > 1:
        joblib.Parallel(n_jobs=CONFIG['multicore'], verbose=5)(
            joblib.delayed(collector)(midi_md5, msd_id, src, dst)
            for midi_md5, msd_id in id_list)
    else:
        for midi_md5, msd_id in id_list:
            collector(midi_md5, msd_id, src, dst)

    print("Subset successfully collected for: {}".format(id_list_path)) 
Example #7
Source File: converter.py    From lakh-pianoroll-dataset with MIT License 6 votes vote down vote up
def main():
    """Main function."""
    src, dst, midi_info_path = parse_args()
    make_sure_path_exists(dst)
    midi_info = {}

    if CONFIG['multicore'] > 1:
        kv_pairs = joblib.Parallel(n_jobs=CONFIG['multicore'], verbose=5)(
            joblib.delayed(converter)(midi_path, src, dst)
            for midi_path in findall_endswith('.mid', src))
        for kv_pair in kv_pairs:
            if kv_pair is not None:
                midi_info[kv_pair[0]] = kv_pair[1]
    else:
        for midi_path in findall_endswith('.mid', src):
            kv_pair = converter(midi_path, src, dst)
            if kv_pair is not None:
                midi_info[kv_pair[0]] = kv_pair[1]

    if midi_info_path is not None:
        with open(midi_info_path, 'w') as f:
            json.dump(midi_info, f)

    print("{} files have been successfully converted".format(len(midi_info))) 
Example #8
Source File: converter.py    From lakh-pianoroll-dataset with MIT License 6 votes vote down vote up
def converter(filepath, src, dst):
    """Convert a MIDI file to a multi-track piano-roll and save the
    resulting multi-track piano-roll to the destination directory. Return a
    tuple of `midi_md5` and useful information extracted from the MIDI file.
    """
    try:
        midi_md5 = os.path.splitext(os.path.basename(filepath))[0]
        multitrack = Multitrack(beat_resolution=CONFIG['beat_resolution'],
                                name=midi_md5)

        pm = pretty_midi.PrettyMIDI(filepath)
        multitrack.parse_pretty_midi(pm)
        midi_info = get_midi_info(pm)

        result_dir = change_prefix(os.path.dirname(filepath), src, dst)
        make_sure_path_exists(result_dir)
        multitrack.save(os.path.join(result_dir, midi_md5 + '.npz'))

        return (midi_md5, midi_info)

    except:
        return None 
Example #9
Source File: app.py    From Pix2Depth with GNU General Public License v3.0 6 votes vote down vote up
def depth():
    if request.method == 'POST':
        file = request.files['image']
        model_name = request.form['model']
        model = CONFIG['depth2pix'][model_name]
        input_path = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
        file.save(input_path)
        if not development:
            result_path = depth2pix(input_path,model)
        else:
            result_path = str(input_path)
        img_left = str(input_path)
        img_right = str(result_path)
    else:
        img_left = os.path.join(app.config['UPLOAD_FOLDER'], 'depth.jpg')
        img_right = os.path.join(app.config['UPLOAD_FOLDER'], 'pix.jpg')
        
    return render_template('client/depth.html',image_left=img_left,image_right=img_right,options = CONFIG['depth2pix']) 
Example #10
Source File: app.py    From Pix2Depth with GNU General Public License v3.0 6 votes vote down vote up
def portrait():
    if request.method == 'POST':
        file = request.files['image']
        model_name = request.form['model']
        model = CONFIG['portrait'][model_name]
        input_path= os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
        file.save(input_path)
        # Perform depth conversion
        if not development:
            result_path = portrait_mode(input_path, model)
        else:
            result_path = str(input_path)
        img_left = str(input_path)
        img_right = str(result_path)
    else:
        img_left = os.path.join(app.config['UPLOAD_FOLDER'], 'pix.jpg')
        img_right = os.path.join(app.config['UPLOAD_FOLDER'], 'pix.jpg')
        
    return render_template('client/potrait.html',image_left=img_left,image_right=img_right,options = CONFIG['portrait']) 
Example #11
Source File: model.py    From mlapp with MIT License 5 votes vote down vote up
def load():

    path = Path('.')
    global model
    global learn
    global classes
    model = CONFIG['model_name']
    # Check if we need to download Model file
    if CONFIG[model]['url'] != "":
        try:
            logging.info(f"Downloading model file from: {CONFIG[model]['url']}")
            urllib.request.urlretrieve(CONFIG[model]['url'], f"models/{model}.pth")
            logging.info(f"Downloaded model file and stored at path: models/{model}.pth")
        except HTTPError as e:
            logging.critical(f"Failed in downloading file from: {CONFIG[model]['url']}, Exception: '{e}'")
            sys.exit(4)

    init_data = ImageDataBunch.single_from_classes(
                                    path, CONFIG[model]['classes'], tfms=get_transforms(),
                                    size=CONFIG[model]['size']
                                ).normalize(imagenet_stats)
    classes = CONFIG[model]['classes']
    logging.info(f"Loading model: {CONFIG['model_name']}, architecture: {CONFIG[model]['arch']}, file: models/{model}.pth")
    learn = create_cnn(init_data, eval(f"models.{CONFIG[model]['arch']}"))
    learn.load(model, device=CONFIG[model]['device'])

    # Create direcotry to get feedback for this model
    Path.mkdir(Path(path_to(FEEDBACK_DIR, model)), parents=True, exist_ok=True) 
Example #12
Source File: app.py    From mlapp with MIT License 5 votes vote down vote up
def auth_middleware(handler):
    """
    Authentication Middleware to check for
    Bearer token header
    """
    def middleware(authorization: Optional[Header]):
        if authorization and authorization[len("Bearer "):] == CONFIG['token'] or getattr(handler, "no_auth", False):
            return handler()
        raise HTTPError(HTTP_401, {"error": "bad credentials"})
    return middleware

# Add OpenAPI and Swaager support to our APIs 
Example #13
Source File: lthnvpnd.py    From lethean-vpn with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def remove_pidfile():
    pf = open(config.CONFIG.PIDFILE,"r")
    pid = int(pf.read())
    if (os.getpid() == pid):
        os.remove(config.CONFIG.PIDFILE)

# Starting here 
Example #14
Source File: utils.py    From project-black with GNU General Public License v2.0 5 votes vote down vote up
def check_authorization(request):
    """ Check if authed """
    if request.token:
        encoded = request.token.split(' ')[1]
        authentication = base64.b64decode(encoded).decode('utf-8')

        login = authentication.split(':')[0]
        password = authentication.split(':')[1]

        if login == CONFIG['application']['username'] and password == CONFIG['application']['password']:
            return True

    return False 
Example #15
Source File: main.py    From AI_For_Music_Composition with MIT License 5 votes vote down vote up
def load_data():
    """Load and return the training data."""
    print('[*] Loading data...')

    # Load data from SharedArray
    if CONFIG['data']['training_data_location'] == 'sa':
        import SharedArray as sa
        x_train = sa.attach(CONFIG['data']['training_data'])

    # Load data from hard disk
    elif CONFIG['data']['training_data_location'] == 'hd':
        if os.path.isabs(CONFIG['data']['training_data_location']):
            x_train = np.load(CONFIG['data']['training_data'])
        else:
            filepath = os.path.abspath(os.path.join(
                os.path.realpath(__file__), 'training_data',
                CONFIG['data']['training_data']))
            x_train = np.load(filepath)

    # Reshape data
    x_train = x_train.reshape(
        -1, CONFIG['model']['num_bar'], CONFIG['model']['num_timestep'],
        CONFIG['model']['num_pitch'], CONFIG['model']['num_track'])
    print('Training set size:', len(x_train))

    return x_train 
Example #16
Source File: post.py    From cheat.sh with MIT License 5 votes vote down vote up
def _save_cheatsheet(topic_name, cheatsheet):
    """
    Save posted cheat sheet `cheatsheet` with `topic_name`
    in the spool directory
    """

    nonce = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(9))
    filename = topic_name.replace('/', '.') + "." + nonce
    filename = os.path.join(CONFIG["path.spool"], filename)

    open(filename, 'w').write(cheatsheet) 
Example #17
Source File: comments.py    From cheat.sh with MIT License 5 votes vote down vote up
def _run_vim_script(script_lines, text_lines):
    """
    Apply `script_lines` to `lines_classes`
    and returns the result
    """

    script_vim = NamedTemporaryFile(delete=True)
    textfile = NamedTemporaryFile(delete=True)

    open(script_vim.name, "w").write("\n".join(script_lines))
    open(textfile.name, "w").write("\n".join(text_lines))

    script_vim.file.close()
    textfile.file.close()

    my_env = os.environ.copy()
    my_env['HOME'] = CONFIG["path.internal.vim"]

    cmd = ["script", "-q", "-c",
           "vim -S %s %s" % (script_vim.name, textfile.name)]

    Popen(cmd, shell=False,
          stdin=open(os.devnull, 'r'),
          stdout=FNULL, stderr=FNULL, env=my_env).communicate()

    return open(textfile.name, "r").read() 
Example #18
Source File: search.py    From cheat.sh with MIT License 5 votes vote down vote up
def find_answers_by_keyword(directory, keyword, options="", request_options=None):
    """
    Search in the whole tree of all cheatsheets or in its subtree `directory`
    by `keyword`
    """

    recursive = 'r' in options

    answers_found = []
    for topic in get_topics_list(skip_internal=True, skip_dirs=True):

        if not topic.startswith(directory):
            continue

        subtopic = topic[len(directory):]
        if not recursive and '/' in subtopic:
            continue

        answer = get_answer_dict(topic, request_options=request_options)

        if answer and answer.get('answer') and keyword.lower() in answer.get('answer', '').lower():
            answers_found.append(answer)

        if len(answers_found) > CONFIG['search.limit']:
            answers_found.append(
                _limited_entry()
            )
            break

    return answers_found 
Example #19
Source File: search.py    From cheat.sh with MIT License 5 votes vote down vote up
def _limited_entry():
    return {
        'topic_type': 'LIMITED',
        "topic": "LIMITED",
        'answer': "LIMITED TO %s ANSWERS" % CONFIG['search.limit'],
        'format': "code",
    } 
Example #20
Source File: internal.py    From cheat.sh with MIT License 5 votes vote down vote up
def _get_page(self, topic, request_options=None):
        if topic.endswith('/:list') or topic.lstrip('/') == ':list':
            return self._get_list_answer(topic)

        answer = ""
        if topic == ':styles':
            answer = "\n".join(CONFIG["frontend.styles"]) + "\n"
        elif topic == ":stat":
            answer = self._get_stat()+"\n"
        elif topic in _INTERNAL_TOPICS:
            answer = open(os.path.join(CONFIG["path.internal.pages"], topic[1:]+".txt"), "r").read()
            if topic in _COLORIZED_INTERNAL_TOPICS:
                answer = colorize_internal(answer)

        return answer 
Example #21
Source File: binarizer.py    From lakh-pianoroll-dataset with MIT License 5 votes vote down vote up
def main():
    """Main function."""
    src, dst = parse_args()
    make_sure_path_exists(dst)

    if CONFIG['multicore'] > 1:
        joblib.Parallel(n_jobs=CONFIG['multicore'], verbose=5)(
            joblib.delayed(binarizer)(npz_path, src, dst)
            for npz_path in findall_endswith('.npz', src))
    else:
        for npz_path in findall_endswith('.npz', src):
            binarizer(npz_path, src, dst)

    print("Dataset successfully binarized.") 
Example #22
Source File: messenger.py    From Briefly with MIT License 5 votes vote down vote up
def send_account_linking(recipient):
    page.send(recipient, Template.AccountLink(text="Welcome. Link your account.",
                                              account_link_url=CONFIG['SERVER_URL'] + "/authorize",
                                              account_unlink_button=True)) 
Example #23
Source File: merger_5.py    From lakh-pianoroll-dataset with MIT License 5 votes vote down vote up
def main():
    """Main function."""
    src, dst = parse_args()
    make_sure_path_exists(dst)

    if CONFIG['multicore'] > 1:
        joblib.Parallel(n_jobs=CONFIG['multicore'], verbose=5)(
            joblib.delayed(merger)(npz_path, src, dst)
            for npz_path in findall_endswith('.npz', src))
    else:
        for npz_path in findall_endswith('.npz', src):
            merger(npz_path, src, dst) 
Example #24
Source File: cleanser.py    From lakh-pianoroll-dataset with MIT License 5 votes vote down vote up
def midi_filter(midi_info):
    """Return True for qualified MIDI files and False for unwanted ones."""
    if midi_info['first_beat_time'] > 0.0:
        return False
    if midi_info['constant_time_signature'] not in CONFIG['time_signatures']:
        return False
    return True 
Example #25
Source File: server.py    From Briefly with MIT License 5 votes vote down vote up
def validate():
    if request.args.get('hub.mode', '') == 'subscribe' and \
                    request.args.get('hub.verify_token', '') == CONFIG['VERIFY_TOKEN']:

        print("Validating webhook")

        return request.args.get('hub.challenge', '')
    else:
        return 'Failed validation. Make sure the validation tokens match.' 
Example #26
Source File: messenger.py    From Briefly with MIT License 5 votes vote down vote up
def send_image(recipient):
    page.send(recipient, Attachment.Image(CONFIG['SERVER_URL'] + "/assets/rift.png")) 
Example #27
Source File: messenger.py    From Briefly with MIT License 5 votes vote down vote up
def send_gif(recipient):
    page.send(recipient, Attachment.Image(CONFIG['SERVER_URL'] + "/assets/instagram_logo.gif")) 
Example #28
Source File: messenger.py    From Briefly with MIT License 5 votes vote down vote up
def send_audio(recipient):
    page.send(recipient, Attachment.Audio(CONFIG['SERVER_URL'] + "/assets/sample.mp3")) 
Example #29
Source File: messenger.py    From Briefly with MIT License 5 votes vote down vote up
def send_video(recipient):
    page.send(recipient, Attachment.Video(CONFIG['SERVER_URL'] + "/assets/allofus480.mov")) 
Example #30
Source File: messenger.py    From Briefly with MIT License 5 votes vote down vote up
def send_receipt(recipient):
    receipt_id = "order1357"
    element = Template.ReceiptElement(title="Oculus Rift",
                                      subtitle="Includes: headset, sensor, remote",
                                      quantity=1,
                                      price=599.00,
                                      currency="USD",
                                      image_url=CONFIG['SERVER_URL'] + "/assets/riftsq.png"
                                      )

    address = Template.ReceiptAddress(street_1="1 Hacker Way",
                                      street_2="",
                                      city="Menlo Park",
                                      postal_code="94025",
                                      state="CA",
                                      country="US")

    summary = Template.ReceiptSummary(subtotal=698.99,
                                      shipping_cost=20.00,
                                      total_tax=57.67,
                                      total_cost=626.66)

    adjustment = Template.ReceiptAdjustment(name="New Customer Discount", amount=-50)

    page.send(recipient, Template.Receipt(recipient_name='Peter Chang',
                                          order_number=receipt_id,
                                          currency='USD',
                                          payment_method='Visa 1234',
                                          timestamp="1428444852",
                                          elements=[element],
                                          address=address,
                                          summary=summary,
                                          adjustments=[adjustment]))