def __init__(self, filenames): Command.__init__(self) self.new_mode = self.model.mode_untracked try: self.new_diff_text = utils.slurp(filenames[0]) except: self.new_diff_text = ''
def __init__(self, filenames): Command.__init__(self) self.new_mode = self.model.mode_untracked try: self.new_diff_text = utils.slurp(filenames[0]) except: self.new_diff_text = ""
def do(self): path = self.path if not path or not os.path.isfile(path): raise errors.UsageError('Error: cannot find commit template', '%s: No such file or directory.' % path) self.model.set_directory(os.path.dirname(path)) self.model.set_commitmsg(utils.slurp(path))
def current_branch(): """Find the current branch.""" head = git.git_path('HEAD') try: data = utils.slurp(head) if _current_branch.data == data: return _current_branch.value except OSError, e: pass
def diff_text_for(self, filename): size = _config.get('cola.readsize', 1024 * 2) try: result = utils.slurp(filename, size=size) except: result = '' if len(result) == size: result += '...' return result
def diff_text_for(self, filename): size = _config.get("cola.readsize", 1024 * 2) try: result = utils.slurp(filename, size=size) except: result = "" if len(result) == size: result += "..." return result
def do(self): new_additions = "" for fname in self.filenames: new_additions = new_additions + fname + "\n" for_status = new_additions if new_additions: if os.path.exists(".gitignore"): current_list = utils.slurp(".gitignore") new_additions = new_additions + current_list utils.write(".gitignore", new_additions) _notifier.broadcast(signals.log_cmd, 0, "Added to .gitignore:\n%s" % for_status) self.model.update_file_status()
def do(self): new_additions = "" for fname in self.filenames: new_additions = new_additions + fname + "\n" for_status = new_additions if new_additions: if os.path.exists(".gitignore"): current_list = utils.slurp(".gitignore") new_additions = new_additions + current_list utils.write(".gitignore", new_additions) Interaction.log_status(0, "Added to .gitignore:\n%s" % for_status, "") self.model.update_file_status()
def do(self): new_additions = '' for fname in self.filenames: new_additions = new_additions + fname + '\n' for_status = new_additions if new_additions: if os.path.exists('.gitignore'): current_list = utils.slurp('.gitignore') new_additions = new_additions + current_list utils.write('.gitignore', new_additions) Interaction.log_status( 0, 'Added to .gitignore:\n%s' % for_status, '') self.model.update_file_status()
def do(self): new_additions = '' for fname in self.filenames: new_additions = new_additions + fname + '\n' for_status = new_additions if new_additions: if os.path.exists('.gitignore'): current_list = utils.slurp('.gitignore') new_additions = new_additions + current_list utils.write('.gitignore', new_additions) Interaction.log_status(0, 'Added to .gitignore:\n%s' % for_status, '') self.model.update_file_status()
def do(self): new_additions = '' for fname in self.filenames: new_additions = new_additions + fname + '\n' for_status = new_additions if new_additions: if '.gitignore' in gitcmds.all_files(): current_list = utils.slurp('.gitignore') new_additions = new_additions + current_list utils.write('.gitignore', new_additions) _notifier.broadcast(signals.log_cmd, 0, 'Added to .gitignore:\n%s' % for_status) self.model.update_file_status()
def do(self): new_additions = '' for fname in self.filenames: new_additions = new_additions + fname + '\n' for_status = new_additions if new_additions: if os.path.exists('.gitignore'): current_list = utils.slurp('.gitignore') new_additions = new_additions + current_list utils.write('.gitignore', new_additions) _notifier.broadcast(signals.log_cmd, 0, 'Added to .gitignore:\n%s' % for_status) self.model.update_file_status()
def _read_git_head(head, default='master', git=git): """Pure-python .git/HEAD reader""" # Legacy .git/HEAD symlinks if os.path.islink(head): refs_heads = os.path.realpath(git.git_path('refs', 'heads')) path = os.path.abspath(head).replace('\\', '/') if path.startswith(refs_heads + '/'): return path[len(refs_heads)+1:] # Common .git/HEAD "ref: refs/heads/master" file elif os.path.isfile(head): data = utils.slurp(core.decode(head)).rstrip() ref_prefix = 'ref: ' if data.startswith(ref_prefix): return data[len(ref_prefix):] # Detached head return data return default
def _read_git_head(head, default='master', git=git): """Pure-python .git/HEAD reader""" # Legacy .git/HEAD symlinks if os.path.islink(head): refs_heads = os.path.realpath(git.git_path('refs', 'heads')) path = os.path.abspath(head).replace('\\', '/') if path.startswith(refs_heads + '/'): return path[len(refs_heads) + 1:] # Common .git/HEAD "ref: refs/heads/master" file elif os.path.isfile(head): data = utils.slurp(core.decode(head)).rstrip() ref_prefix = 'ref: ' if data.startswith(ref_prefix): return data[len(ref_prefix):] # Detached head return data return default
def show_shortcuts(): try: from PyQt4 import QtWebKit except ImportError: # redhat disabled QtWebKit in their qt build but don't punish the # users qtutils.critical(N_('This PyQt4 does not include QtWebKit.\n' 'The keyboard shortcuts feature is unavailable.')) return try: html = show_shortcuts.html except AttributeError: hotkeys = resources.doc(N_('hotkeys.html')) html = show_shortcuts.html = utils.slurp(hotkeys) try: widget = show_shortcuts.widget except AttributeError: parent = qtutils.active_window() widget = show_shortcuts.widget = QtGui.QDialog(parent) widget.setWindowModality(Qt.WindowModal) web = QtWebKit.QWebView(parent) web.setHtml(html) layout = QtGui.QHBoxLayout() layout.setMargin(0) layout.setSpacing(0) layout.addWidget(web) widget.setWindowTitle(N_('Shortcuts')) widget.setLayout(layout) widget.resize(800, min(parent.height(), 600)) qtutils.add_action(widget, N_('Close'), widget.accept, Qt.Key_Question, Qt.Key_Enter, Qt.Key_Return) widget.show() return widget
def apply_diff_to_worktree(self, path): if os.path.exists(path): self.last_worktree_diff = utils.slurp(path)
def __init__(self, model, parent): QtGui.QWidget.__init__(self, parent) self.model = model self.notifying = False self.spellcheck_initialized = False self._linebreak = None self._textwidth = None self._tabwidth = None # Actions self.signoff_action = add_action(self, cmds.SignOff.name(), cmds.run(cmds.SignOff), cmds.SignOff.SHORTCUT) self.signoff_action.setToolTip(N_('Sign off on this commit')) self.commit_action = add_action(self, N_('Commit@@verb'), self.commit, cmds.Commit.SHORTCUT) self.commit_action.setToolTip(N_('Commit staged changes')) # Widgets self.summary = CommitSummaryLineEdit() self.summary.extra_actions.append(self.signoff_action) self.summary.extra_actions.append(self.commit_action) self.description = CommitMessageTextEdit() self.description.extra_actions.append(self.signoff_action) self.description.extra_actions.append(self.commit_action) commit_button_tooltip = N_('Commit staged changes\n' 'Shortcut: Ctrl+Enter') self.commit_button = create_toolbutton(text=N_('Commit@@verb'), tooltip=commit_button_tooltip, icon=save_icon()) self.actions_menu = QtGui.QMenu() self.actions_button = create_toolbutton(icon=options_icon(), tooltip=N_('Actions...')) self.actions_button.setMenu(self.actions_menu) self.actions_button.setPopupMode(QtGui.QToolButton.InstantPopup) self.actions_menu.addAction(self.signoff_action) self.actions_menu.addAction(self.commit_action) self.actions_menu.addSeparator() # Amend checkbox self.amend_action = self.actions_menu.addAction( N_('Amend Last Commit')) self.amend_action.setCheckable(True) self.amend_action.setShortcut(cmds.AmendMode.SHORTCUT) self.amend_action.setShortcutContext(Qt.ApplicationShortcut) # Spell checker self.check_spelling_action = self.actions_menu.addAction( N_('Check Spelling')) self.check_spelling_action.setCheckable(True) self.check_spelling_action.setChecked(False) # Line wrapping self.actions_menu.addSeparator() self.autowrap_action = self.actions_menu.addAction( N_('Auto-Wrap Lines')) self.autowrap_action.setCheckable(True) self.autowrap_action.setChecked(linebreak()) self.prev_commits_menu = self.actions_menu.addMenu( N_('Load Previous Commit Message')) self.connect(self.prev_commits_menu, SIGNAL('aboutToShow()'), self.build_prev_commits_menu) self.toplayout = QtGui.QHBoxLayout() self.toplayout.setMargin(0) self.toplayout.setSpacing(defs.spacing) self.toplayout.addWidget(self.actions_button) self.toplayout.addWidget(self.summary) self.toplayout.addWidget(self.commit_button) self.mainlayout = QtGui.QVBoxLayout() self.mainlayout.setMargin(defs.margin) self.mainlayout.setSpacing(defs.spacing) self.mainlayout.addLayout(self.toplayout) self.mainlayout.addWidget(self.description) self.setLayout(self.mainlayout) connect_button(self.commit_button, self.commit) notifier = cola.notifier() notifier.connect(notifier.AMEND, self.amend_action.setChecked) # Broadcast the amend mode connect_action_bool(self.amend_action, cmds.run(cmds.AmendMode)) connect_action_bool(self.check_spelling_action, self.toggle_check_spelling) # Handle the one-off autowrapping connect_action_bool(self.autowrap_action, self.set_linebreak) add_action(self.summary, N_('Move Down'), self.focus_description, Qt.Key_Down, Qt.Key_Return, Qt.Key_Enter) self.model.add_observer(self.model.message_commit_message_changed, self.set_commit_message) self.connect(self.summary, SIGNAL('cursorPosition(int,int)'), self.emit_position) self.connect(self.description, SIGNAL('cursorPosition(int,int)'), # description starts at line 2 lambda row, col: self.emit_position(row + 2, col)) # Keep model informed of changes self.connect(self.summary, SIGNAL('textChanged(QString)'), self.commit_message_changed) self.connect(self.description, SIGNAL('textChanged()'), self.commit_message_changed) self.connect(self.description, SIGNAL('leave()'), self.focus_summary) self.setFont(diff_font()) self.summary.enable_hint(True) self.description.enable_hint(True) self.commit_button.setEnabled(False) self.commit_action.setEnabled(False) self.setFocusProxy(self.summary) self.set_tabwidth(tabwidth()) self.set_textwidth(textwidth()) self.set_linebreak(linebreak()) # Loading message commit_msg = "" commit_msg_path = commit_message_path() if commit_msg_path: commit_msg = utils.slurp(commit_msg_path) self.set_commit_message(commit_msg) # Allow tab to jump from the summary to the description self.setTabOrder(self.summary, self.description)
def load(path): return decode(utils.slurp(path))
def do(self): self.model.set_directory(os.path.dirname(self.path)) self.model.set_commitmsg(utils.slurp(self.path))
def apply_diff(self, path): if os.path.exists(path): self.last_diff = utils.slurp(path)
def __init__(self, fwd, reverse): self.fwd = utils.slurp(fwd) self.reverse = utils.slurp(reverse)
def __init__(self, model, parent): QtGui.QWidget.__init__(self, parent) self.model = model self.notifying = False self._linebreak = None self._textwidth = None self._tabwidth = None # Actions self.signoff_action = add_action(self, cmds.SignOff.name(), cmds.run(cmds.SignOff), cmds.SignOff.SHORTCUT) self.signoff_action.setToolTip(N_('Sign off on this commit')) self.commit_action = add_action(self, N_('Commit@@verb'), self.commit, cmds.Commit.SHORTCUT) self.commit_action.setToolTip(N_('Commit staged changes')) # Widgets self.summary = CommitSummaryLineEdit() self.summary.extra_actions.append(self.signoff_action) self.summary.extra_actions.append(self.commit_action) self.description = CommitMessageTextEdit() self.description.extra_actions.append(self.signoff_action) self.description.extra_actions.append(self.commit_action) commit_button_tooltip = N_('Commit staged changes\n' 'Shortcut: Ctrl+Enter') self.commit_button = create_toolbutton(text=N_('Commit@@verb'), tooltip=commit_button_tooltip, icon=save_icon()) self.actions_menu = QtGui.QMenu() self.actions_button = create_toolbutton(icon=options_icon(), tooltip=N_('Actions...')) self.actions_button.setMenu(self.actions_menu) self.actions_button.setPopupMode(QtGui.QToolButton.InstantPopup) self.actions_menu.addAction(self.signoff_action) self.actions_menu.addAction(self.commit_action) self.actions_menu.addSeparator() # Amend checkbox self.amend_action = self.actions_menu.addAction( N_('Amend Last Commit')) self.amend_action.setCheckable(True) self.amend_action.setShortcut(cmds.AmendMode.SHORTCUT) self.amend_action.setShortcutContext(Qt.ApplicationShortcut) # Line wrapping self.actions_menu.addSeparator() self.autowrap_action = self.actions_menu.addAction( N_('Auto-Wrap Lines')) self.autowrap_action.setCheckable(True) self.autowrap_action.setChecked(linebreak()) self.prev_commits_menu = self.actions_menu.addMenu( N_('Load Previous Commit Message')) self.connect(self.prev_commits_menu, SIGNAL('aboutToShow()'), self.build_prev_commits_menu) self.toplayout = QtGui.QHBoxLayout() self.toplayout.setMargin(0) self.toplayout.setSpacing(defs.spacing) self.toplayout.addWidget(self.actions_button) self.toplayout.addWidget(self.summary) self.toplayout.addWidget(self.commit_button) self.mainlayout = QtGui.QVBoxLayout() self.mainlayout.setMargin(defs.margin) self.mainlayout.setSpacing(defs.spacing) self.mainlayout.addLayout(self.toplayout) self.mainlayout.addWidget(self.description) self.setLayout(self.mainlayout) connect_button(self.commit_button, self.commit) notifier = cola.notifier() notifier.connect(notifier.AMEND, self.amend_action.setChecked) # Broadcast the amend mode connect_action_bool(self.amend_action, cmds.run(cmds.AmendMode)) # Handle the one-off autowrapping connect_action_bool(self.autowrap_action, self.set_linebreak) add_action(self.summary, N_('Move Down'), self.focus_description, Qt.Key_Down, Qt.Key_Return, Qt.Key_Enter) self.model.add_observer(self.model.message_commit_message_changed, self.set_commit_message) self.connect(self.summary, SIGNAL('cursorPosition(int,int)'), self.emit_position) self.connect( self.description, SIGNAL('cursorPosition(int,int)'), # description starts at line 2 lambda row, col: self.emit_position(row + 2, col)) # Keep model informed of changes self.connect(self.summary, SIGNAL('textChanged(QString)'), self.commit_message_changed) self.connect(self.description, SIGNAL('textChanged()'), self.commit_message_changed) self.connect(self.description, SIGNAL('leave()'), self.focus_summary) self.setFont(diff_font()) self.summary.enable_hint(True) self.description.enable_hint(True) self.commit_button.setEnabled(False) self.commit_action.setEnabled(False) self.setFocusProxy(self.summary) self.set_tabwidth(tabwidth()) self.set_textwidth(textwidth()) self.set_linebreak(linebreak()) # Loading message commit_msg = "" commit_msg_path = commit_message_path() if commit_msg_path: commit_msg = utils.slurp(commit_msg_path) self.set_commit_message(commit_msg) # Allow tab to jump from the summary to the description self.setTabOrder(self.summary, self.description)