Exemplo n.º 1
0
 def run(self):
     """
     Main worker.
     """
     update_name = None  # Store update name, i.e: Eddy v0.9.1
     update_version = self.current  # Store update version, i.e: 0.9.1
     update_url = None  # Store update HTML url, i.e: http://github.com/...
     try:
         LOGGER.info(
             'Connecting to GitHub to retrieve update information (channel: %s)',
             self.channel.value)
         github = GitHub(token='6a417ccfe9a7c526598e77a74cbf1cba6e688f0e')
         repository = github.repository('danielepantaleone', 'eddy')
         for release in repository.releases():
             if self.channel is Channel.Beta or not release.prerelease:
                 try:
                     if NormalizedVersion(
                             release.tag_name[1:]) > NormalizedVersion(
                                 update_version):
                         update_name = release.name
                         update_version = release.tag_name[1:]
                         update_url = release.html_url
                 except IrrationalVersionError as e:
                     LOGGER.warning(
                         'Failed to parse version number from TAG: %s', e)
         if update_version != self.current:
             LOGGER.info('Update available: %s', update_name)
             self.sgnUpdateAvailable.emit(update_name, update_url)
         else:
             LOGGER.info('No update available')
             self.sgnNoUpdateAvailable.emit()
     except Exception as e:
         LOGGER.warning('Failed to retrieve update data: %s', e)
         self.sgnNoUpdateDataAvailable.emit()
     self.finished.emit()
Exemplo n.º 2
0
    def validate(self, **kwargs):
        if not (self.MIN_VERSION and self.MAX_VERSION):
            warnings.warn(
                "Capsule '%s' does not specify compatible which "
                "taskwarrior-capsule versions it is compatible with; you may "
                "encounter compatibility problems. " % (self.command_name))
        else:
            curr_version = self.get_taskwarrior_capsules_version()
            min_version = NormalizedVersion(self.MIN_VERSION)
            max_version = NormalizedVersion(self.MAX_VERSION)

            if not min_version <= curr_version <= max_version:
                warnings.warn(
                    "Capsule '%s' is not compatible with version %s of "
                    "taskwarrior-capsules; "
                    "minimum version: %s; "
                    "maximum version %s." % (
                        self.command_name,
                        __version__,
                        min_version,
                        max_version,
                    ), )

        if not self.TASKWARRIOR_VERSION_CHECK_NECESSARY:
            # Let's just continue on without checking taskwarrior
            # version compatibility.
            pass
        elif not (self.MAX_TASKWARRIOR_VERSION
                  and self.MIN_TASKWARRIOR_VERSION):
            warnings.warn(
                "Capsule '%s' does not specify which taskwarrior versions it "
                "is compatible with; you may encounter compatibility "
                "problems. " % (self.command_name))
        else:
            tw_version = self.get_taskwarrior_version()
            min_tw_version = NormalizedVersion(self.MIN_TASKWARRIOR_VERSION)
            max_tw_version = NormalizedVersion(self.MAX_TASKWARRIOR_VERSION)

            if not min_tw_version <= tw_version <= max_tw_version:
                warnings.warn(
                    "Capsule '%s' is not compatible with version %s of "
                    "taskwarrior; "
                    "minimum version: %s; "
                    "maximum version %s." % (
                        self.command_name,
                        tw_version,
                        min_tw_version,
                        max_tw_version,
                    ), )

        return True
Exemplo n.º 3
0
def get_git_version():
    result = subprocess.check_output(
        ['git', '--version'],
        stderr=subprocess.PIPE,
    ).decode('utf8')
    version_string = re.match('git version ([0-9.]+).*', result).group(1)
    return NormalizedVersion(version_string)
Exemplo n.º 4
0
def ensure_default_settings(config):
    version = NormalizedVersion(__version__)
    if 'version' in config:
        config_version = NormalizedVersion(config['version'])
    else:
        config_version = NormalizedVersion('0.1')

    for section, values in DEFAULT_SETTINGS.items():
        if section not in config:
            config[section] = {}
        for key, value in values.items():
            if key not in config[section] or version > config_version:
                config[section][key] = value

    config['version'] = __version__
    return config
Exemplo n.º 5
0
 def version(self):
     """
     Returns the version of the reasoner.
     :rtype: NormalizedVersion
     """
     return NormalizedVersion(self.spec.get('reasoner', 'version'))
Exemplo n.º 6
0
 def version(self):
     """
     Returns the version of the plugin.
     :rtype: NormalizedVersion
     """
     return NormalizedVersion(self.spec.get('plugin', 'version'))
Exemplo n.º 7
0
 def get_taskwarrior_capsules_version(self):
     return NormalizedVersion(__version__)
