Verified Commit c4bc4d50 authored by Sheogorath's avatar Sheogorath

Refactor gitkraken role

The current gitkraken role is either insecure, outdated and overly
complicated.

This patch moves GitKraken to a flathub based setup that is easy to use
and can be upgraded easily.

Fixes: #17
parent 3c987812
Pipeline #646 failed with stage
in 28 minutes and 7 seconds
---
# defaults file for gitkraken
gitkraken_download_path: "/tmp/gitkraken-amd64.tar.gz"
gitkraken_install_path: "/opt/GitKraken"
gitkraken_download_url: "https://release.gitkraken.com/linux/gitkraken-amd64.tar.gz"
# -*- coding: UTF-8 -*-
# This example is contributed by Martin Enlund
# Example modified for GitKraken
# Shortcuts Provider was inspired by captain nemo extension
from gettext import gettext, textdomain
from subprocess import PIPE, call
from urllib import unquote
from urlparse import urlparse
from gi import require_version
require_version('Gtk', '3.0')
require_version('Nautilus', '3.0')
from gi.repository import Gio, GObject, Gtk, Nautilus
COMMAND = "gitkraken"
KEYBINDINGS = "com.axosoft.GitKraken.Keybindings"
GSETTINGS_OPEN_TERMINAL = "nautilus-open"
textdomain("gitkraken")
_ = gettext
def run(file_):
if file_.is_directory():
filename = Gio.File.new_for_uri(file_.get_uri()).get_path()
if filename:
call('{0} --args -p "{1}" &'.format(COMMAND, filename), shell=True)
else:
call("{0} &".format(COMMAND), shell=True)
class OpenGitKrakenShortcutProvider(GObject.GObject,
Nautilus.LocationWidgetProvider):
def __init__(self):
source = Gio.SettingsSchemaSource.get_default()
if source.lookup(KEYBINDINGS, True):
self._gsettings = Gio.Settings.new(KEYBINDINGS)
self._gsettings.connect("changed", self._bind_shortcut)
self._create_accel_group()
self._window = None
self._uri = None
def _create_accel_group(self):
self._accel_group = Gtk.AccelGroup()
shortcut = self._gsettings.get_string(GSETTINGS_OPEN_TERMINAL)
key, mod = Gtk.accelerator_parse(shortcut)
self._accel_group.connect(key, mod, Gtk.AccelFlags.VISIBLE,
self._open_terminal)
def _bind_shortcut(self, gsettings, key):
if key == GSETTINGS_OPEN_TERMINAL:
self._accel_group.disconnect(self._open_terminal)
self._create_accel_group()
def _open_terminal(self, *args):
filename = unquote(self._uri[7:])
run(filename)
def get_widget(self, uri, window):
self._uri = uri
if self._window:
self._window.remove_accel_group(self._accel_group)
if self._gsettings:
window.add_accel_group(self._accel_group)
self._window = window
return None
class OpenGitKrakenExtension(GObject.GObject, Nautilus.MenuProvider):
def _open_terminal(self, file_):
run(file_)
def _menu_activate_cb(self, menu, file_):
self._open_terminal(file_)
def _menu_background_activate_cb(self, menu, file_):
self._open_terminal(file_)
def get_file_items(self, window, files):
if len(files) != 1:
return
items = []
file_ = files[0]
print("Handling file: ", file_.get_uri())
print("file scheme: ", file_.get_uri_scheme())
if file_.is_directory():
filename = file_.get_name().decode('utf-8')
item = Nautilus.MenuItem(name='NautilusPython::open_file_item',
label=_(u'Open In GitKraken'),
tip=_(u'Open GitKraken In {}').format(filename))
item.connect('activate', self._menu_activate_cb, file_)
items.append(item)
return items
def get_background_items(self, window, file_):
items = []
item = Nautilus.MenuItem(name='NautilusPython::open_bg_file_item',
label=_(u'Open GitKraken Here'),
tip=_(u'Open GitKraken In This Directory'))
item.connect('activate', self._menu_background_activate_cb, file_)
items.append(item)
return items
---
# handlers file for gitkraken
- name: Update icon directory timestamp
file:
path: "/usr/share/icons/hicolor"
state: touch
tags:
- gitkraken
- gtk
become: true
- name: Update GTK icon cache
tags:
- gitkraken
- gtk
command: "gtk-update-icon-cache"
---
# handlers file for gitkraken
- name: refresh GTK icon cache
import_tasks: "clear-gtk-cache.yml"
......@@ -19,4 +19,5 @@ galaxy_info:
- all
galaxy_tags: []
dependencies: []
dependencies:
- flathub
---
# Fedora setup for GitKraken
- name: Detect broken setup
stat:
path: "{{ gitkraken_install_path }}/gitkraken"
tags:
- gitkraken
register: gitkraken_broken_setup
- name: Remove broken setup
file:
path: "{{ gitkraken_install_path }}"
state: absent
tags:
- gitkraken
become: true
when: gitkraken_broken_setup.stat.isdir is defined and gitkraken_broken_setup.stat.isdir
- name: Check that GitKraken is installed
stat:
path: "{{ gitkraken_install_path }}"
tags:
- gitkraken
register: gitkraken_dir
- name: Download GitKraken
get_url:
url: "{{ gitkraken_download_url }}"
dest: "{{ gitkraken_download_path }}"
tags:
- download
- gitkraken
when: gitkraken_dir.stat.exists == False
- name: Unpack GitKraken
unarchive:
src: "{{ gitkraken_download_path }}"
dest: "/tmp/"
remote_src: yes
tags:
- gitkraken
- unarchive
register: unpacked_gitkraken
when: gitkraken_dir.stat.exists == False
- name: Install GitKraken
command: "mv /tmp/gitkraken {{ gitkraken_install_path }}"
args:
creates: "{{ gitkraken_install_path }}"
tags:
- gitkraken
become: yes
when: gitkraken_dir.stat.exists == False
- name: Clean up
file:
path: /tmp/gitkraken
state: absent
tags:
- gitkraken
when: unpacked_gitkraken is succeeded
- name: Create desktop entry
template:
src: gitkraken.desktop
dest: /usr/share/applications/gitkraken.desktop
tags:
- gitkraken
- desktop
become: true
- name: Install desktop icon
copy:
src: gitkraken.png
dest: /usr/share/icons/hicolor/512x512/apps/gitkraken.png
tags:
- gitkraken
- gtk
- icons
- desktop
become: true
notify: "refresh GTK icon cache"
- name: Install GitKraken to path
file:
state: link
src: "{{ gitkraken_install_path }}/gitkraken"
dest: "/usr/local/bin/gitkraken"
tags:
- gitkraken
- path
become: true
- name: Install Nautilus-Extension
copy:
src: open-gitkraken.py
dest: /usr/share/nautilus-python/extensions/open-gitkraken.py
tags:
- gitkraken
- python
- nautilus
- nautilus-python
- nautlius-python-extension
become: true
notify: "Nautilus python extension notification"
- name: Increase inotify count
sysctl:
name: fs.inotify.max_user_watches
value: 524288
sysctl_set: yes
state: present
reload: yes
become: true
- import_tasks: remove.yml
- import_tasks: flatpak.yml
---
- name: Install GitKraken from FlatHub
flatpak:
name: com.axosoft.GitKraken
state: present
remote: flathub
become: true
---
- name: Remove legacy setup
file:
state: absent
path: "{{ gitkraken_install_path }}"
become: true
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment