artemis.py
changeset 24 17a8293bbbbf
parent 21 5b3579dc7abf
child 26 4574d2d34009
equal deleted inserted replaced
23:a42b9c661bc1 24:17a8293bbbbf
    10 state = {'new': 'new', 'fixed': 'fixed'}
    10 state = {'new': 'new', 'fixed': 'fixed'}
    11 state['default'] = state['new']
    11 state['default'] = state['new']
    12 issues_dir = ".issues"
    12 issues_dir = ".issues"
    13 filter_prefix = ".filter"
    13 filter_prefix = ".filter"
    14 date_format = '%a, %d %b %Y %H:%M:%S'
    14 date_format = '%a, %d %b %Y %H:%M:%S'
       
    15 maildir_dirs = ['new','cur','tmp']
    15 
    16 
    16 
    17 
    17 def ilist(ui, repo, **opts):
    18 def ilist(ui, repo, **opts):
    18     """List issues associated with the project"""
    19     """List issues associated with the project"""
    19 
    20 
    27     # Find issues
    28     # Find issues
    28     issues_path = os.path.join(repo.root, issues_dir)
    29     issues_path = os.path.join(repo.root, issues_dir)
    29     if not os.path.exists(issues_path): return
    30     if not os.path.exists(issues_path): return
    30 
    31 
    31     issues = glob.glob(os.path.join(issues_path, '*'))
    32     issues = glob.glob(os.path.join(issues_path, '*'))
       
    33 
       
    34     # Create missing dirs
       
    35     for i in issues:
       
    36         for d in maildir_dirs:
       
    37             path = os.path.join(issues_path,i,d)
       
    38             if not os.path.exists(path): os.mkdir(path)
    32 
    39 
    33     # Process filter
    40     # Process filter
    34     if opts['filter']:
    41     if opts['filter']:
    35         filters = glob.glob(os.path.join(issues_path, filter_prefix + '*'))
    42         filters = glob.glob(os.path.join(issues_path, filter_prefix + '*'))
    36         config = ConfigParser.SafeConfigParser()
    43         config = ConfigParser.SafeConfigParser()
    70     if id:
    77     if id:
    71         issue_fn, issue_id = _find_issue(ui, repo, id)
    78         issue_fn, issue_id = _find_issue(ui, repo, id)
    72         if not issue_fn:
    79         if not issue_fn:
    73             ui.warn('No such issue\n')
    80             ui.warn('No such issue\n')
    74             return
    81             return
       
    82         for d in maildir_dirs:
       
    83             path = os.path.join(issues_path,issue_id,d)
       
    84             if not os.path.exists(path): os.mkdir(path)
    75 
    85 
    76     user = ui.username()
    86     user = ui.username()
    77 
    87 
    78     default_issue_text  =         "From: %s\nDate: %s\n" % (user, util.datestr(format = date_format))
    88     default_issue_text  =         "From: %s\nDate: %s\n" % (user, util.datestr(format = date_format))
    79     if not id:
    89     if not id:
    80         default_issue_text +=     "State: %s\n" % state['default']
    90         default_issue_text +=     "State: %s\n" % state['default']
    81     default_issue_text +=        "Subject: brief description\n\n"
    91     default_issue_text +=         "Subject: brief description\n\n"
    82     default_issue_text +=         "Detailed description."
    92     default_issue_text +=         "Detailed description."
    83 
    93 
    84     issue = ui.edit(default_issue_text, user)
    94     issue = ui.edit(default_issue_text, user)
    85     if issue.strip() == '':
    95     if issue.strip() == '':
    86         ui.warn('Empty issue, ignoring\n')
    96         ui.warn('Empty issue, ignoring\n')
   127     """Shows issue ID, or possibly its comment COMMENT"""
   137     """Shows issue ID, or possibly its comment COMMENT"""
   128 
   138 
   129     comment = int(comment)
   139     comment = int(comment)
   130     issue, id = _find_issue(ui, repo, id)
   140     issue, id = _find_issue(ui, repo, id)
   131     if not issue: return
   141     if not issue: return
       
   142     
       
   143     # Create missing dirs
       
   144     for d in maildir_dirs:
       
   145         path = os.path.join(repo.root,issues_dir,issue,d)
       
   146         if not os.path.exists(path): os.mkdir(path)
       
   147 
   132     mbox = mailbox.Maildir(issue, factory=mailbox.MaildirMessage)
   148     mbox = mailbox.Maildir(issue, factory=mailbox.MaildirMessage)
   133 
   149 
   134     if opts['all']:
   150     if opts['all']:
   135         ui.write('='*70 + '\n')
   151         ui.write('='*70 + '\n')
   136         i = 0
   152         i = 0
   147 def iupdate(ui, repo, id, **opts):
   163 def iupdate(ui, repo, id, **opts):
   148     """Update properties of issue ID"""
   164     """Update properties of issue ID"""
   149 
   165 
   150     issue, id = _find_issue(ui, repo, id)
   166     issue, id = _find_issue(ui, repo, id)
   151     if not issue: return
   167     if not issue: return
       
   168     
       
   169     # Create missing dirs
       
   170     for d in maildir_dirs:
       
   171         path = os.path.join(repo.root,issues_dir,issue,d)
       
   172         if not os.path.exists(path): os.mkdir(path)
       
   173 
   152 
   174 
   153     properties = _get_properties(opts['property'])
   175     properties = _get_properties(opts['property'])
   154 
   176 
   155     # Read the issue
   177     # Read the issue
   156     mbox = mailbox.Maildir(issue, factory=mailbox.MaildirMessage)
   178     mbox = mailbox.Maildir(issue, factory=mailbox.MaildirMessage)
   175                             (user, util.datestr(format = date_format),
   197                             (user, util.datestr(format = date_format),
   176                              _pretty_list(list(set([property for property, value in properties]))),
   198                              _pretty_list(list(set([property for property, value in properties]))),
   177                              properties_text)
   199                              properties_text)
   178         msg = mailbox.mboxMessage(properties_text)
   200         msg = mailbox.mboxMessage(properties_text)
   179         msg.add_header('Message-Id', "<%s-%s-artemis@%s>" % (id, _random_id(), socket.gethostname()))
   201         msg.add_header('Message-Id', "<%s-%s-artemis@%s>" % (id, _random_id(), socket.gethostname()))
   180         msg.add_header('References', mbox[0]['Message-Id'])
   202         msg.add_header('References', mbox[root]['Message-Id'])
   181         msg.add_header('In-Reply-To', mbox[0]['Message-Id'])
   203         msg.add_header('In-Reply-To', mbox[root]['Message-Id'])
   182         #msg.set_from('artemis', True)
   204         #msg.set_from('artemis', True)
   183         repo.add([issue_fn[(len(repo.root)+1):] + '/new/'  + mbox.add(msg)])   # +1 for the trailing /
   205         repo.add([issue[(len(repo.root)+1):] + '/new/'  + mbox.add(msg)])   # +1 for the trailing /
   184     mbox.close()
   206     mbox.close()
   185 
   207 
   186     # Show updated message
   208     # Show updated message
   187     _show_mbox(ui, mbox, 0)
   209     _show_mbox(ui, mbox, 0)
   188 
   210