Mercurial and Git clients can push and pull from this alias URL to interact with this repository. You can change to which repository an alias points by going to the Aliases link on the project page.
# hgemail.py - TortoiseHg's dialog for sending patches via email## Copyright 2007 TK Soh <teekaysoh@gmail.com># Copyright 2007 Steve Borho <steve@borho.org># Copyright 2010 Yuya Nishihara <yuya@tcha.org>## This software may be used and distributed according to the terms of the# GNU General Public License version 2, incorporated herein by reference.importos,tempfile,refromStringIOimportStringIOfromPyQt4.QtCoreimportQt,pyqtSlot,QAbstractTableModel,QVariant,QModelIndexfromPyQt4.QtGuiimportQDialogfrommercurialimporthg,error,extensions,utilfromtortoisehg.utilimporthglib,pathsfromtortoisehg.hgqt.i18nimport_fromtortoisehg.hgqtimportcmdui,lexerstry:fromtortoisehg.hgqt.ui_hgemailimportUi_EmailDialogexceptImportError:fromPyQt4importuicUi_EmailDialog=uic.loadUiType(os.path.join(os.path.dirname(__file__),'hgemail.ui'))[0]classEmailDialog(QDialog):"""Dialog for sending patches via email"""def__init__(self,ui,repo,revs,parent=None):super(EmailDialog,self).__init__(parent)self._ui=uiself._repo=repoself._revs=revsself._qui=Ui_EmailDialog()self._qui.setupUi(self)self._qui.bundle_radio.setEnabled(False)# TODO: bundle supportself._qui.settings_button.setEnabled(False)# TODO: open settings dialogchangesets=_ChangesetsModel(self._repo,self._revs,parent=self)self._qui.changesets_view.setModel(changesets)self._initpreviewtab()self._initintrobox()self._filldefaults()self._connectvalidateform()self._validateform()defkeyPressEvent(self,event):# don't send email by just hitting enterifevent.key()in(Qt.Key_Return,Qt.Key_Enter):ifevent.modifiers()==Qt.ControlModifier:self.accept()# Ctrl+Enterreturnreturnsuper(EmailDialog,self).keyPressEvent(event)def_filldefaults(self):"""Fill form by default values"""defgetfromaddr(ui):"""Get sender address in the same manner as patchbomb"""addr=ui.config('email','from')orui.config('patchbomb','from')ifaddr:returnaddrtry:returnui.username()excepterror.Abort:return''# TODO: ui.config's encoding?self._qui.to_edit.setText(self._ui.config('email','to',''))self._qui.cc_edit.setText(self._ui.config('email','cc',''))self._qui.from_edit.setText(getfromaddr(self._ui))self.setdiffformat(self._ui.configbool('diff','git')and'git'or'hg')defsetdiffformat(self,format):"""Set diff format, 'hg', 'git' or 'plain'"""try:radio=getattr(self._qui,'%spatch_radio'%format)exceptAttributeError:raiseValueError('unknown diff format: %r'%format)radio.setChecked(True)defgetdiffformat(self):"""Selected diff format"""foreinself._qui.patch_frame.children():m=re.match(r'(\w+)patch_radio',str(e.objectName()))ifmande.isChecked():returnm.group(1)return'hg'defgetextraopts(self):"""Dict of extra options"""opts={}foreinself._qui.extra_frame.children():m=re.match(r'(\w+)_check',str(e.objectName()))ifm:opts[m.group(1)]=e.isChecked()returnoptsdef_patchbombopts(self,**opts):"""Generate opts for patchbomb by form values"""opts['to']=[hglib.fromunicode(self._qui.to_edit.text())]opts['cc']=[hglib.fromunicode(self._qui.cc_edit.text())]opts['from']=hglib.fromunicode(self._qui.from_edit.text())opts['in_reply_to']=hglib.fromunicode(self._qui.inreplyto_edit.text())opts['flag']=[hglib.fromunicode(self._qui.flag_edit.text())]defdiffformat():n=self.getdiffformat()ifn=='hg':return{}else:return{n:True}opts.update(diffformat())opts.update(self.getextraopts())defwritetempfile(s):fd,fname=tempfile.mkstemp(prefix='thg_emaildesc_')try:os.write(fd,s)returnfnamefinally:os.close(fd)opts['intro']=self._qui.writeintro_check.isChecked()ifopts['intro']:opts['subject']=hglib.fromunicode(self._qui.subject_edit.text())opts['desc']=writetempfile(hglib.fromunicode(self._qui.body_edit.toPlainText()))# TODO: change patchbomb not to use temporary filereturnoptsdef_isvalid(self):"""Filled all required values?"""req=['to_edit','from_edit']ifself._qui.writeintro_check.isChecked():req.append('subject_edit')foreinreq:ifnotgetattr(self._qui,e).text():returnFalse# TODO: is it nice if we can choose revisions to send?ifnotself._revs:returnFalsereturnTrue@pyqtSlot()def_validateform(self):"""Check form values to update send/preview availability"""valid=self._isvalid()self._qui.send_button.setEnabled(valid)self._qui.main_tabs.setTabEnabled(self._previewtabindex(),valid)def_connectvalidateform(self):# TODO: connect programmaticallyforein('to_edit','from_edit','subject_edit'):getattr(self._qui,e).textChanged.connect(self._validateform)self._qui.writeintro_check.toggled.connect(self._validateform)defaccept(self):# TODO: want to pass patchbombopts directlydefcmdargs(opts):args=[]fork,vinopts.iteritems():ifisinstance(v,bool):ifv:args.append('--%s'%k.replace('_','-'))else:foreinisinstance(v,basestring)and[v]orv:args+=['--%s'%k.replace('_','-'),e]returnargshglib.loadextension(self._ui,'patchbomb')opts=self._patchbombopts()try: cmd = cmdui.Dialog(['email'] + cmdargs(opts) + list(self._revs),
parent=self)
cmd.setWindowTitle(_('Sending Email'))
+ cmd.show_output(False) if cmd.exec_():
super(EmailDialog, self).accept()
finally:
if'desc'inopts:os.unlink(opts['desc'])# TODO: don't use tempfiledef_initintrobox(self):self._qui.intro_box.hide()# hidden by defaultifself._introrequired():self._qui.writeintro_check.setChecked(True)self._qui.writeintro_check.setEnabled(False)def_introrequired(self):"""Is intro message required?"""returnlen(self._revs)>1def_initpreviewtab(self):definitqsci(w):w.setUtf8(True)w.setReadOnly(True)w.setMarginWidth(1,0)# hide area for line numbersw.setLexer(lexers.DiffLexerSelector().lexer())# TODO: better way to setup diff lexerinitqsci(self._qui.preview_edit)self._qui.main_tabs.currentChanged.connect(self._refreshpreviewtab)self._refreshpreviewtab(self._qui.main_tabs.currentIndex())@pyqtSlot(int)def_refreshpreviewtab(self,index):"""Generate preview text if current tab is preview"""ifself._previewtabindex()!=index:returnself._qui.preview_edit.setText(self._preview())def_preview(self):"""Generate preview text by running patchbomb"""defloadpatchbomb():hglib.loadextension(self._ui,'patchbomb')returnextensions.find('patchbomb')defwrapui(ui):buf=StringIO()# TODO: common way to prepare pure uinewui=ui.copy()newui.setconfig('ui','interactive',False)newui.setconfig('diff','git',False)newui.write=lambda*args,**opts:buf.write(''.join(args))newui.status=lambda*args,**opts:Nonereturnnewui,bufdefstripheadmsg(s):# TODO: skip until first Content-type: line ??return'\n'.join(s.splitlines()[3:])ui,buf=wrapui(self._ui)opts=self._patchbombopts(test=True)try:# TODO: fix hgext.patchbomb's implementation insteadif'PAGER'inos.environ:delos.environ['PAGER']loadpatchbomb().patchbomb(ui,self._repo,*self._revs,**opts)returnstripheadmsg(hglib.tounicode(buf.getvalue()))finally:if'desc'inopts:os.unlink(opts['desc'])# TODO: don't use tempfiledef_previewtabindex(self):"""Index of preview tab"""returnself._qui.main_tabs.indexOf(self._qui.preview_tab)class_ChangesetsModel(QAbstractTableModel):# TODO: use component of log viewer?_COLUMNS=[('rev',lambdactx:'%d:%s'%(ctx.rev(),ctx)),('author',lambdactx:hglib.username(ctx.user())),('date',lambdactx:util.shortdate(ctx.date())),('description',lambdactx:ctx.description().splitlines()[0])]def__init__(self,repo,revs,parent=None):super(_ChangesetsModel,self).__init__(parent)self._repo=repoself._revs=revsdefdata(self,index,role):if(notindex.isValid())orrole!=Qt.DisplayRole:returnQVariant()coldata=self._COLUMNS[index.column()][1]rev=self._revs[index.row()]returnQVariant(hglib.tounicode(coldata(self._repo[rev])))defrowCount(self,parent=QModelIndex()):returnlen(self._revs)defcolumnCount(self,parent=QModelIndex()):returnlen(self._COLUMNS)defheaderData(self,section,orientation,role):ifrole!=Qt.DisplayRoleororientation!=Qt.Horizontal:returnQVariant()returnQVariant(self._COLUMNS[section][0].capitalize())defrun(ui,*revs,**opts):# TODO: same options as patchbomb# TODO: repo should be specified as an argument?# TODO: if no revs specified?repo=hg.repository(ui,paths.find_root())returnEmailDialog(repo.ui,repo,revs)
Attach a Trello Card
Add a tag
Your session has expired
You are no longer logged in. Please log in and try your request again.
Filter RSS Feed
This RSS feed URL allows you to see the contents of your current filter using any feed reader.
This link includes a special authentication token. If you share the URL with anyone else, they can see this RSS feed's activity. You can disable these tokens when needed.
Your current filter is unsaved; changing it won't affect this RSS feed.