Пример #1
0
    def _set_mobile_title_in_vars(self, command, vars):
        """
        Set the mobile_title into the vars dict.
        """
        mobile_title = None
        for arg in command.args:
            m = re.match("mobile_application_title=(.+)", arg)
            if m:
                mobile_title = m.group(1)
                break

        if mobile_title is None:
            prompt = "The mobile application title:"
            mobile_title = input_(prompt).strip()

        vars["mobile_application_title"] = mobile_title
Пример #2
0
    def _set_mobile_title_in_vars(self, command, vars):
        """
        Set the mobile_title into the vars dict.
        """
        mobile_title = None
        for arg in command.args:
            m = re.match("mobile_application_title=(.+)", arg)
            if m:
                mobile_title = m.group(1)
                break

        if mobile_title is None:
            prompt = "The mobile application title:"
            mobile_title = input_(prompt).strip()

        vars["mobile_application_title"] = mobile_title
Пример #3
0
    def _get_vars(vars, name, prompt, type=None):
        """
        Set an attribute in the vars dict.
        """

        value = vars.get(name)

        if value is None:
            value = input_(prompt).strip()

        if type is not None:
            try:
                type(value)
            except ValueError:
                exit("The attribute {} is not a {}".format(name, type))

        vars[name] = value
Пример #4
0
    def _get_vars(self, vars, name, prompt, type=None):
        """
        Set an attribute in the vars dict.
        """

        value = vars.get(name)

        if value is None:
            value = input_(prompt).strip()

        if type is not None:
            try:
                type(value)
            except ValueError:
                exit("The attribute {} is not a {}".format(name, type))

        vars[name] = value
Пример #5
0
 def _set_srid_in_vars(self, command, vars):
     """
     Set the SRID into the vars dict.
     """
     srid = None
     for arg in command.args:
         m = re.match('srid=(\d+)', arg)
         if m:
             srid = m.group(1)
             break
     if srid is None:
         prompt = 'Spatial Reference System Identifier ' \
                  '(e.g. 21781): '
         srid = input_(prompt).strip()
     try:
         vars['srid'] = int(srid)
     except ValueError:
         raise ValueError('Specified SRID is not an integer')
Пример #6
0
 def _set_srid_in_vars(self, command, vars):
     """
     Set the SRID into the vars dict.
     """
     srid = None
     for arg in command.args:
         m = re.match("srid=(\d+)", arg)
         if m:
             srid = m.group(1)
             break
     if srid is None:
         prompt = "Spatial Reference System Identifier " \
                  "(e.g. 21781): "
         srid = input_(prompt).strip()
     try:
         vars["srid"] = int(srid)
     except ValueError:
         raise ValueError(
             "Specified SRID is not an integer")
Пример #7
0
    def _get_vars(vars_: Dict[str, Any], name: str, prompt: str, type_: Type = None) -> None:
        """
        Set an attribute in the vars dict.
        """

        if name.upper() in os.environ and os.environ[name.upper()] != "":
            value = os.environ.get(name.upper())
        else:
            value = vars_.get(name)

        if value is None:
            value = input_(prompt).strip()

        if type_ is not None and not isinstance(value, type_):
            try:
                value = type_(value)
            except ValueError:
                print(("The attribute {}={} is not a {}".format(name, value, type_)))
                sys.exit(1)

        vars_[name] = value
Пример #8
0
    def _get_vars(vars_, name, prompt, type_=None):
        """
        Set an attribute in the vars dict.
        """

        if name.upper() in os.environ and os.environ[name.upper()] != "":
            value = os.environ[name.upper()]
        else:
            value = vars_.get(name)

        if value is None:
            value = input_(prompt).strip()

        if type_ is not None and not isinstance(value, type_):
            try:
                type_(value)
            except ValueError:
                print(("The attribute {}={} is not a {}".format(name, value, type_)))
                exit(1)

        vars_[name] = value
Пример #9
0
 def confirm_bad_name(self, prompt):  # pragma: no cover
     answer = input_('{0} [y|N]: '.format(prompt))
     return answer.strip().lower() == 'y'
Пример #10
0
 def confirm_bad_name(self, prompt):  # pragma: no cover
     answer = input_('{0} [y|N]: '.format(prompt))
     return answer.strip().lower() == 'y'
