Example #1
0
def search_track(client: Client, artist: str, title: str, prompt=False) -> tp.Union[None, Track]:

    def _search(text, results):
        search = client.search(text)
        if search.best and search.best.type == 'track':
            result = search.best.result
            if result.title.lower() == title.lower() and any(artist.lower() == a.name.lower() for a in result.artists):
                return Track.from_ya(result)
            results.append(Track.from_ya(result))
        if search.tracks:
            for i, result in enumerate(search.tracks.results):
                if result.title.lower() == title.lower() and any(artist.lower() == a.name.lower() for a in result.artists):
                    return Track.from_ya(result)
                results.append(Track.from_ya(result))
                if i == 4:
                    break
        return None

    results = []
    r = _search(title, results)
    if r is None:
        r = _search(f'{artist} {title}', results)
    if r is None and prompt:
        for i, r in enumerate(results):
            echo(f'{i}. {r.artist} - {r.title}')
        a = input(color.y('{} - {} [1/n] defaul: n '.format(artist, title)))
        if not a or not a.isdigit():
            return None
        a = int(a)
        return results[a] if a < len(results) else None
    return r
Example #2
0
def set_locale_ubuntu(locale, args, indent=0):
    if locale == System.current_locale:
        echo("Locale '%s' is already the active one." % System.current_locale, indent=indent)
        return 0

    # TODO: check asked locale is valid
    language = locale.split('.')[0]

    # Generate locale
    exit_code = pretty_execute("Generating locale '%s'" % locale,
                               ['sudo', 'locale-gen', locale],
                               args, indent=indent)
    if exit_code:
        return exit_code

    # Update locale
    command = [
        'sudo',
        'update-locale',
        'LANG="%s"' % locale,
        'LANGUAGE="%s"' % language,
        'LC_ALL="%s"' % locale,
        'LC_CTYPE="%s"'% locale
    ]
    exit_code = pretty_execute("Updating locale to '%s'" % locale, command,  args, indent=indent)
    if exit_code:
        return exit_code

    # Reconfigure locales
    command = ['sudo', 'dpkg-reconfigure', 'locales']
    exit_code = pretty_execute("Reconfiguring locales", command,  args, indent=indent)
    return exit_code
Example #3
0
    def processCommand(self, command):

        if type(command) != str:
            return None, None

        cmd_input = command

        # considerar la entrada si la orden empieza con la palabra "gaari"
        if re.search("^(gary|cari)", cmd_input):
            orden_list = cmd_input.split()

            # comprobamos que la orden tiene almenos dos palabras
            if len(orden_list) > 1:
                # solo nos interesa la segunda palabra
                orden = orden_list[1]
            else:
                return None, None


            # comprobar si la orden existe
            orden_existe = False
            orden_solicitada = { "label": None, "codigo": None }

            for _orden in const.ORDENES:
                if orden == _orden["label"]:
                    orden_existe = True
                    orden_solicitada = _orden

            # comprobar si laorden era "devuelve"

            objeto_retorno = 0
            orden_existe_2 = False
            if orden_existe == True and orden_solicitada["label"] == "devuelve" and len(orden_list) == 3:
                obj = orden_list[2]

                for _objeto in const.ORDENES[4:]:
                    if obj == _objeto["label"]:
                        objeto_retorno = _objeto["codigo"]
                        orden_existe_2 = True

            print(orden_solicitada, objeto_retorno)

            # Comprobar si la secuencia del orden es posible
            if orden_existe == True:
                if orden_solicitada["label"] != "devuelve":
                    return orden_solicitada["codigo"], objeto_retorno
                elif orden_solicitada["label"] == "devuelve" and orden_existe_2 == True:
                    return orden_solicitada["codigo"], objeto_retorno
                else:
                    echo(const.GAARI_SAYS + "No te he entendido, repite porfavor.", color=colors.FAIL)
                    return "REPITE", None
            else:
                echo(const.GAARI_SAYS + "No te he entendido, repite porfavor.", color=colors.FAIL)
                return "REPITE", None

        # parar la ejecución
        elif cmd_input == 'apágate' or cmd_input == 'adiós':
            return "APAGAR", None

        return None, None
Example #4
0
def install(args, indent=0):
    """
    Install postgresql server
    :param args:
    :type args:
    :return:
    :rtype:
    """
    echo("Installing PostgreSQL Server", indent=indent)

    if System.postgresql_version:
        echo("PostgreSQL server '%s' already installed with locale '%s'." % (
            System.postgresql_version,
            System.current_locale,
        ),
             indent=indent + 1,
             color=Fore.GREEN)
        return 0

    if System.system_name == 'darwin':
        return postgresql_install_darwin(args, indent=indent + 1)

    elif System.system_name in (
            'debian',
            'ubuntu',
    ):
        return postgresql_install_debian(args, indent=indent + 1)
    else:
        raise NotImplementedError(
            "Postgresql installation is not supported on '%s'." %
            System.system_name)
def process_a_set_of_marks_permutation(
        ps_idx, permutations, data, n_group_A, celltypes, marks,
        ct_chrom_fnames, real_chrom_lengths, ChromHMM_model_path, BIN_SIZE,
        states, compute_per_state_scores, max_min_window, to_smooth,
        use_posteriors, use_mean_distance_matrix, keep_max_scores_per_bin):

    background_model = new_score_dict(states, compute_per_state_scores)

    for perm_no, perm in enumerate(permutations):
        echo('Subset:', ps_idx, 'Combo:', perm_no)
        combo_background_scores = process_marks_permutation(
            perm, data, n_group_A, celltypes, marks, ct_chrom_fnames,
            real_chrom_lengths, ChromHMM_model_path, BIN_SIZE, states,
            compute_per_state_scores, max_min_window, to_smooth,
            use_posteriors, use_mean_distance_matrix, keep_max_scores_per_bin)
        for score_type in combo_background_scores:
            for s in combo_background_scores[score_type]:
                if s not in background_model[score_type]:
                    background_model[score_type][s] = 0

                background_model[score_type][s] += combo_background_scores[
                    score_type][s]

        gc.collect()

    return background_model
Example #6
0
def install_wkhtmltopdf(args, indent=0):
    if args.no_wkhtmltopdf:
        echo("wkhtmltopdf installation skipped.",
             indent=indent,
             color=Fore.CYAN)
        return 0

    if not System.wkhtmltopdf_version:
        if System.system_name in (
                'debian',
                'ubuntu',
        ):
            return install_wkhtmltopdf_debian(args, indent=indent)
        else:
            raise NotImplemented()

    # wkhtmltopdf is installed.
    # We warn user if installed version is different than ikez expected one
    if System.wkhtmltopdf_version != WKHTMLTOPDF_REQUIRED_VERSION:
        echo("WARNING: wkhtmltopdf is already installed at version '%s' "
             "while odoo v8 require '%s'." % (
                 System.wkhtmltopdf_version,
                 WKHTMLTOPDF_REQUIRED_VERSION,
             ),
             indent=indent)
    return 0
