Skip to content

Commit

Permalink
Updating multiple project files
Browse files Browse the repository at this point in the history
  • Loading branch information
kamaal111 committed Apr 28, 2024
1 parent 7a2688e commit bbba5fb
Show file tree
Hide file tree
Showing 6 changed files with 1,165 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ xctools = "xctools_kamaalio:cli.cli"

[project]
name = "xctools_kamaalio"
version = "0.3.0"
version = "0.4.0"
authors = [{ name = "Kamaal Farah", email = "[email protected]" }]
description = "A package to help deal with Xcode projects."
readme = "README.md"
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build==0.10.0
click==8.1.6
kamaalpy==0.1.0
pytest==7.4.3
twine==4.0.2
66 changes: 48 additions & 18 deletions src/xctools_kamaalio/project_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@


class ProjectUpdater:
project_configuration: Path
project_configurations: list[Path]

def __init__(self) -> None:
project_configurations: list[Path] = []
for path in Path.cwd().glob("**/*"):
if path.name == "project.pbxproj":
self.project_configuration = path
break
else:
if path.name != "project.pbxproj":
continue

project_configurations.append(path)

if len(project_configurations) == 0:
raise ProjectUpdaterException("No project path found")

self.project_configurations = project_configurations

def bump_version(self, build_number: int | None, version_number: str | None):
has_changes = self.__edit(
object_to_update=omit_empty(
Expand All @@ -28,13 +33,11 @@ def bump_version(self, build_number: int | None, version_number: str | None):
else:
print("No changes where needed")

def __edit(self, object_to_update: dict[str, str]):
if object_to_update == {}:
return False

project_configuration_file_lines = (
self.project_configuration.read_text().splitlines()
)
@staticmethod
def edit_configuration(
project_configuration: str, object_to_update: dict[str, str]
):
project_configuration_file_lines = project_configuration.splitlines()
keys_to_update = object_to_update.keys()
has_changes = False
for line_number, line in enumerate(project_configuration_file_lines):
Expand All @@ -44,21 +47,48 @@ def __edit(self, object_to_update: dict[str, str]):

amount_of_tabs = line.count("\t")
tabs = "\t" * amount_of_tabs
project_configuration_file_lines[
line_number
] = f"{tabs}{key} = {object_to_update[key]};"
project_configuration_file_lines[line_number] = (
f"{tabs}{key} = {object_to_update[key]};"
)
has_changes = True
break

if not has_changes:
return False
return

if len(project_configuration_file_lines[-1]) != 0:
project_configuration_file_lines.append("")

self.project_configuration.write_text(
"\n".join(project_configuration_file_lines)
return "\n".join(project_configuration_file_lines)

def __edit(self, object_to_update: dict[str, str]):
if object_to_update == {}:
return False

has_some_changes = False
for project_configuration in self.project_configurations:
has_changes = ProjectUpdater.__edit_configuration(
project_configuration=project_configuration,
object_to_update=object_to_update,
)
if not has_changes:
continue
has_some_changes = True

return has_some_changes

@classmethod
def __edit_configuration(
cls, project_configuration: Path, object_to_update: dict[str, str]
):
project_configuration_changes = cls.edit_configuration(
project_configuration=project_configuration.read_text(),
object_to_update=object_to_update,
)
if project_configuration_changes is None:
return False

project_configuration.write_text(project_configuration_changes)
return True


Expand Down
Loading

0 comments on commit bbba5fb

Please sign in to comment.