Skip to content

Commit

Permalink
Exclude GUI. By @diivi (#1846)
Browse files Browse the repository at this point in the history
  • Loading branch information
m3nu authored Nov 24, 2023
1 parent c9f170a commit b502fc3
Show file tree
Hide file tree
Showing 12 changed files with 754 additions and 99 deletions.
153 changes: 153 additions & 0 deletions src/vorta/assets/UI/excludedialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>504</width>
<height>426</height>
</rect>
</property>
<property name="windowTitle">
<string>Add patterns to exclude</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="topMargin">
<number>10</number>
</property>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Custom</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="customPresetsHelpText">
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QListView" name="customExclusionsList"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="bAddPattern"/>
</item>
<item>
<widget class="QToolButton" name="bRemovePattern"/>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Presets</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="exclusionPresetsHelpText">
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QListView" name="exclusionPresetsList"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_4">
<attribute name="title">
<string>Raw</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="rawExclusionsHelpText">
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="rawExclusionsText"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">
<string>Preview</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="exclusionsPreviewHelpText">
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="exclusionsPreviewText"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="bPreviewCopy">
<property name="text">
<string>Copy to Clipboard</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
71 changes: 11 additions & 60 deletions src/vorta/assets/UI/sourcetab.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="2,1">
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="2">
<property name="spacing">
<number>12</number>
</property>
Expand Down Expand Up @@ -112,6 +112,16 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="bExclude">
<property name="text">
<string>Manage Excluded Items…</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout"/>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
Expand Down Expand Up @@ -147,65 +157,6 @@
</layout>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout" rowstretch="0,1">
<property name="topMargin">
<number>12</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Exclude Patterns (&lt;a href=&quot;https://borgbackup.readthedocs.io/en/stable/usage/help.html#borg-help-patterns&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0984e3;&quot;&gt;more&lt;/span&gt;&lt;/a&gt;):&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Exclude If Present (exclude folders with these files):</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPlainTextEdit" name="excludePatternsField">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContentsOnFirstShow</enum>
</property>
<property name="plainText">
<string/>
</property>
<property name="placeholderText">
<string>E.g. */.cache</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPlainTextEdit" name="excludeIfPresentField">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContentsOnFirstShow</enum>
</property>
<property name="placeholderText">
<string>E.g. .nobackup</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
Expand Down
71 changes: 71 additions & 0 deletions src/vorta/assets/exclusion_presets/browsers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
[
{
"name": "Chromium cache and config files",
"slug": "chromium-cache",
"patterns":
[
"fm:*/.config/chromium/*/Local Storage",
"fm:*/.config/chromium/*/Session Storage",
"fm:*/.config/chromium/*/Service Worker/CacheStorage",
"fm:*/.config/chromium/*/Application Cache",
"fm:*/.config/chromium/*/History Index *",
"fm:*/snap/chromium/common/.cache",
"fm:*/snap/chromium/*/.config/chromium/*/Service Worker/CacheStorage",
"fm:*/snap/chromium/*/.local/share/"
],
"tags":["application:chromium", "type:browser", "os:linux"],
"author": "Divi"
},
{
"name": "Google Chrome cache and config files",
"slug": "google-chrome-cache",
"patterns":
[
"fm:*/.config/google-chrome/ShaderCache",
"fm:*/.config/google-chrome/*/Local Storage",
"fm:*/.config/google-chrome/*/Session Storage",
"fm:*/.config/google-chrome/*/Application Cache",
"fm:*/.config/google-chrome/*/History Index *",
"fm:*/.config/google-chrome/*/Service Worker/CacheStorage"
],
"tags": ["application:chrome", "type:browser", "os:linux"],
"author": "Divi"
},
{
"name": "Brave cache and config files",
"slug": "brave-cache",
"patterns":[
"fm:*/.config/BraveSoftware/Brave-Browser/*/Feature Engagement Tracker/",
"fm:*/.config/BraveSoftware/Brave-Browser/*/Local Storage/",
"fm:*/.config/BraveSoftware/Brave-Browser/*/Service Worker/CacheStorage/",
"fm:*/.config/BraveSoftware/Brave-Browser/*/Session Storage/",
"fm:*/.config/BraveSoftware/Brave-Browser/Safe Browsing/",
"fm:*/.config/BraveSoftware/Brave-Browser/ShaderCache/"
],
"tags": ["application:brave", "type:browser", "os:linux"],
"author": "Divi"
},
{
"name": "Mozilla Firefox cache and config files",
"slug": "firefox-cache",
"patterns":[
"fm:*/.mozilla/firefox/*/Cache",
"fm:*/.mozilla/firefox/*/minidumps",
"fm:*/.mozilla/firefox/*/.parentlock",
"fm:*/.mozilla/firefox/*/urlclassifier3.sqlite",
"fm:*/.mozilla/firefox/*/blocklist.xml",
"fm:*/.mozilla/firefox/*/extensions.sqlite",
"fm:*/.mozilla/firefox/*/extensions.sqlite-journal",
"fm:*/.mozilla/firefox/*/extensions.rdf",
"fm:*/.mozilla/firefox/*/extensions.ini",
"fm:*/.mozilla/firefox/*/extensions.cache",
"fm:*/.mozilla/firefox/*/XUL.mfasl",
"fm:*/.mozilla/firefox/*/XPC.mfasl",
"fm:*/.mozilla/firefox/*/xpti.dat",
"fm:*/.mozilla/firefox/*/compreg.dat",
"fm:*/.mozilla/firefox/*/pluginreg.dat"
],
"tags": ["application:firefox", "type:browser", "os:linux"],
"author": "Divi"
}
]
37 changes: 37 additions & 0 deletions src/vorta/assets/exclusion_presets/dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[
{
"name": "Node Modules and package manager cache",
"slug": "node-cache",
"patterns":
[
"fm:*/node_modules",
"fm:*/.npm"
],
"tags": ["type:dev", "lang:javascript", "os:linux", "os:darwin"],
"author": "Divi"
},
{
"name": "Python cache and virtualenv",
"slug": "python-cache",
"patterns":
[
"fm:*/__pycache__",
"fm:*.pyc",
"fm:*.pyo",
"fm:*/.virtualenvs"
],
"tags": ["type:dev", "lang:python", "os:linux", "os:darwin"],
"author": "Divi"
},
{
"name": "Rust artefacts",
"slug": "rust-artefacts",
"patterns":
[
"fm:*/.cargo",
"fm:*/.rustup"
],
"tags": ["type:dev", "lang:rust", "os:linux", "os:darwin"],
"author": "Divi"
}
]
36 changes: 18 additions & 18 deletions src/vorta/borg/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,24 @@ def prepare(cls, profile):

# Add excludes
# Partly inspired by borgmatic/borgmatic/borg/create.py
if profile.exclude_patterns is not None:
exclude_dirs = []
for p in profile.exclude_patterns.split('\n'):
if p.strip():
expanded_directory = os.path.expanduser(p.strip())
exclude_dirs.append(expanded_directory)

if exclude_dirs:
pattern_file = tempfile.NamedTemporaryFile('w', delete=True)
pattern_file.write('\n'.join(exclude_dirs))
pattern_file.flush()
cmd.extend(['--exclude-from', pattern_file.name])
ret['cleanup_files'].append(pattern_file)

if profile.exclude_if_present is not None:
for f in profile.exclude_if_present.split('\n'):
if f.strip():
cmd.extend(['--exclude-if-present', f.strip()])
exclude_dirs = []
for p in profile.get_combined_exclusion_string().split('\n'):
if p.strip():
expanded_directory = os.path.expanduser(p.strip())
exclude_dirs.append(expanded_directory)

if exclude_dirs:
pattern_file = tempfile.NamedTemporaryFile('w', delete=True)
pattern_file.write('\n'.join(exclude_dirs))
pattern_file.flush()
cmd.extend(['--exclude-from', pattern_file.name])
ret['cleanup_files'].append(pattern_file)

# Currently not in use, but may be added back to the UI later.
# if profile.exclude_if_present is not None:
# for f in profile.exclude_if_present.split('\n'):
# if f.strip():
# cmd.extend(['--exclude-if-present', f.strip()])

# Add repo url and source dirs.
new_archive_name = format_archive_name(profile, profile.new_archive_name)
Expand Down
Loading

0 comments on commit b502fc3

Please sign in to comment.