Example #7
0
def install_packages_debian(package_list, args=None, indent=0):

    if args.no_packages_check:
        echo("System packages and dependencies update skipped.",
             indent=indent,
             color=Fore.CYAN)
        return 0

    # update apt-get index
    exit_code = refresh_system_packages_index_debian(args, indent=indent)
    if exit_code:
        return exit_code

    # install each package that is not
    failed = 0

    for package in package_list:
        exit_code, output = execute(['sudo', 'dpkg', '-s', package],
                                    capture_output=True)
        if exit_code:  # Not installed
            exit_code = pretty_execute(
                "Installing package: '%s'" % package,
                ['sudo', 'apt-get', 'install', '-y', package],
                args,
                indent=indent)
            if exit_code:
                failed = exit_code

    return failed
def read_features(pos_fname, neg_fname, chrom_lengths, bin_size):
    echo('Reading features:', pos_fname, neg_fname)
    features = dict(
        (chrom, [SKIP] * chrom_lengths[chrom]) for chrom in chrom_lengths)

    with open_file(pos_fname) as in_f:
        for l in in_f:
            chrom, start, end = l.strip().split('\t')[:3]
            start_bin = int(start) / bin_size
            end_bin = int(end) / bin_size

            if chrom not in features:
                features[chrom] = []

            for bin_i in xrange(start_bin, end_bin + 1):
                features[chrom][bin_i] = POS

    if neg_fname is not None:
        with open_file(neg_fname) as in_f:
            for l in in_f:
                chrom, start, end = l.strip().split('\t')[:3]
                start_bin = int(start) / bin_size
                end_bin = int(end) / bin_size

                if chrom not in features:
                    features[chrom] = []

                for bin_i in xrange(start_bin, end_bin + 1):
                    features[chrom][bin_i] = NEG
    else:
        for chrom in features:
            for bin_i in xrange(len(features[chrom])):
                if features[chrom][bin_i] != POS:
                    features[chrom][bin_i] = NEG
    return features
Example #9
0
 def print_attempts(self):
     for node in self.nodes:
         self.attempts.extend(node.attempts)
     echo('Length of attempts: {}'.format(len(self.attempts)))
     for exc, group in itertools.groupby(self.attempts,
                                         lambda a: type(a).__name__):
         length = len(list(group))
         echo('Exception: {}, Count: {}'.format(exc, length),
              color='yellow')
Example #10
0
 def display_box(self, channel, user=None, ignore_whisper=False):
     if self.content is None or self.box_open:
         return
     if user is not None:
         utils.msg(user, self.content)
         self.clear_display()
         return
     utils.echo(channel, self.content, ignore_whisper=ignore_whisper)
     self.clear_display()
Example #11
0
def reset(args):
    echo("Removing all buildout generated items...")
    echo("Note that the ./downloads directory is not removed to avoid re-downloading openerp.",
         indent=1, color=Fore.CYAN)

    exit_code = pretty_execute("Deleting buildout files",
                               ['rm', '-rf', '.installed.cfg', 'bin/', 'develop-eggs/', 'eggs/', 'etc/', 'py27/'],
                               args=args, indent=1)
    return exit_code
Example #12
0
def add_postgres_to_system_path(args, indent=0):
    bash_profile_content = """# ikez: add Postgres.app binary to system PATH
export PATH=%s:$PATH
""" % POSTGRESQL_DEFAULT_PATH
    bash_profile_path = os.path.expanduser('~/.bash_profile')

    echo("Postgres.app bin folder added to .bash_profile", indent, color=Fore.GREEN)
    bash_profile = open(bash_profile_path, mode='a')
    bash_profile.write(bash_profile_content)
    bash_profile.close()
Example #13
0
def install_xcode(args, indent=0):
    echo("On Darwin, developer tools must be installed from Apple servers.", indent=indent, color=Fore.CYAN)
    echo("On the window that will open, click on \"Get Xcode\", if you want to", indent=indent, color=Fore.CYAN)
    echo("install the full Apple Development Environment (> 1Gb) or click ", indent=indent, color=Fore.CYAN)
    echo("on \"Install\" to only install command line tools required", indent=indent, color=Fore.CYAN)
    echo("by ikez.", indent=indent, color=Fore.CYAN)
    prompt("Press Return when ready and relaunch ikez when it will be done ! ", indent=indent, color=Fore.RED)
    exit_code = pretty_execute("Launching Apple developer tools installer",
                               ['xcode-select', '--install'], args, indent=indent)
    sys.exit(1)
Example #14
0
def install_brew(args, indent=0):
    echo("ikez use \"Homebrew\" (aka brew) package manager to install some", indent=indent, color=Fore.CYAN)
    echo("required frameworks (eg. libjpeg)", indent=indent, color=Fore.CYAN)
    echo("and programs (eg. git).", indent=indent, color=Fore.CYAN)
    echo("Homebrew home is http://brew.sh", indent=indent, color=Fore.CYAN)
    echo("You must install brew following instructions on the home page that will open.", indent=indent, color=Fore.CYAN)
    prompt("Press Return when ready and relaunch ikez when it will be done ! ", indent=indent, color=Fore.RED)
    exit_code = pretty_execute("Opening brew homepage",
                               ['open', 'http://brew.sh'],
                               args, indent=indent)
    sys.exit(1)
Example #15
0
 def wrapper(*args, **kwargs):
     for _ in range(100):
         try:
             return f(*args, **kwargs)
         except TimeoutError as e:
             args[0].attempts.append(e)
             echo('Timeout error reading from socket. '
                  'Trying again in 10 seconds.',
                  color='red')
             time.sleep(10)
     raise
Example #16
0
def add_postgres_to_system_path(args, indent=0):
    bash_profile_content = """# ikez: add Postgres.app binary to system PATH
export PATH=%s:$PATH
""" % POSTGRESQL_DEFAULT_PATH
    bash_profile_path = os.path.expanduser('~/.bash_profile')

    echo("Postgres.app bin folder added to .bash_profile",
         indent,
         color=Fore.GREEN)
    bash_profile = open(bash_profile_path, mode='a')
    bash_profile.write(bash_profile_content)
    bash_profile.close()
Example #17
0
def assert_buildout_cfg_files(args, indent=0):
    """
    Check every required buildout cfg files exists and
    create missing ones
    """
    echo("Checking buildout.cfg files", indent=indent)
    exit_code = generate_appserver_cfg(args, indent=indent + 1)
    if exit_code:
        return exit_code

    exit_code = generate_buildout_cfg(args, indent=indent + 1)
    return exit_code
Example #18
0
def assert_buildout_cfg_files(args, indent=0):
    """
    Check every required buildout cfg files exists and
    create missing ones
    """
    echo("Checking buildout.cfg files", indent=indent)
    exit_code = generate_appserver_cfg(args, indent=indent+1)
    if exit_code:
        return exit_code

    exit_code = generate_buildout_cfg(args, indent=indent+1)
    return exit_code
def get_chrom_lengths(fname, bin_size):
    echo('Computing chromosome lengths:', fname)
    chrom_lengths = {}
    with open_file(fname) as in_f:
        for l in in_f:
            chrom, start, end = l.strip().split()[:3]
            if chrom not in chrom_lengths:
                chrom_lengths[chrom] = 0

            chrom_lengths[chrom] = max(chrom_lengths[chrom],
                                       int(end) / bin_size)
    return chrom_lengths