Пример #11
0
def query_interactive(src_fn, dest_fn, src_content, dest_content,
                      simulate, out_=sys.stdout):
    def out(msg):
        out_.write(msg)
        out_.write('\n')
        out_.flush()
    global all_answer
    from difflib import unified_diff, context_diff
    u_diff = list(unified_diff(
        dest_content.splitlines(),
        src_content.splitlines(),
        dest_fn, src_fn))
    c_diff = list(context_diff(
        dest_content.splitlines(),
        src_content.splitlines(),
        dest_fn, src_fn))
    added = len([l for l in u_diff if l.startswith('+')
                   and not l.startswith('+++')])
    removed = len([l for l in u_diff if l.startswith('-')
                   and not l.startswith('---')])
    if added > removed:
        msg = '; %i lines added' % (added-removed)
    elif removed > added:
        msg = '; %i lines removed' % (removed-added)
    else:
        msg = ''
    out('Replace %i bytes with %i bytes (%i/%i lines changed%s)' % (
        len(dest_content), len(src_content),
        removed, len(dest_content.splitlines()), msg))
    prompt = 'Overwrite %s [y/n/d/B/?] ' % dest_fn
    while 1:
        if all_answer is None:
            response = input_(prompt).strip().lower()
        else:
            response = all_answer
        if not response or response[0] == 'b':
            import shutil
            new_dest_fn = dest_fn + '.bak'
            n = 0
            while os.path.exists(new_dest_fn):
                n += 1
                new_dest_fn = dest_fn + '.bak' + str(n)
            out('Backing up %s to %s' % (dest_fn, new_dest_fn))
            if not simulate:
                shutil.copyfile(dest_fn, new_dest_fn)
            return True
        elif response.startswith('all '):
            rest = response[4:].strip()
            if not rest or rest[0] not in ('y', 'n', 'b'):
                out(query_usage)
                continue
            response = all_answer = rest[0]
        if response[0] == 'y':
            return True
        elif response[0] == 'n':
            return False
        elif response == 'dc':
            out('\n'.join(c_diff))
        elif response[0] == 'd':
            out('\n'.join(u_diff))
        else:
            out(query_usage)
Пример #12
0
def query_interactive(src_fn, dest_fn, src_content, dest_content,
                      simulate, out_=sys.stdout):
    def out(msg):
        out_.write(msg)
        out_.write('\n')
        out_.flush()
    global all_answer
    from difflib import unified_diff, context_diff
    u_diff = list(unified_diff(
        dest_content.splitlines(),
        src_content.splitlines(),
        dest_fn, src_fn))
    c_diff = list(context_diff(
        dest_content.splitlines(),
        src_content.splitlines(),
        dest_fn, src_fn))
    added = len([l for l in u_diff if l.startswith('+')
                   and not l.startswith('+++')])
    removed = len([l for l in u_diff if l.startswith('-')
                   and not l.startswith('---')])
    if added > removed:
        msg = '; %i lines added' % (added-removed)
    elif removed > added:
        msg = '; %i lines removed' % (removed-added)
    else:
        msg = ''
    out('Replace %i bytes with %i bytes (%i/%i lines changed%s)' % (
        len(dest_content), len(src_content),
        removed, len(dest_content.splitlines()), msg))
    prompt = 'Overwrite %s [y/n/d/B/?] ' % dest_fn
    while 1:
        if all_answer is None:
            response = input_(prompt).strip().lower()
        else:
            response = all_answer
        if not response or response[0] == 'b':
            import shutil
            new_dest_fn = dest_fn + '.bak'
            n = 0
            while os.path.exists(new_dest_fn):
                n += 1
                new_dest_fn = dest_fn + '.bak' + str(n)
            out('Backing up %s to %s' % (dest_fn, new_dest_fn))
            if not simulate:
                shutil.copyfile(dest_fn, new_dest_fn)
            return True
        elif response.startswith('all '):
            rest = response[4:].strip()
            if not rest or rest[0] not in ('y', 'n', 'b'):
                out(query_usage)
                continue
            response = all_answer = rest[0]
        if response[0] == 'y':
            return True
        elif response[0] == 'n':
            return False
        elif response == 'dc':
            out('\n'.join(c_diff))
        elif response[0] == 'd':
            out('\n'.join(u_diff))
        else:
            out(query_usage)