Exemplo n.º 8
0
 def get_taskwarrior_version(self):
     taskwarrior_version = subprocess.Popen(
         ['task', '--version'], stdout=subprocess.PIPE).communicate()[0]
     return NormalizedVersion(taskwarrior_version)
Exemplo n.º 9
0
def main():
    term = Terminal()
    if sys.version_info < (2, 7):
        raise RuntimeError(
            "Jirafs requires minimally version 2.7 of Python 2, or "
            "any version of Python 3.  Please upgrade your version of "
            "python before using Jirafs.")
    if utils.get_git_version() < NormalizedVersion('1.8'):
        raise RuntimeError(
            "Jirafs requires minimally version 1.8 of Git.  Please "
            "upgrade your version of git before using Jirafs.")

    commands = utils.get_installed_commands()

    parser = argparse.ArgumentParser(
        description='Edit Jira issues locally from your filesystem',
        add_help=False,
    )
    parser.add_argument('command', type=six.text_type, choices=commands.keys())
    parser.add_argument('--subtasks', action='store_true', default=False)
    parser.add_argument(
        '--log-level',
        default=None,
        dest='log_level',
    )
    parser.add_argument('--folder', default=os.getcwd())
    parser.add_argument(
        '--no-subfolders',
        action='store_true',
        default=False,
    )
    parser.add_argument(
        '--traceback',
        action='store_true',
        default=False,
    )
    args, extra = parser.parse_known_args()

    if args.log_level is not None:
        logging.basicConfig(level=logging.getLevelName(args.log_level))

    command_name = args.command
    cmd_class = commands[command_name]

    # Subtasks
    if args.subtasks:
        cmd_class.RUN_FOR_SUBTASKS = True

    started = time.time()
    logger.debug('Command %s(%s) started', command_name, extra)
    jira = utils.lazy_get_jira()
    try:
        value = cmd_class.execute_command(extra,
                                          jira=jira,
                                          path=args.folder,
                                          command_name=command_name)
        logger.debug('Command %s(%s) finished in %s seconds', command_name,
                     extra, (time.time() - started))
        if value:
            value.echo()
        sys.exit(value.return_code)
    except GitCommandError as e:
        print(u"{t.red}Error (code: {code}) while running git "
              u"command.{t.normal}".format(t=term, code=e.returncode))
        print("")
        print(u"{t.red}Command:{t.normal}{t.red}{t.bold}".format(t=term))
        print(u"    {cmd}".format(cmd=e.command))
        print(u"{t.normal}".format(t=term))
        print(u"{t.red}Output:{t.normal}{t.red}{t.bold}".format(t=term))
        for line in e.output.decode('utf8').split('\n'):
            print(u"    %s" % line)
        print(u"{t.normal}".format(t=term))
        if args.traceback:
            traceback.print_exc()
        sys.exit(10)
    except NotTicketFolderException:
        if not getattr(cmd_class, 'TRY_SUBFOLDERS', False):
            print(u"{t.red}The command '{cmd}' must be ran from "
                  u"within an issue folder.{t.normal}".format(
                      t=term, cmd=command_name))
            sys.exit(20)
        elif args.no_subfolders:
            sys.exit(20)

        count_runs = 0
        for folder in os.listdir(os.getcwd()):
            full_path = os.path.join(
                os.getcwd(),
                folder,
            )
            if not os.path.isdir(full_path):
                continue

            try:
                full_args = copy.copy(sys.argv)
                if '--no-subfolders' not in full_args:
                    full_args.append('--no-subfolders')
                result = subprocess.call(' '.join(
                    [shlex_quote(a) for a in full_args]),
                                         cwd=full_path,
                                         shell=True)
                if result == 0:
                    count_runs += 1
            except NotTicketFolderException:
                pass
        if count_runs == 0:
            if args.traceback:
                traceback.print_exc()
            sys.exit(21)
    except JIRAError as e:
        print(u"{t.red}Jirafs encountered an error while interacting with "
              u"your JIRA instance: {t.normal}{t.red}{t.bold}{error}"
              u"{t.normal}".format(t=term, error=str(e)))
        if args.traceback:
            traceback.print_exc()
        sys.exit(70)
    except JiraInteractionFailed as e:
        print(u"{t.red}JIRA was unable to satisfy your "
              u"request: {t.normal}{t.red}{t.bold}{error}{t.normal}".format(
                  t=term, error=str(e)))
        if args.traceback:
            traceback.print_exc()
        sys.exit(80)
    except JirafsError as e:
        print(u"{t.red}Jirafs encountered an error processing your "
              u"request: {t.normal}{t.red}{t.bold}{error}{t.normal}".format(
                  t=term, error=str(e)))
        if args.traceback:
            traceback.print_exc()
        sys.exit(90)