Example #20
0
def reset(args):
    echo("Removing all buildout generated items...")
    echo(
        "Note that the ./downloads directory is not removed to avoid re-downloading openerp.",
        indent=1,
        color=Fore.CYAN)

    exit_code = pretty_execute("Deleting buildout files", [
        'rm', '-rf', '.installed.cfg', 'bin/', 'develop-eggs/', 'eggs/',
        'etc/', 'py27/'
    ],
                               args=args,
                               indent=1)
    return exit_code
Example #21
0
    def migrate_slot(self, dst, slot, cluster):
        dst.set_slot('IMPORTING', slot, self.name)
        self.set_slot('MIGRATING', slot, dst.name)

        total_keys = 0
        for keys in self._scan_keys(slot, cluster.key_migration_count):
            results = self.migrate_keys(dst.host, dst.port, keys)
            self.attempts.extend(filter(lambda r: any(
                isinstance(r, e) for e in self.ignored_exceptions), results))
            total_keys += len(keys)

        echo('{} key(s) migrated from {} to {} in slot {}'.format(
            total_keys, self, dst, slot))

        cluster.update_slot_mapping(slot, dst.name)
def str_to_bits(string_array):
    bits = [0] * (len(string_array) / 8 +
                  (1 if len(string_array) % 8 != 0 else 0))
    c_bit_array_idx = -1
    for i in xrange(len(string_array)):
        bit_pos = i % 8
        if bit_pos == 0:
            c_bit_array_idx += 1
        if string_array[i] not in ['0', '1']:
            echo(
                'ERROR: ChromHMM binarized data should consist of only 0 and 1s:',
                i, ', char=', string_array[i])
            exit(1)
        bits[c_bit_array_idx] |= int(string_array[i]) << bit_pos
    return ''.join(map(chr, bits))
Example #23
0
def install_system_dependencies(args, indent=0):

    if args.no_packages_check:
        echo("System packages and dependencies update skipped.", indent=indent, color=Fore.CYAN)
        return 0

    echo("Checking required system packages and dependencies", indent=indent)

    if System.system_name in ('ubuntu', 'debian',):
        return install_system_dependencies_ubuntu(args, indent=indent+1)

    elif System.system_name == 'darwin':
        return install_system_dependencies_darwin(args, indent=indent+1)
    else:
        raise NotImplemented()
Example #24
0
async def interpretar_comandos(loop):
    echo("Escuchando...", color=colors.OKCYAN)

    code = None

    with sr.Microphone() as source:
        while True:
            orden, objeto = voice.recognize(source)

            if orden != "APAGAR":
                if orden != "REPITE" and orden != None:
                    # procesar la orden
                    procesar_orden(orden, objeto)
            else:
                # apagar el robot
                return
def worker(args):
    func = None

    try:
        func = args[0]
        return func(*args[1:])

    except Exception, e:
        print 'Caught exception in output worker thread (combo_on: %s):' % str(args[1])
        print func

        echo(e)
        if hasattr(open_log, 'logfile'):
            traceback.print_exc(file=open_log.logfile)
        traceback.print_exc()

        print
        raise e
Example #26
0
def install_brew(args, indent=0):
    echo("ikez use \"Homebrew\" (aka brew) package manager to install some",
         indent=indent,
         color=Fore.CYAN)
    echo("required frameworks (eg. libjpeg)", indent=indent, color=Fore.CYAN)
    echo("and programs (eg. git).", indent=indent, color=Fore.CYAN)
    echo("Homebrew home is http://brew.sh", indent=indent, color=Fore.CYAN)
    echo(
        "You must install brew following instructions on the home page that will open.",
        indent=indent,
        color=Fore.CYAN)
    prompt("Press Return when ready and relaunch ikez when it will be done ! ",
           indent=indent,
           color=Fore.RED)
    exit_code = pretty_execute("Opening brew homepage",
                               ['open', 'http://brew.sh'],
                               args,
                               indent=indent)
    sys.exit(1)
Example #27
0
def install_wkhtmltopdf(args, indent=0):
    if args.no_wkhtmltopdf:
        echo("wkhtmltopdf installation skipped.", indent=indent, color=Fore.CYAN)
        return 0

    if not System.wkhtmltopdf_version:
        if System.system_name in ('debian', 'ubuntu',):
            return install_wkhtmltopdf_debian(args, indent=indent)
        else:
            raise NotImplemented()

    # wkhtmltopdf is installed.
    # We warn user if installed version is different than ikez expected one
    if System.wkhtmltopdf_version != WKHTMLTOPDF_REQUIRED_VERSION:
        echo("WARNING: wkhtmltopdf is already installed at version '%s' "
             "while odoo v8 require '%s'." % (System.wkhtmltopdf_version,
                                              WKHTMLTOPDF_REQUIRED_VERSION,),
             indent=indent)
    return 0
Example #28
0
def install_system_dependencies(args, indent=0):

    if args.no_packages_check:
        echo("System packages and dependencies update skipped.",
             indent=indent,
             color=Fore.CYAN)
        return 0

    echo("Checking required system packages and dependencies", indent=indent)

    if System.system_name in (
            'ubuntu',
            'debian',
    ):
        return install_system_dependencies_ubuntu(args, indent=indent + 1)

    elif System.system_name == 'darwin':
        return install_system_dependencies_darwin(args, indent=indent + 1)
    else:
        raise NotImplemented()
def read_binarized(fname, random_chunks):
    echo('Reading:', fname)
    with open_file(fname) as in_f:
        ct, chrom = in_f.readline().strip().split()

        if chrom not in random_chunks:
            return None, None, None, None

        marks = in_f.readline().strip().split()
        c_data = {}

        chunks = random_chunks[chrom]
        chunk_no = 0
        chunk_start, chunk_end = chunks[chunk_no]
        chunk_id = chrom + '_' + str(chunk_no)
        c_data[chunk_id] = dict((m, []) for m in marks)

        for bin_no, l in enumerate(in_f):

            if bin_no == chunk_end:
                chunk_no += 1
                if chunk_no == len(chunks):
                    break

                chunk_id = chrom + '_' + str(chunk_no)
                c_data[chunk_id] = dict((m, []) for m in marks)
                chunk_start, chunk_end = chunks[chunk_no]

            if bin_no < chunk_start:
                continue

            binarized = l.strip().split()
            for b, m in zip(binarized, marks):
                c_data[chunk_id][m].append(b)

        # convert the binary data array to a string to save some memory
        for chunk_id in c_data:
            for m in c_data[chunk_id]:
                c_data[chunk_id][m] = ''.join(c_data[chunk_id][m])

    return marks, ct, chrom, c_data
def read_binarized_in_full(fname, chrom_lengths):
    echo('Reading:', fname)
    with open_file(fname) as in_f:
        ct, chrom = in_f.readline().strip().split()

        # if chrom not in chrom_lengths:
        #     echo('Skipping:', chrom)
        #     return None, None, None, None
        #
        marks = in_f.readline().strip().split()
        data = dict((m, [''] * chrom_lengths[chrom]) for m in marks)

        for bin_no, l in enumerate(in_f):
            binarized = l.strip().split()
            for b, m in zip(binarized, marks):
                data[m][bin_no] = b

        for m in data:
            data[m] = compress(data[m])

    return marks, ct, chrom, data
