Note that there are some explanatory texts on larger screens.

plurals
  1. POUse Class and Class methods from another class in python
    primarykey
    data
    text
    <p>I have couple of classes in jira.py, providing 2 for sample</p> <pre><code>class JiraCommand: name = "&lt;default&gt;" aliases = [] summary = "&lt;--- no summary ---&gt;" usage = "" mandatory = "" commands = None def __init__(self, commands): self.commands = commands def dispatch(self, logger, jira_env, args): """Return the exit code of the whole process""" if len(args) &gt; 0 and args[0] in ("--help", "-h"): logger.info("") alias_text = '' first_alias = True for a in self.aliases: if first_alias: if len(self.aliases) == 1: alias_text = " (alias: " + a else: alias_text = " (aliases: " + a first_alias = False else: alias_text += ", " + a if not first_alias: alias_text += ")" logger.info("%s: %s%s" % (self.name, self.summary, alias_text)) if self.usage == "": opts = "" else: opts = " [options]" logger.info("") logger.info("Usage: %s %s %s%s" % \ (sys.argv[0], self.name, self.mandatory, opts)) logger.info(self.usage) return 0 results = self.run(logger, jira_env, args) if results: return self.render(logger, jira_env, args, results) else: return 1 def run(self, logger, jira_env, args): """Return a non-zero object for success""" return 0 def render(self, logger, jira_env, args, results): """Return 0 for success""" return 0 </code></pre> <p>and a second class in the same file "jira.py"</p> <pre><code>class JiraCat(JiraCommand): name = "cat" summary = "Show all the fields in an issue" usage = """ &lt;issue key&gt; Issue identifier, e.g. CA-1234 """ def run(self, logger, jira_env, args): global soap, auth if len(args) != 1: logger.error(self.usage) return 0 issueKey = args[0] try: jira_env['fieldnames'] = soap.service.getFieldsForEdit(auth, issueKey) except Exception, e: # In case we don't have edit permission jira_env['fieldnames'] = {} try: return soap.service.getIssue(auth, issueKey) except Exception, e: logger.error(decode(e)) def render(self, logger, jira_env, args, results): # For available field names, see the variables in # src/java/com/atlassian/jira/rpc/soap/beans/RemoteIssue.java fields = jira_env['fieldnames'] for f in ['key','summary','reporter','assignee','description', 'environment','project', 'votes' ]: logger.info(getName(f, fields) + ': ' + encode(results[f])) logger.info('Type: ' + getName(results['type'], jira_env['types'])) logger.info('Status: ' + getName(results['status'], jira_env['statuses'])) logger.info('Priority: ' + getName(results['priority'], jira_env['priorities'])) logger.info('Resolution: ' + getName(results['resolution'], jira_env['resolutions'])) for f in ['created', 'updated', 'duedate' ]: logger.info(getName(f, fields) + ': ' + dateStr(results[f])) for f in results['components']: logger.info(getName('components', fields) + ': ' + encode(f['name'])) for f in results['affectsVersions']: logger.info(getName('versions', fields) + ': ' + encode(f['name'])) for f in results['fixVersions']: logger.info('Fix Version/s:' + encode(f['name'])) # TODO bug in JIRA api - attachmentNames are not returned #logger.info(str(results['attachmentNames'])) # TODO restrict some of the fields that are shown here for f in results['customFieldValues']: fieldName = str(f['customfieldId']) for v in f['values']: logger.info(getName(fieldName, fields) + ': ' + encode(v)) return 0 </code></pre> <p>Now, JiraCat is using JiraCommand as an argument</p> <p>How can i use JiraCat to get live results</p> <p>here is what i tried:</p> <pre><code>&gt;&gt;&gt; from jira import JiraCommand &gt;&gt;&gt; dir(JiraCommand) ['__doc__', '__init__', '__module__', 'aliases', 'commands', 'dispatch', 'mandatory', 'name', 'render', 'run', 'summary', 'usage'] &gt;&gt;&gt; jcmd = JiraCommand("http://jira.server.com:8080") &gt;&gt;&gt; from jira import JiraCat &gt;&gt;&gt; dir(JiraCat) ['__doc__', '__init__', '__module__', 'aliases', 'commands', 'dispatch', 'mandatory', 'name', 'render', 'run', 'summary', 'usage'] &gt;&gt;&gt; jc = JiraCat(jcmd) &gt;&gt;&gt; print jc &lt;jira.JiraCat instance at 0x2356d88&gt; &gt;&gt;&gt; jc.run("-s", "cat", "QA-65") Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "jira.py", line 163, in run logger.error(self.usage) AttributeError: 'str' object has no attribute 'error' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload