def runAction(self): "run wrapper for all action methods" repo, action, parent = self.repo, self.sender(), self.parent() func = action._runfunc files = [wfile for t, wfile in self.selrows if t & action._filetypes] hu = htmlui.htmlui() name = hglib.tounicode(func.__name__.title()) notify = False cwd = os.getcwd() try: os.chdir(repo.root) try: # All operations should quietly succeed. Any error should # result in a message box notify = func(parent, hu, repo, files) o, e = hu.getdata() if e: QMessageBox.warning(parent, name + _(" errors"), e) elif o: QMessageBox.information(parent, name + _(" output"), o) elif notify: wfiles = [repo.wjoin(x) for x in files] shlib.shell_notify(wfiles) except (IOError, OSError), e: err = hglib.tounicode(str(e)) QMessageBox.critical(parent, name + _(" Aborted"), err) except util.Abort, e: if e.hint: err = _("%s (hint: %s)") % (hglib.tounicode(str(e)), hglib.tounicode(e.hint)) else: err = hglib.tounicode(str(e)) QMessageBox.critical(parent, name + _(" Aborted"), err)
def update_batch(batch): '''updates thgstatus for all paths in batch''' roots, notifypaths = getrepos(batch) if roots: _ui = ui.ui(); failedroots = set() errorstream = cStringIO.StringIO() _stderr = sys.stderr sys.stderr = errorstream try: # Ensure that all unset dirstate entries can be updated. time.sleep(2) updated_any = False for r in sorted(roots): try: if shlib.update_thgstatus(_ui, r, wait=False): updated_any = True shlib.shell_notify([r], noassoc=True) logger.msg('Updated ' + r) except (IOError, OSError): print "IOError or OSError on updating %s (check permissions)" % r logger.msg('Failed updating %s (check permissions)' % r) failedroots.add(r) except (error.Abort, error.ConfigError, error.RepoError, error.RevlogError, ImportError), e: logger.msg('Failed updating %s (%s)' % (r, str(e))) failedroots.add(r) notifypaths -= failedroots if notifypaths: shlib.shell_notify(list(notifypaths), noassoc=not updated_any) logger.msg('Shell notified') errmsg = errorstream.getvalue() if errmsg: logger.msg('stderr: %s' % errmsg) finally:
def writeIgnoreFile(self): eol = self.doseoln and '\r\n' or '\n' out = eol.join(self.ignorelines) + eol hasignore = os.path.exists(self.repo.join(self.ignorefile)) try: f = util.atomictempfile(self.ignorefile, 'wb', createmode=None) f.write(out) f.close() if not hasignore: ret = qtlib.QuestionMsgBox( _('New file created'), _('TortoiseHg has created a new ' '.hgignore file. Would you like to ' 'add this file to the source code ' 'control repository?'), parent=self) if ret: commands.add(ui.ui(), self.repo, self.ignorefile) shlib.shell_notify([self.ignorefile]) self.ignoreFilterUpdated.emit() except EnvironmentError, e: qtlib.WarningMsgBox(_('Unable to write .hgignore file'), hglib.tounicode(str(e)), parent=self)
def commandFinished(self, ret): self.bb.button(QDialogButtonBox.Ok).setEnabled(True) self.statusbar.clearProgress() if ret == 0: shlib.shell_notify(self.files) self.reject() else: self._cmddialog.show()
def command_done(self, returncode, useraborted, list): if returncode == 0: shlib.shell_notify(list) self.cmd.set_result(_('Successfully'), style='ok') elif useraborted: self.cmd.set_result(_('Canceled'), style='error') else: self.cmd.set_result(_('Failed'), style='error')
def command_done(self, returncode, useraborted, src, dest): self.add_src_to_recent(src) self.add_dest_to_recent(dest) if returncode == 0: if dest: shlib.shell_notify([dest]) self.cmd.set_result(_('Cloned successfully'), style='ok') elif useraborted: self.cmd.set_result(_('Canceled updating'), style='error') else: self.cmd.set_result(_('Failed to clone'), style='error')
def hg_add(self, files): wfiles = [self.stat.repo.wjoin(x) for x in files] # Create new opts, so nothing unintented gets through addopts = self.stat.merge_opts(commands.table['^add'][1], ('include', 'exclude')) def dohgadd(): commands.add(self.stat.ui, self.stat.repo, *wfiles, **addopts) success, outtext = self.stat._hg_call_wrapper('Add', dohgadd) if success: shlib.shell_notify(wfiles) self.stat.reload_status()
def hg_revert(self, files): wfiles = [self.stat.repo.wjoin(x) for x in files] if self.stat.count_revs() > 1: gdialog.Prompt(_('Nothing Reverted'), _('Revert not allowed when viewing revision range.'), self.stat).run() return # Create new opts, so nothing unintented gets through. revertopts = self.stat.merge_opts(commands.table['revert'][1], ('include', 'exclude', 'rev')) def dohgrevert(): commands.revert(self.stat.ui, self.stat.repo, *wfiles, **revertopts) def filelist(files): text = '\n'.join(files[:5]) if len(files) > 5: text += ' ...\n' return hglib.toutf(text) if self.stat.is_merge(): res = gdialog.CustomPrompt( _('Uncommited merge - please select a parent revision'), _('Revert files to local or other parent?'), self.stat, (_('&Local'), _('&Other'), _('&Cancel')), 2).run() if res == 0: revertopts['rev'] = self.stat.repo[None].p1().rev() elif res == 1: revertopts['rev'] = self.stat.repo[None].p2().rev() else: return response = None else: # response: 0=Yes, 1=Yes,no backup, 2=Cancel revs = revertopts['rev'] if revs and type(revs) == list: revertopts['rev'] = revs[0] msg = _('Revert files to revision %s?') % revs[0] else: revertopts['rev'] = '.' msg = _('Revert files?') msg += '\n\n' msg += filelist(files) response = gdialog.CustomPrompt(_('Confirm Revert'), msg, self.stat, (_('&Yes (backup changes)'), _('Yes (&discard changes)'), _('&Cancel')), 2, 2).run() if response in (None, 0, 1): if response == 1: revertopts['no_backup'] = True success, outtext = self.stat._hg_call_wrapper('Revert', dohgrevert) if success: shlib.shell_notify(wfiles) self.stat.reload_status()
def runDialogAction(self): 'run wrapper for modal dialog action methods' repo, action, parent = self.repo, self.sender(), self.parent() func = action._runfunc files = self._filesForAction(action) notify = func(parent, self._repoagent, files) if notify: wfiles = [repo.wjoin(x) for x in files] shlib.shell_notify(wfiles) self.refreshNeeded.emit()
def revert_file(self, menuitem): 'User selected file revert from the file list context menu' rev = self.currev dialog = gdialog.Confirm(_('Confirm revert file to old revision'), [], self, _('Revert %s to contents at revision %d?') % (self.curfile, rev)) if dialog.run() == gtk.RESPONSE_NO: return cmdline = ['hg', 'revert', '--verbose', '--rev', str(rev), '--', self.curfile] dlg = hgcmd.CmdDialog(cmdline) dlg.run() dlg.hide() shlib.shell_notify([self.repo.wjoin(self.curfile)])
def writeIgnoreFile(self): eol = self.doseoln and '\r\n' or '\n' out = eol.join(self.ignorelines) + eol try: f = util.atomictempfile(self.ignorefile, 'wb', createmode=None) f.write(out) f.rename() shlib.shell_notify([self.ignorefile]) self.ignoreFilterUpdated.emit() except EnvironmentError, e: qtlib.WarningMsgBox(_('Unable to write .hgignore file'), hglib.tounicode(str(e)), parent=self)
def run(_ui, *pats, **opts): if opts.get('all'): roots = [] base = os.getcwd() for f in os.listdir(base): r = paths.find_root(os.path.join(base, f)) if r is not None: roots.append(r) for r in roots: _ui.note("%s\n" % r) shlib.update_thgstatus(_ui, r, wait=False) shlib.shell_notify([r]) return root = paths.find_root() if opts.get('repository'): root = opts.get('repository') if root is None: _ui.status("no repository\n") return repo = hg.repository(_ui, root) if opts.get('remove'): try: os.remove(cachefilepath(repo)) except OSError: pass return if opts.get('show'): try: f = open(cachefilepath(repo), 'rb') for e in f: _ui.status("%s %s\n" % (e[0], e[1:-1])) f.close() except IOError: _ui.status("*no status*\n") return wait = opts.get('delay') is not None shlib.update_thgstatus(_ui, root, wait=wait) if opts.get('notify'): shlib.shell_notify(opts.get('notify')) _ui.note("thgstatus updated\n")
def remove(args): path = args[0] logger.msg('Removing ' + path) roots, notifypaths = getrepos([path]) if roots: for r in sorted(roots): tfn = os.path.join(r, '.hg', 'thgstatus') try: f = posixfile(tfn, 'rb') e = f.readline() f.close() if not e.startswith('@@noicons'): unlink(tfn) except (IOError, OSError), e: if e.errno != errno.ENOENT: logger.msg("Error while trying to remove %s (%s)" % (tfn, e)) if notifypaths: shlib.shell_notify(list(notifypaths))
def writeIgnoreFile(self): eol = self.doseoln and '\r\n' or '\n' out = eol.join(self.ignorelines) + eol hasignore = os.path.exists(self.repo.join(self.ignorefile)) try: f = util.atomictempfile(self.ignorefile, 'wb', createmode=None) f.write(out) f.close() if not hasignore: ret = qtlib.QuestionMsgBox(_('New file created'), _('TortoiseHg has created a new ' '.hgignore file. Would you like to ' 'add this file to the source code ' 'control repository?'), parent=self) if ret: commands.add(ui.ui(), self.repo, self.ignorefile) shlib.shell_notify([self.ignorefile]) self.ignoreFilterUpdated.emit() except EnvironmentError, e: qtlib.WarningMsgBox(_('Unable to write .hgignore file'), hglib.tounicode(str(e)), parent=self)
def accept_match(self): 'User pressed "accept match" button' hglib.invalidaterepo(self.repo) wctx = self.repo[None] canmodel, upaths = self.cantree.get_selection().get_selected_rows() for path in upaths: row = canmodel[path] src, usrc, dest, udest, percent, sensitive = row if not sensitive: continue if not os.path.exists(self.repo.wjoin(src)): # Mark missing rename source as removed wctx.remove([src]) wctx.copy(src, dest) shlib.shell_notify([self.repo.wjoin(src), self.repo.wjoin(dest)]) if self.notify_func: self.notify_func() # Mark all rows with this target file as non-sensitive for row in canmodel: if row[2] == dest: row[5] = False self.refresh()
def runAction(self): 'run wrapper for all action methods' repo, action, parent = self.repo, self.sender(), self.parent() func = action._runfunc files = [wfile for t, wfile in self.selrows if t & action._filetypes] hu = htmlui.htmlui() name = hglib.tounicode(func.__name__.title()) notify = False cwd = os.getcwd() try: os.chdir(repo.root) try: # All operations should quietly succeed. Any error should # result in a message box notify = func(parent, hu, repo, files) o, e = hu.getdata() if e: QMessageBox.warning(parent, name + _(' errors'), hglib.tounicode(e)) elif o: QMessageBox.information(parent, name + _(' output'), hglib.tounicode(o)) elif notify: wfiles = [repo.wjoin(x) for x in files] shlib.shell_notify(wfiles) except (IOError, OSError), e: err = hglib.tounicode(str(e)) QMessageBox.critical(parent, name + _(' Aborted'), err) except util.Abort, e: if e.hint: err = _('%s (hint: %s)') % (hglib.tounicode( str(e)), hglib.tounicode(e.hint)) else: err = hglib.tounicode(str(e)) QMessageBox.critical(parent, name + _(' Aborted'), err)
def _notifyChanges(self): # include all selected files for maximum possibility wfiles = [hglib.fromunicode(fd.absoluteFilePath()) for fd in self._selfds] shlib.shell_notify(wfiles) self.refreshNeeded.emit()
def _notify(self, ret, *args): time.sleep(0.5) # give fs some time to pick up changes shlib.shell_notify([self.repo.root])
def commandFinished(self, ret): self.bb.button(QDialogButtonBox.Ok).setEnabled(True) if ret == 0: shlib.shell_notify(self.files) self.reject()
def commandFinished(self, ret): if ret == 0: shlib.shell_notify(self.files) sys.exit(0)
l = [] model = gtk.ListStore(str) self.ignorelines = [] for line in l: model.append([hglib.toutf(line.strip())]) self.ignorelines.append(line.strip()) self.pattree.set_model(model) def write_ignore_lines(self): if self.doseoln: out = [line + '\r\n' for line in self.ignorelines] else: out = [line + '\n' for line in self.ignorelines] try: f = util.atomictempfile(self.ignorefile, 'wb', createmode=None) f.writelines(out) f.rename() except EnvironmentError, e: dialog.error_dialog(self, _('Unable to write .hgignore file'), hglib.tounicode(str(e))) shlib.shell_notify([self.ignorefile]) if self.notify_func: self.notify_func() def run(_ui, *pats, **opts): if pats and pats[0].endswith('.hgignore'): pats = [] return HgIgnoreDialog(*pats)
def commandFinished(self, ret): if ret == 0: shlib.shell_notify(self.files) sys.exit(0) else: self._cmddialog.show()