Example #31
0
    def all_docs():
        with open(filename, newline='') as doc_file:
            fields = get_fieldnames(doc_file)
            dict_reader = csv.DictReader(doc_file, fieldnames=fields)
            if 'ticket' in doc_type:
                fields.append("ticket_time")

            echo('Using the following ' + str(len(fields)) + ' fields:',
                 quiet)
            for field in fields:
                echo(field, quiet)

            i = 0
            for row in dict_reader:
                # Prepare meta info for each indexed document.
                meta = {
                    'index': idx_name,
                    'type': doc_type,
                }
                if id_field_idx is not None:
                    meta['id'] = row[fields[int(id_field_idx)]]
                # Convert tim inteval to an integer in minutes.
                for k, v in row.items():
                    if isinstance(v, str) and isperiod(v):
                        row[k] = t2i(v)
                if 'ticket' in doc_type:
                    row['ticket_time'] = time_interval(row['create_time'],
                                                       row['close_time'],
                                                       '%m/%d/%Y %I:%M:%S %p')
                i += 1
                echo('Sending item %s to ES ...' % i, quiet)
                yield index_op(row, meta)
Example #32
0
    def voiceInput(self, source):
        echo("GAAR-I le escucha", color=colors.OKGREEN)
        RECONGNIZER.adjust_for_ambient_noise(source)
        audio = RECONGNIZER.listen(source)

        try:
            command = RECONGNIZER.recognize_google(audio, language="es-ES")
            echo('Ha dicho: {}'.format(command), color=colors.WARNING)
        except:
            echo(const.GAARI_SAYS + "Disculpa, no se le escucha", color=colors.FAIL)
            echo(const.GAARI_SAYS + "Vuelva a probar", color=colors.FAIL)
            command = ""

        return command
Example #33
0
    def all_docs():
        with open(filename, newline='') as doc_file:
            fields = get_fieldnames(doc_file)
            dict_reader = csv.DictReader(doc_file, fieldnames=fields)
            if 'ticket' in doc_type:
                fields.append("ticket_time")

            echo('Using the following ' + str(len(fields)) + ' fields:',
                 quiet)
            for field in fields:
                echo(field, quiet)

            i = 0
            for row in dict_reader:
                # Prepare meta info for each indexed document.
                meta = {
                    'index': idx_name,
                    'type': doc_type,
                }
                if id_field_idx is not None:
                    meta['id'] = row[fields[int(id_field_idx)]]
                # Convert tim inteval to an integer in minutes.
                for k, v in row.items():
                    if isinstance(v, str) and isperiod(v):
                        row[k] = t2i(v)
                if 'ticket' in doc_type:
                    row['ticket_time'] = time_interval(row['create_time'],
                                                       row['close_time'],
                                                       '%m/%d/%Y %I:%M:%S %p')
                i += 1
                echo('Sending item %s to ES ...' % i, quiet)
                yield index_op(row, meta)
Example #34
0
def enforcing_odoo_server_database_user(args, indent=0):
    """
    Check supplied PostgreSQL user and password are valid
    """

    echo("Enforcing appserver database user", indent=indent)

    if not args.password:
        args.password = args.username

    # test if user exists
    if postgresql.pg_user_exists(args.username, args=args, indent=indent + 1):
        # it exists ; is login password ok
        exit_code = pg_test_user_connection(args.username,
                                            args.password,
                                            args.host,
                                            args=args,
                                            indent=indent + 1)
        if exit_code:
            # No !
            if args.force:
                exit_code = postgresql.pg_set_password(args.username,
                                                       args.password,
                                                       args,
                                                       indent=indent + 1)

            elif not args.unattended:
                user_permission = (prompt(
                    "User '%s' exists but with another password. Do you want to change his password with '%s' [Y/n] ? "
                    % (
                        args.username,
                        args.password,
                    ),
                    indent=indent + 1,
                    color=Fore.RED)
                                   or 'Y').lower() in ['y', 'yes', 'o', 'oui']
                if user_permission:
                    exit_code = postgresql.pg_set_password(args.username,
                                                           args.password,
                                                           args,
                                                           indent=indent + 2)
            else:
                echo(
                    "ERROR: Wrong PostgreSQL password for user '%s'. Aborting Odoo installation."
                    % args.username,
                    indent=indent + 1,
                    color=Fore.RED)
                echo(
                    "Relaunch install --force or with valid PostgreSQL username and password or create one using 'ikez postgresql createuser' command.",
                    indent=indent + 1,
                    color=Fore.RED)
                return exit_code

    else:  # User do not exists, create it
        exit_code = postgresql.pg_create_user(args.username,
                                              args.password,
                                              args=args,
                                              indent=indent + 1)

    return exit_code
Example #35
0
def createuser(args, indent=0):
    """
    Create a postgresql user or update his password.
    :param args:
    :type args: Namespace
    :return:
    :rtype:
    """
    assert System.postgresql_version, "PostgreSQL server is not installed"

    args.username = args.username or os.environ['USER']

    if pg_user_exists(args.username, args, indent=indent+1):
        echo("User '%s' already exists."  % args.username, indent=indent+1)

        if args.password:
            echo("Resetting user '%s' password with '%s'." % (args.username, args.password,), indent=indent+1)
            exit_code = pg_set_password(args.username, args.password, args=args, indent=indent+1)
            if exit_code:
                return exit_code
        else:
            echo("No password specified. Nothing done !", indent=indent+1)
    else:
        args.password = args.password or args.username
        exit_code = pg_create_user(args.username, args.password, args=args, indent=indent+1)
        if exit_code:
            return exit_code

    # We create a database named after user so that we can launch psql without any error
    exit_code = pg_create_user_database(args.username, args=args, indent=indent+1)
    return exit_code
Example #36
0
def enforcing_odoo_server_database_user(args, indent=0):
    """
    Check supplied PostgreSQL user and password are valid
    """

    echo("Enforcing appserver database user", indent=indent)

    if not args.password:
        args.password = args.username

    # test if user exists
    if postgresql.pg_user_exists(args.username, args=args, indent=indent+1):
        # it exists ; is login password ok
        exit_code = pg_test_user_connection(args.username, args.password, args.host, args=args, indent=indent+1)
        if exit_code:
            # No !
            if args.force:
                exit_code = postgresql.pg_set_password(args.username, args.password, args, indent=indent+1)

            elif not args.unattended:
                user_permission = (prompt("User '%s' exists but with another password. Do you want to change his password with '%s' [Y/n] ? " % (args.username, args.password,),
                                          indent=indent+1, color=Fore.RED) or 'Y').lower() in ['y', 'yes', 'o', 'oui']
                if user_permission:
                    exit_code = postgresql.pg_set_password(args.username, args.password, args, indent=indent+2)
            else:
                echo("ERROR: Wrong PostgreSQL password for user '%s'. Aborting Odoo installation." % args.username, indent=indent+1, color=Fore.RED)
                echo("Relaunch install --force or with valid PostgreSQL username and password or create one using 'ikez postgresql createuser' command.", indent=indent+1, color=Fore.RED)
                return exit_code

    else:  # User do not exists, create it
        exit_code = postgresql.pg_create_user(args.username, args.password, args=args, indent=indent+1)

    return exit_code
