Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Mergin/project_status_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from .diff_dialog import DiffViewerDialog
from .validation import MultipleLayersWarning, warning_display_string, MerginProjectValidator, SingleLayerWarning
from .utils import is_versioned_file, icon_path, unsaved_project_check, UnsavedChangesStrategy
from .repair import fix_datum_shift_grids
from .repair import fix_datum_shift_grids, fix_project_home_path


ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ui", "ui_status_dialog.ui")
Expand Down Expand Up @@ -241,7 +241,8 @@ def link_clicked(self, url):
if parsed_url.path == "reset_file":
query_parameters = parse_qs(parsed_url.query)
self.reset_local_changes(query_parameters["layer"][0])

if parsed_url.path == "fix_project_home_path":
fix_project_home_path()
self.validate_project()

def validate_project(self):
Expand Down
9 changes: 8 additions & 1 deletion Mergin/repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from qgis.core import QgsProject

from .utils import project_grids_directory, copy_datum_shift_grids
from .utils import project_grids_directory, copy_datum_shift_grids, set_qgis_project_home_ignore


def fix_datum_shift_grids(mp):
Expand All @@ -24,3 +24,10 @@ def fix_datum_shift_grids(mp):
return f"Following grids were not found in the QGIS folder: {','.join(missed_files)}"

return None


def fix_project_home_path():
"""Remove home path settings from the project."""
cur_project = QgsProject.instance()
set_qgis_project_home_ignore(cur_project)
return None
14 changes: 11 additions & 3 deletions Mergin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,11 +620,19 @@ def set_qgis_project_relative_paths(qgis_project):
_ = qgis_project.writeEntry("Paths", "/Absolute", "false")


def save_current_project(project_path, warn=False, relative_paths=True):
def set_qgis_project_home_ignore(qgis_project):
"""Check if given QGIS project have home path set up. If yes - remove it from the project."""
if qgis_project.presetHomePath():
qgis_project.setPresetHomePath("")


def save_current_project(project_path, warn=False):
"""Save current QGIS project to project_path. Set the project to use relative paths if relative_paths is True."""
cur_project = QgsProject.instance()
if relative_paths:
set_qgis_project_relative_paths(cur_project)

set_qgis_project_relative_paths(cur_project)
set_qgis_project_home_ignore(cur_project)

cur_project.setFileName(project_path)
write_success = cur_project.write()
if not write_success and warn:
Expand Down
10 changes: 10 additions & 0 deletions Mergin/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Warning(Enum):
EDITOR_NON_DIFFABLE_CHANGE = 25
EDITOR_JSON_CONFIG_CHANGE = 26
EDITOR_DIFFBASED_FILE_REMOVED = 27
PROJECT_HOME_PATH = 28


class MultipleLayersWarning:
Expand Down Expand Up @@ -113,6 +114,7 @@ def run_checks(self):
return self.issues
self.get_proj_layers()
self.check_proj_paths_relative()
self.check_proj_home_path()
self.check_saved_in_proj_dir()
self.check_editable_vectors_format()
self.check_offline()
Expand Down Expand Up @@ -158,6 +160,12 @@ def check_proj_paths_relative(self):
if not abs_paths == "false":
self.issues.append(MultipleLayersWarning(Warning.ABSOLUTE_PATHS))

def check_proj_home_path(self):
"""Check if the QGIS project has project home path specified."""
project_home_path = self.qgis_proj.presetHomePath()
if project_home_path:
self.issues.append(MultipleLayersWarning(Warning.PROJECT_HOME_PATH))

def get_proj_layers(self):
"""Get project layers and find those editable."""
self.layers = self.qgis_proj.mapLayers()
Expand Down Expand Up @@ -485,3 +493,5 @@ def warning_display_string(warning_id, url=None):
return f"You don't have permission to change the configuration of this project. <a href='{url}'>Reset the configuration</a> to be able to sync data changes."
elif warning_id == Warning.EDITOR_DIFFBASED_FILE_REMOVED:
return f"You don't have permission to remove this layer. <a href='{url}'>Reset the layer</a> to be able to sync changes."
elif warning_id == Warning.PROJECT_HOME_PATH:
return "QGIS Project Home Path is specified. <a href='fix_project_home_path'>Quick fix the issue. (This will unset project home)</a>"
4 changes: 3 additions & 1 deletion scripts/deploy_win.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

this_dir = os.path.dirname(os.path.realpath(__file__))
home_dir = os.path.expanduser("~")
dest_dir_plug = os.path.join(home_dir, "AppData", "Roaming", "QGIS", "QGIS3", "profiles", profile, "python", "plugins", "Mergin")
dest_dir_plug = os.path.join(
home_dir, "AppData", "Roaming", "QGIS", "QGIS3", "profiles", profile, "python", "plugins", "Mergin"
)
print(dest_dir_plug)
src_dir_plug = os.path.join(os.path.dirname(this_dir), "Mergin")
try:
Expand Down
4 changes: 2 additions & 2 deletions scripts/update_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def replace_in_file(filepath, regex, sub):
with open(filepath, 'r') as f:
with open(filepath, "r") as f:
content = f.read()

content_new = re.sub(regex, sub, content, flags=re.M)
Expand All @@ -15,7 +15,7 @@ def replace_in_file(filepath, regex, sub):

dir_path = os.path.dirname(os.path.realpath(__file__))
parser = argparse.ArgumentParser()
parser.add_argument('--version', help='version to replace')
parser.add_argument("--version", help="version to replace")
args = parser.parse_args()
ver = args.version
print("using version " + ver)
Expand Down
Loading