Example #37
0
def set_locale_ubuntu(locale, args, indent=0):
    if locale == System.current_locale:
        echo("Locale '%s' is already the active one." % System.current_locale,
             indent=indent)
        return 0

    # TODO: check asked locale is valid
    language = locale.split('.')[0]

    # Generate locale
    exit_code = pretty_execute("Generating locale '%s'" % locale,
                               ['sudo', 'locale-gen', locale],
                               args,
                               indent=indent)
    if exit_code:
        return exit_code

    # Update locale
    command = [
        'sudo', 'update-locale',
        'LANG="%s"' % locale,
        'LANGUAGE="%s"' % language,
        'LC_ALL="%s"' % locale,
        'LC_CTYPE="%s"' % locale
    ]
    exit_code = pretty_execute("Updating locale to '%s'" % locale,
                               command,
                               args,
                               indent=indent)
    if exit_code:
        return exit_code

    # Reconfigure locales
    command = ['sudo', 'dpkg-reconfigure', 'locales']
    exit_code = pretty_execute("Reconfiguring locales",
                               command,
                               args,
                               indent=indent)
    return exit_code
Example #38
0
def install(args, indent=0):
    """
    Install postgresql server
    :param args:
    :type args:
    :return:
    :rtype:
    """
    echo("Installing PostgreSQL Server", indent=indent)

    if System.postgresql_version:
        echo("PostgreSQL server '%s' already installed with locale '%s'." % (System.postgresql_version, System.current_locale,),
             indent=indent+1, color=Fore.GREEN)
        return 0


    if System.system_name == 'darwin':
        return postgresql_install_darwin(args, indent=indent+1)

    elif System.system_name in ('debian', 'ubuntu',):
        return postgresql_install_debian(args, indent=indent+1)
    else:
        raise NotImplementedError("Postgresql installation is not supported on '%s'." % System.system_name)
Example #39
0
def install_xcode(args, indent=0):
    echo("On Darwin, developer tools must be installed from Apple servers.",
         indent=indent,
         color=Fore.CYAN)
    echo(
        "On the window that will open, click on \"Get Xcode\", if you want to",
        indent=indent,
        color=Fore.CYAN)
    echo("install the full Apple Development Environment (> 1Gb) or click ",
         indent=indent,
         color=Fore.CYAN)
    echo("on \"Install\" to only install command line tools required",
         indent=indent,
         color=Fore.CYAN)
    echo("by ikez.", indent=indent, color=Fore.CYAN)
    prompt("Press Return when ready and relaunch ikez when it will be done ! ",
           indent=indent,
           color=Fore.RED)
    exit_code = pretty_execute("Launching Apple developer tools installer",
                               ['xcode-select', '--install'],
                               args,
                               indent=indent)
    sys.exit(1)
Example #40
0
def read_binarized(fname, random_chunks):
    echo('Reading:', fname)
    with gzip.open(fname) if fname.endswith('.gz') else open(fname) as in_f:
        ct, chrom = in_f.readline().strip().split()

        if chrom not in random_chunks:
            return None, None, None, None

        marks = in_f.readline().strip().split()
        c_data = {}

        chunks = random_chunks[chrom]
        chunk_no = 0
        chunk_start, chunk_end = chunks[chunk_no]
        chunk_id = chrom + '_' + str(chunk_no)
        c_data[chunk_id] = dict((m, []) for m in marks)

        for bin_no, l in enumerate(in_f):

            if bin_no == chunk_end:
                chunk_no += 1
                if chunk_no == len(chunks):
                    break

                chunk_id = chrom + '_' + str(chunk_no)
                c_data[chunk_id] = dict((m, []) for m in marks)
                chunk_start, chunk_end = chunks[chunk_no]

            if bin_no < chunk_start:
                continue

            binarized = l.strip().split()
            for b, m in zip(binarized, marks):
                c_data[chunk_id][m].append(b)

    return marks, ct, chrom, c_data
Example #41
0
def pg_create_user_database(username, args=None, indent=0):
    """
    Create a database named after user so that we can launch psql without any error.
    :param username:
    :type username: str
    :param password:
    :type password: str
    :return:
    :rtype: bool
    """
    if System.system_name in ('debian', 'ubuntu', 'darwin'):
        exit_code, result = exec_psql_command("Check whether a database named '%s' exists" %  username,
                                              "SELECT COUNT(*) FROM pg_database WHERE datname='%s';" % username, args=args, indent=indent)
        if exit_code:
            return exit_code

        if int(result) == 1:
            # TODO: Check dbowner
            echo("WARNING: A database named '%s' already exists. Check owner." % username, indent=indent)
            return 126

        exit_code, result = exec_psql_command("Create database '%s'" % username,
                                              "CREATE DATABASE %s WITH OWNER=%s ;" % (username, username,), args=args, indent=indent+1)
        return exit_code
Example #42
0
def install_packages_debian(package_list, args=None, indent=0):

    if args.no_packages_check:
        echo("System packages and dependencies update skipped.", indent=indent, color=Fore.CYAN)
        return 0

    # update apt-get index
    exit_code = refresh_system_packages_index_debian(args, indent=indent)
    if exit_code:
        return exit_code

    # install each package that is not
    failed = 0

    for package in package_list:
        exit_code, output = execute(['sudo', 'dpkg', '-s', package], capture_output=True)
        if exit_code:  # Not installed
            exit_code = pretty_execute("Installing package: '%s'" % package,
                                       ['sudo', 'apt-get', 'install', '-y', package],
                                       args, indent=indent)
            if exit_code:
                failed = exit_code

    return failed
Example #43
0
def pg_create_user_database(username, args=None, indent=0):
    """
    Create a database named after user so that we can launch psql without any error.
    :param username:
    :type username: str
    :param password:
    :type password: str
    :return:
    :rtype: bool
    """
    if System.system_name in ('debian', 'ubuntu', 'darwin'):
        exit_code, result = exec_psql_command(
            "Check whether a database named '%s' exists" % username,
            "SELECT COUNT(*) FROM pg_database WHERE datname='%s';" % username,
            args=args,
            indent=indent)
        if exit_code:
            return exit_code

        if int(result) == 1:
            # TODO: Check dbowner
            echo(
                "WARNING: A database named '%s' already exists. Check owner." %
                username,
                indent=indent)
            return 126

        exit_code, result = exec_psql_command(
            "Create database '%s'" % username,
            "CREATE DATABASE %s WITH OWNER=%s ;" % (
                username,
                username,
            ),
            args=args,
            indent=indent + 1)
        return exit_code
Example #44
0
def procesar_orden(orden, objeto):
    if orden == const.ORDEN_VEN:  # ven
        seq.ven()
        echo(const.GAARI_SAYS + "Gaari viene", color=colors.OKGREEN)
    elif orden == const.ORDEN_ABRE:  # abre
        seq.abre()
        echo(const.GAARI_SAYS + "Gaari está abriendo", color=colors.OKGREEN)
    # elif orden == const.ORDEN_AGARRA: # agarra
    #     seq.agarra()
    #     echo(const.GAARI_SAYS + "Gaari agarra", color=colors.OKGREEN)
    elif orden == const.ORDEN_DEVUELVE:  # devuelve
        seq.devuelve(objeto)
        echo(const.GAARI_SAYS + "Gaari va a devolver", color=colors.OKGREEN)
    else:
        seq.objeto(orden)
        echo(const.GAARI_SAYS + "Gaari coje el objecto", color=colors.OKGREEN)

    return True
Example #45
0
def generate_appserver_cfg(args, indent=0):
    if not os.path.exists('appserver.cfg') or args.force_appserver_cfg:
        echo("Generating appserver.cfg: ", indent=indent, end='')
        appserver_cfg_content = APPSERVER_CFG_TEMPLATE.format(**args.__dict__)
        appserver_cfg = open('appserver.cfg', mode='w')
        appserver_cfg.write(appserver_cfg_content)
        appserver_cfg.close()
        echo("Done", indent=0, color=Fore.GREEN)
    else:
        echo("Existing appserver.cfg untouched. Use --force-appserver-cfg to regenerate it.", indent, Fore.CYAN)
    return 0
Example #46
0
def generate_buildout_cfg(args, indent=0):

    if not os.path.exists('buildout.cfg') or args.force:
        echo("Generating buildout.cfg: ", indent=indent, end='')
        if args.index:
            # TODO: check index is a valid URL pointing to a PYPI server
            args.index = "index = %s" % args.index
        buildout_cfg_content = BUILDOUT_CFG_TEMPLATE.format(**args.__dict__)
        buildout_cfg = open('buildout.cfg', mode='w')
        buildout_cfg.write(buildout_cfg_content)
        buildout_cfg.close()
        echo("Done", indent=0, color=Fore.GREEN)
    else:
        echo("Existing buildout.cfg untouched. Use --force to regenerate it.", indent, Fore.CYAN)

    return 0
Example #47
0
def install_wkhtmltopdf_darwin(args, indent=0):

    echo("Installing wkhtmltopdf 0.12.1 (required by Odoo v8 and above to print QWeb reports)",
         indent=indent)

    echo("On Darwin, wkhtmltopdf is installed using an interactive installer from wkhtmltopdf", indent=indent+1, color=Fore.CYAN)
    echo("official web site: http://wkhtmltopdf.org", indent=indent+1, color=Fore.CYAN)

    command = [
        'wget',
        'http://downloads.sourceforge.net/project/wkhtmltopdf/archive/0.12.1/'
        'wkhtmltox-0.12.1_osx-cocoa-x86-64.pkg'
    ]
    if not os.path.exists('wkhtmltox-0.12.1_osx-cocoa-x86-64.pkg'):
        exit_code = pretty_execute("Downloading wkhtmltopdf 0.12.1", command, args, indent=indent+1)
        if exit_code:
            return exit_code

    prompt("When you're ready, press Enter to launch wkhtmltopdf installer then relaunch"
           " ikez when it will be done ! ", indent=indent+1, color=Fore.RED)
    exit_code = pretty_execute("Launching 'wkhtmltox-0.12.1_osx-cocoa-x86-64.pkg' installer",
                               ['open', 'wkhtmltox-0.12.1_osx-cocoa-x86-64.pkg'], args, indent=indent+1)
    sys.exit(1)
Example #48
0
def connect_to_network(options):
    utils.echo("Please connect to network {0}.".format(options.robot_network_name), 'red')
    utils.echo('Hit [enter] when done.', 'red')
Example #49
0
def install_virtualenv(args, indent=0):

    echo("Installing virtualenv", indent)

    if not System.virtualenv_version:
        echo("virtualenv is not installed !!!!", indent+1, Fore.CYAN)
        echo("ikez (and buildout) requires a virtualenv version > 1.9.1", indent+1, Fore.CYAN)

        if System.system_name == 'debian':
            if System.system_major_version == '7':
                echo("On Wheezy (Debian 7.8), default virtualenv version is too old for ikez (and buildout).", indent=indent+1,
                     color=Fore.CYAN)
                echo("So we will install recent setuptools (14.1.1) and virtualenv (12.0.7) from pypi.", indent=indent+1, color=Fore.CYAN)
                echo("Please look there for detail:", indent=indent+1, color=Fore.CYAN)
                echo("  - https://pypi.python.org/pypi/setuptools", indent=indent+1, color=Fore.CYAN)
                echo("  - https://pypi.python.org/pypi/virtualenv", indent=indent+1, color=Fore.CYAN)
                if not args.force:
                    user_permission = (prompt("Are you Ok ? [Y/n] ", indent=indent+1, color=Fore.RED) or 'Y').lower() in ['y', 'yes', 'o',                                                                                                                          'oui']
                    if not user_permission:
                        return 1

                return install_virtualenv_from_pypi(args, indent=indent+1)

            elif System.system_major_version == '8':
                echo("On Jessie (Debian 8), default virtualenv version is too old for ikez (and buildout).", indent=indent+1,
                     color=Fore.CYAN)
                echo("So we will install recent setuptools (14.1.1) and virtualenv (12.0.7) from pypi.", indent=indent+1, color=Fore.CYAN)
                echo("Please look there for detail:", indent=indent+1, color=Fore.CYAN)
                echo("  - https://pypi.python.org/pypi/setuptools", indent=indent+1, color=Fore.CYAN)
                echo("  - https://pypi.python.org/pypi/virtualenv", indent=indent+1, color=Fore.CYAN)
                if not args.force:
                    user_permission = (prompt("Are you Ok ? [Y/n] ", indent=indent+1, color=Fore.RED) or 'Y').lower() in ['y', 'yes', 'o',                                                                                                                          'oui']
                    if not user_permission:
                        return 1

                return install_virtualenv_from_pypi(args, indent=indent+1)

            else:
                echo("You are running ikez on an unsupported Debian version ! ikez supports only"
                     "precise and trusty for now.", color=Fore.RED)
                raise NotImplementedError()

        elif System.system_name == 'ubuntu':

            if System.system_major_version == '12':
                echo("On Precise (Ubuntu 12), default virtualenv version is too old for ikez (and buildout).", indent=indent+1,
                     color=Fore.CYAN)
                echo("So we will install recent setuptools (14.1.1) and virtualenv (12.0.7) from pypi.", indent=indent+1, color=Fore.CYAN)
                echo("Please look there for detail:", indent=indent+1, color=Fore.CYAN)
                echo("  - https://pypi.python.org/pypi/setuptools", indent=indent+1, color=Fore.CYAN)
                echo("  - https://pypi.python.org/pypi/virtualenv", indent=indent+1, color=Fore.CYAN)
                if not args.force:
                    user_permission = (prompt("Are you Ok ? [Y/n] ", indent=indent+1, color=Fore.RED) or 'Y').lower() in ['y', 'yes', 'o',                                                                                                                          'oui']
                    if not user_permission:
                        return 1

                return install_virtualenv_from_pypi(args, indent=indent+1)

            elif System.system_major_version in ('14', '15',):
                echo("On Ubuntu 14 and 15, default virtualenv version is ok so we just apt-get it.",
                     indent=indent+1, color=Fore.CYAN)
                exit_code = pretty_execute("Installing Ubuntu distribution virtualenv",
                                           ['sudo', 'apt-get', 'install', '-y', 'python-virtualenv'],
                                           args, indent=indent+1)
                return exit_code
            else:
                echo("You are running ikez on an unsupported Ubuntu version ! ikez supports only "
                     "Ubuntu 14 and 15 for now.", color=Fore.RED)
                raise NotImplementedError()

        elif System.system_name == 'darwin':
            echo("On Darwin / MacOS, we install recent setuptools (14.1.1) and virtualenv (12.0.7) from pypi.", indent=indent+1, color=Fore.CYAN)
            echo("Please look there for detail:", indent=indent+1, color=Fore.CYAN)
            echo("  - https://pypi.python.org/pypi/setuptools", indent=indent+1, color=Fore.CYAN)
            echo("  - https://pypi.python.org/pypi/virtualenv", indent=indent+1, color=Fore.CYAN)
            if not args.force:
                user_permission = (prompt("Are you Ok ? [Y/n] ", indent=indent+1, color=Fore.RED) or 'Y').lower() in ['y', 'yes', 'o',                                                                                                                          'oui']
                if not user_permission:
                    return 1

            return install_virtualenv_from_pypi(args, indent=indent+1)

        else:
            raise NotImplementedError()

    elif semver.compare(System.virtualenv_version, '1.9.1') > 0:
        print "No need to install virtualenv ;  installed version ('%s') is ok (> '1.9.1')." % System.virtualenv_version
        return 126
    else:
        echo("Installed virtualenv version '%s' is too old ! " % System.virtualenv_version, indent=indent+1, color=Fore.CYAN)
        echo("ikez requires virtualenv version > 1.9.1", indent=indent+1, color=Fore.CYAN)
        echo("Look at: ", indent=indent+1, color=Fore.CYAN)
        echo("  - https://pypi.python.org/pypi/setuptools", indent=indent+1, color=Fore.CYAN)
        echo("  - https://pypi.python.org/pypi/virtualenv", indent=indent+1, color=Fore.CYAN)

    return 1  #
def run_confirmation():
    utils.echo('Please confirm that you have completely configured "config.txt"', 'cyan')
    utils.echo('Press [Enter] when ready to proceed', 'cyan')
    raw_input()
Example #51
0
def postgresql_install_darwin(args, indent=0):
    if args.locale:
        exit_code = system.set_locale_darwin(args.locale, args, indent=indent)
        if exit_code:
            return exit_code

    if not os.path.exists(POSTGRESQL_DEFAULT_PATH):
        echo("PostgreSQL database automated installation is not supported on Darwin.", color=Fore.CYAN)
        echo("Today, ikez recommended way of installing PostgreSQL is to use http://postgresapp.com :", color=Fore.CYAN)
        echo("  - Open https://github.com/PostgresApp/PostgresApp/releases/ in your browser", color=Fore.CYAN)
        echo("  - Download the last version in the "+Fore.RED+"9.3 serie.", color=Fore.CYAN)
        echo("  - Unzip the file, launch it,", color=Fore.CYAN)
        echo("  - Click on the Move button, when asked whether you want to \"Move to Applications folder ?\"", color=Fore.CYAN)
        return 126

    if POSTGRESQL_DEFAULT_PATH not in os.environ['PATH'].split(':'):
        echo("Postgres.app exists but psql is not on system path.", indent=indent, color=Fore.CYAN)
        add_postgres_to_system_path(args, indent=indent)
        echo("Now, you must reopen a new Terminal tab for the change to be effective.", indent=indent, color=Fore.RED)
        return 126
Example #52
0
    def main(self):
        # init the config file
        conf = configHandler()
        if not conf.ok:
            _err_exit('Problem with the config file')

        libraryPath, xmlFileName, outputDir = \
                     conf.getValuesAndUpdateFromUser(self.libraryPath,
                                                     self.xmlFileName,
                                                     self.outputDir)

        ##
        # get iPhoto datas or flat dir pictures list
        if self.fb:
            logger.info('generate gallery from photos in %s dir' % self.fromDir)
            xmlData = None
            self.albumName = 'My Facebook pictures'
            self.fromDir = '/tmp/fb_files'

            facebook_download(self.fromDir, self.fb_uid)
            # sys.exit(0)

        elif not self.fromDir:
            try:
                adp = AlbumDataParser(libraryPath, xmlFileName)
                xmlData = adp.maybeLoadFromXML(conf)
            except(AlbumDataParserError):
                _err_exit("Problem parsing AlbumData.xml")
        else:
            logger.info('generate gallery from photos in %s dir' % self.fromDir)
            xmlData = None
            # FIXME: this '/' may not be portable ...
            self.albumName = basename(rstrip(self.fromDir, '/'))
            logger.info('albumName is %s' % self.albumName)

	# FIXME: remove the output dir if a problem occur
        up = 'pytof'
        topDir = join(self.outputDir, up, self.albumName)
        try:
            if not exists(topDir):
                os.makedirs(topDir)
        except (os.error):
            _err_exit('Cannot create %s' %(topDir))

        echo('output dir is %s' % (topDir))

        try:
            if self.info:
                for a in xmlData.getAlbumList():
                    try: 
                        print a.encode('utf8')
                    except UnicodeDecodeError:
                        print a
            else:
                if self.fs:
                    makefs.main(self.albumName, topDir, xmlData)
                else:
                    makepage.main(self.albumName, topDir, xmlData,
                                  self.stripOriginals, self.style,
                                  self.fromDir, self.progress)

            archive = None
            if self.Zip or self.tar:
                archive = mkarchive(fn = join(outputDir, up, self.albumName),
                                    prefix = join(outputDir, up),
                                    mainDir = self.albumName,
                                    files = [],
                                    Zip = self.Zip,
                                    tar = self.tar)
                echo('output archive is %s' % (archive))

            if not self.info and not self.fs:
                import webbrowser
                url = 'file:///'
                url += '/'.join(topDir.split(sep)) + '/'
                url += '/'.join(['..', 'index.html'])
                webbrowser.open(url)

            if self.ftp:
                ftpPush(conf, archive, topDir, self.fs)

        except (KeyboardInterrupt):

            if not self.info:
                if not self.fs:
                    # os.remove(makepage.cssfile)
                    # we should remove the css file if there aren't
                    # any other exported albums left... hard to know,
                    # may be stored in the rc file, under the Internal section.
                    # => if that's the only file in the pytof dir we should be good to go.
                    pass

                if exists(topDir):
                    rmtree(topDir)

                _err_exit("\nAborted by user")
Example #53
0
def cli(host, index_name, doc_type, import_file, mapping_file,
        id_field_idx, delete_index, quiet):
    """
    Bulk import a delimited file into a target Elasticsearch instance.
    Common delimited files include things like CSV.

    Load a CSV file:
    data2es --index-name myindex --doc-type mydoc --import-file test.csv
    """

    echo('Using host: %s' % host, quiet)
    es = Elasticsearch(hosts=[host])

    if es.indices.exists(index_name):
        echo('Index %s already exist' % index_name, False)
        if delete_index:
            es.indices.delete(index=index_name)
            echo('Deleted: %s' % index_name, quiet)
            es.indices.create(index=index_name)
            echo('Created new index: %s' % index_name, quiet)
    else:
        es.indices.create(index=index_name)
        echo('Created new index: %s' % index_name, quiet)

    echo('Using document type: %s' % doc_type, quiet)
    if mapping_file:
        echo('Applying mapping from: %s' % mapping_file, quiet)
        with open(mapping_file) as f:
            mapping = json.loads(f.read())
        es.indices.put_mapping(doc_type, mapping, [index_name,])

    action_g = docs_from_file(import_file, index_name, doc_type,
                              id_field_idx, quiet)
    helpers.bulk(es, action_g())
Example #54
0
#   GLOBALS
###
ITEMS = []

###
#   LOOK FOR CORRECT JAVA FILES
###
utils.sub("Looking for java files: ")
#utils.sub("Keywords: %s" % ', '.join(conf.ITEMS_JAVA_KEYWORDS), end='\n')
for keyword in conf.ITEMS_JAVA_KEYWORDS:
    cmd = utils.run('grep \'%s\' ./classes/*' % keyword)
    for result in cmd:
        if result and result is not '':
            java_file = os.path.basename(result.strip().split()[0][:-1])
            if java_file not in conf.ITEMS_FILES:
                utils.echo("%s " % java_file, end='')
                conf.ITEMS_FILES.append(java_file)

utils.echo('\r')

###
#   GET ITEMS INFO FROM CLASSFILE
###
utils.sub('Looking for dataz', end='\n')

# Old items for final count
try:
    OLD_ITEMS = json.loads(open('items.json').read())
except:
    OLD_ITEMS = {}
    OLD_ITEMS['list'] = []
Example #55
0
def install(args):
    """
    Install Odoo from an ikez Git repository
    :param args:
    :type args:
    :return:
    :rtype:
    """

    if not args.username:
        print "You must specify a PostgreSQL username and password that will be used by Odoo to connect to database."
        print "If this user does not exist, ikez will create it. But if this user exists with a password different "
        print "than the one provided, ikez will exit and you will have to re-launch with a valid password"
        sys.exit(1)

    # Gather answer to all questions
    if not System.postgresql_version:
        if not args.locale and System.system_name in ('debian', 'ubuntu',):  # TODO: Check for Linux, add a system_info to group all Linux distrib
            if not args.unattended:
                locale = raw_input("Enter the locale you want to install or leave blank to use '%s' ? " % System.current_locale)
                if locale:
                    args.locale = locale
            else:
                echo("ERROR: Postgresql is not installed and '--locale' parameter "
                     "is missing. Relaunch with --locale or remove --unattended.",
                     color=Fore.RED)
                sys.exit(1)

    echo("Installing Odoo server")

    # Install required system packages
    exit_code = system.install_system_dependencies(args, indent=1)
    if exit_code:
        return exit_code

    # Install PostgreSQL
    if not System.postgresql_version:
        exit_code = postgresql.install(args, indent=1)
        if exit_code:
            return exit_code

    if args.repository:
        exit_code = pretty_execute("Checking repository URL validity",
                                   ['git', 'ls-remote', args.repository],
                                   args, indent=1)
        if exit_code:
            return exit_code

        # Computing dest directory
        if not args.destination:
            args.destination = args.repository.split('/')[-1]
            # TODO: Remove .git extension

        if args.destination:
            if os.path.exists(args.destination):
                echo("ERROR: folder '%s' exists. Please remove it then relaunch ikez." % args.destination,
                     indent=1, color=Fore.RED)
                return 1
        exit_code = pretty_execute("Cloning repository '%s'" % args.repository,
                                   ['git', 'clone', args.repository, args.destination],
                                   args, indent=1)
        if exit_code:
            return exit_code

        echo("Changing current directory to '%s'" % args.destination, indent=1)
        try:
            os.chdir('./'+args.destination)
        except:
            echo("ERROR: Unable to change current directory to '%s'." % args.destination, indent=1, color=Fore.RED)
            return 1

    if not is_cwd_an_ikez_repo(args):
        print "ERROR: Current directory is not an ikez Odoo repository."
        return 1

    # assert db user exists
    exit_code = enforcing_odoo_server_database_user(args, indent=1)
    if exit_code:
        return exit_code

    if not System.virtualenv_version_ok:
        exit_code = system.install_virtualenv(args, indent=1)
        if exit_code:
            return exit_code

    #integrated in bootstrap_bildout        
    #exit_code = assert_buildout_cfg_files(args, indent=1)
    #if exit_code:
    #    return exit_code

    if not os.path.exists('bin/buildout'):
        exit_code = bootstrap_buildout(args, indent=1)
        if exit_code:
            return exit_code

    exit_code = do_buildout(args, indent=1)

    return exit_code
Example #56
0
def bootstrap_buildout(args, indent=0):
    """
    bootstrap a buildout.
    """
    echo("Bootstrapping buildout", indent=indent)

    if not args.password:
        args.password = args.username

    exit_code = assert_buildout_cfg_files(args, indent=indent+1)
    if exit_code:
        return exit_code

    # To get latest bootstrap.py use:
    #    wget https://raw.github.com/buildout/buildout/master/bootstrap/bootstrap.py
    # We download bootstrap.py as of 14/12/2014 commit = 88ad9f4 using
    # wget https://raw.githubusercontent.com/buildout/buildout/88ad9f41bfbb32330a8fd37326ab93a82a984ba1/bootstrap/bootstrap.py
    exit_code = pretty_execute("Downloading bootstrap.py",
                               ['wget', 'https://raw.githubusercontent.com/buildout/buildout/'
                                '88ad9f41bfbb32330a8fd37326ab93a82a984ba1/bootstrap/bootstrap.py'],
                               args, indent=indent+1)
    if exit_code:
        return exit_code

    exit_code = pretty_execute("Creating virtualenv",
                               ['virtualenv', 'py27', '--no-setuptools', '--no-site-packages'],
                               args, indent=indent+1)
    if exit_code:
        return exit_code

    # we want setuptools==14.1.1 and zc.buildout==2.3.1
    exit_code = pretty_execute("Bootstrapping buildout '%s'" % ('2.3.1',),
                               ['py27/bin/python', 'bootstrap.py', '--version=2.3.1'],
                               args, indent=indent+1)
    if exit_code:
        return exit_code

    exit_code = pretty_execute("Cleaning",
                               ['rm', 'bootstrap.py'],
                               args, indent=indent+1)
    if exit_code:
        return exit_code

    # by default Install pip to have a developer friendly virtualenv
    if not args.no_pip:
        echo("Installing pip in virtualenv (use --no-pip if you want a pure virtualenv)", indent+1)
        exit_code = pretty_execute("Downloading get-pip.py",
                                   ['wget', 'https://bootstrap.pypa.io/get-pip.py'],
                                   args, indent=indent+2)
        if exit_code:
            return exit_code

        # Note that as of 15/03/2015, get-pip.py do not allow to choose pip version to install.
        exit_code = pretty_execute("Running get-pip.py",
                                   ['py27/bin/python', 'get-pip.py'],
                                   args, indent=indent+2)
        if exit_code:
            return exit_code

        exit_code = pretty_execute("Deleting files",
                                   ['rm', 'get-pip.py'],
                                   args, indent=indent+1)
        if not args.no_bzr:
            exit_code = pretty_execute("Installing bzr 2.6 (use --no-bzr to prevent)",
                                       ['py27/bin/pip', 'install', 'bzr==2.6'],
                                       args, indent=indent+1)
            if exit_code:
                return exit_code

    return exit_code