Skip to content

Commit

Permalink
[#77] Renamed osx_path to macos_path in Repository class, also …
Browse files Browse the repository at this point in the history
…added alembic migration script for this.
  • Loading branch information
eoyilmaz committed Nov 1, 2024
1 parent 93b0536 commit 3753567
Show file tree
Hide file tree
Showing 26 changed files with 268 additions and 242 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.cache/*
.coverage
.DS_Store
.env
.pytest_cache
.venv/
.vscode/
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Create a ``Repository`` for project files to be saved under:
name='Commercial Projects Repository',
windows_path='Z:/Projects',
linux_path='/mnt/Z/Projects',
osx_path='/Volumes/Z/Projects'
macos_path='/Volumes/Z/Projects'
)
Create a ``FilenameTemplate`` (to be used as file naming convention):
Expand Down
26 changes: 26 additions & 0 deletions alembic/versions/feca9bac7d5a_renamed_osx_to_macos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Renamed OSX to macOS
Revision ID: feca9bac7d5a
Revises: bf67e6a234b4
Create Date: 2024-11-01 12:22:24.818481
"""

from alembic import op

import sqlalchemy as sa



# revision identifiers, used by Alembic.
revision = 'feca9bac7d5a'
down_revision = 'bf67e6a234b4'


def upgrade():
"""Upgrade the tables."""
op.alter_column("Repositories", "osx_path", new_column_name="macos_path")


def downgrade():
"""Downgrade the tables."""
op.alter_column("Repositories", "macos_path", new_column_name="osx_path")
2 changes: 1 addition & 1 deletion docs/source/_static/images/stalker_design.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3750,7 +3750,7 @@
<URIString>http://vue.tufts.edu/rdf/resource/73db9f4c7f0001010b45ad3de656431d</URIString>
<shape arcwidth="20.0" archeight="20.0" xsi:type="roundRect"/>
</child>
<child ID="2193" label="osx_path | UNICODE"
<child ID="2193" label="macos_path | UNICODE"
created="1290433929378" x="34.0" y="43.25" width="126.0"
height="23.0" strokeWidth="1.0" autoSized="true" xsi:type="node">
<fillColor>#F2AE45</fillColor>
Expand Down
2 changes: 1 addition & 1 deletion docs/source/design.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Here is the code::
name='Commercials Repo',
linux_path='/mnt/T/Commercials/',
windows_path='T:/Commercials/',
osx_path='/Volumes/T/Commercials/'
macos_path='/Volumes/T/Commercials/'
)

commercial_structure = Structure(
Expand Down
4 changes: 2 additions & 2 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Install Python

Stalker is completely written with Python, so it requires Python. It currently
works with Python version 2.6 and 2.7. So you first need to have Python
installed in your system. On Linux and OSX there is a system wide Python
installed in your system. On Linux and macOS there is a system wide Python
already installed. For Windows, you need to download the Python installer
suitable for your Windows operating system (32 or 64 bit) from `Python.org`_

Expand All @@ -33,7 +33,7 @@ bootstrap script.
Installing `setuptools` with `ez_setup`:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

These steps are generally needed just for Windows. Linux and OSX users can skip
These steps are generally needed just for Windows. Linux and macOS users can skip
this part.

1. download `ez_setup.py`_
Expand Down
10 changes: 5 additions & 5 deletions docs/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ database::

or::

db.setup({"sqlalchemy.url": "sqlite:////home/ozgur/studio.db"}) # under linux or osx
db.setup({"sqlalchemy.url": "sqlite:////home/ozgur/studio.db"}) # under linux or macos

.. ::
This command will do the following:
Expand Down Expand Up @@ -519,15 +519,15 @@ task.
On a linux system this should be fairly straight forward, just install
`TaskJuggler`_ and stalker will be able to use it.

But for other OSes, like OSX and Windows, you should create an environment
But for other OSes, like macOS and Windows, you should create an environment
variable called ``STALKER_PATH`` and then place a file called ``config.py``
inside the folder that this path is pointing at. And then add the following
to this ``config.py``::

tj_command = 'C:\\Path\\to\\tj3.exe'

The default value for ``tj_command`` config variable is
``/usr/local/bin/tj3``, so if on a Linux or OSX system when you run::
``/usr/local/bin/tj3``, so if on a Linux or macOS system when you run::

which tj3

Expand Down Expand Up @@ -631,7 +631,7 @@ create our projects into. Lets enter the paths for all the major operating
systems::

commercial_repo.linux_path = "/mnt/M/commercials"
commercial_repo.osx_path = "/Volumes/M/commercials"
commercial_repo.macos_path = "/Volumes/M/commercials"
commercial_repo.windows_path = "M:/commercials" # you can use reverse
# slashes (\\) if you want

Expand All @@ -645,7 +645,7 @@ correct answer according to your operating system::
# in Linux and variants:
# /mnt/M/commercials
#
# and in OSX:
# and in macOS:
# /Volumes/M/commercials

.. note::
Expand Down
4 changes: 2 additions & 2 deletions docs/source/tutorial_files/tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
print(new_project.to_tjp)

commercial_repo.linux_path = "/mnt/M/commercials"
commercial_repo.osx_path = "/Volumes/M/commercials"
commercial_repo.macos_path = "/Volumes/M/commercials"
commercial_repo.windows_path = "M:/commercials" # you can use reverse slashes
# (\\) if you want

Expand All @@ -223,7 +223,7 @@
# in Linux and variants:
# /mnt/M/commercials
#
# and in OSX:
# and in macOS:
# /Volumes/M/commercials


Expand Down
2 changes: 1 addition & 1 deletion docs/source/upgrade_db.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ installation directory::
# for Windows
..\Scripts\alembic.exe upgrade head

# for Linux or OSX
# for Linux or macOS
../bin/alembic upgrade head

# this should output something like that:
Expand Down
2 changes: 1 addition & 1 deletion examples/flat_project_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
repo = Repository(
name="Test Repository",
linux_path="/mnt/T/stalker_tests/",
osx_path="/Volumes/T/stalker_tests/",
macos_path="/Volumes/T/stalker_tests/",
windows_path="T:/stalker_tests/",
)

Expand Down
2 changes: 1 addition & 1 deletion src/stalker/db/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
logger = log.get_logger(__name__)

# TODO: Try to get it from the API (it was not working inside a package before)
alembic_version = "bf67e6a234b4"
alembic_version = "feca9bac7d5a"


def setup(settings=None):
Expand Down
63 changes: 32 additions & 31 deletions src/stalker/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Repository(Entity, CodeMixin):
different installations of Stalker.
linux_path (str): shows the linux path of the repository root, should be
a string
osx_path (str): shows the mac osx path of the repository root, should be
macos_path (str): shows the macOS path of the repository root, should be
a string.
windows_path (str): shows the windows path of the repository root, should
be a string
Expand All @@ -67,7 +67,7 @@ class Repository(Entity, CodeMixin):
# OpenLDAP server.
#
# The AutoFS can be installed to any linux system easily or it is already
# installed. OSX has it already. I know nothing about Windows.
# installed. macOS has it already. I know nothing about Windows.
#
# AutoFS can be setup to listen for new mount points from an OpenLDAP
# server. Thus it is heavily related with the users system, Stalker
Expand All @@ -87,16 +87,16 @@ class Repository(Entity, CodeMixin):
)
linux_path = Column(String(256))
windows_path = Column(String(256))
osx_path = Column(String(256))
macos_path = Column(String(256))

def __init__(self, code="", linux_path="", windows_path="", osx_path="", **kwargs):
def __init__(self, code="", linux_path="", windows_path="", macos_path="", **kwargs):
kwargs["code"] = code
super(Repository, self).__init__(**kwargs)
CodeMixin.__init__(self, **kwargs)

self.linux_path = linux_path
self.windows_path = windows_path
self.osx_path = osx_path
self.macos_path = macos_path

@validates("linux_path")
def _validate_linux_path(self, key, linux_path):
Expand Down Expand Up @@ -136,36 +136,36 @@ def _validate_linux_path(self, key, linux_path):

return linux_path

@validates("osx_path")
def _validate_osx_path(self, key, osx_path):
@validates("macos_path")
def _validate_macos_path(self, key, macos_path):
"""Validate the given macOS path.
Args:
key (str): The name of the validated column.
osx_path (str): The OSX path to validate.
macos_path (str): The macOS path to validate.
Raises:
TypeError: If the given OSX path is not a str.
TypeError: If the given macOS path is not a str.
Returns:
str: The validated OSX path.
str: The validated macOS path.
"""
if not isinstance(osx_path, string_types):
if not isinstance(macos_path, string_types):
raise TypeError(
f"{self.__class__.__name__}.osx_path should be an instance of string, "
f"not {osx_path.__class__.__name__}: '{osx_path}'"
f"{self.__class__.__name__}.macos_path should be an instance of string, "
f"not {macos_path.__class__.__name__}: '{macos_path}'"
)

osx_path = os.path.normpath(osx_path) + "/"
osx_path = osx_path.replace("\\", "/")
macos_path = os.path.normpath(macos_path) + "/"
macos_path = macos_path.replace("\\", "/")
if self.code is not None and platform.system() == "Darwin":
# update the environment variable
os.environ[defaults.repo_env_var_template.format(code=self.code)] = osx_path
os.environ[defaults.repo_env_var_template.format(code=self.code)] = macos_path

if self.id is not None and platform.system() == "Darwin":
os.environ[defaults.repo_env_var_template_old.format(id=self.id)] = osx_path
os.environ[defaults.repo_env_var_template_old.format(id=self.id)] = macos_path

return osx_path
return macos_path

@validates("windows_path")
def _validate_windows_path(self, key, windows_path):
Expand Down Expand Up @@ -222,7 +222,7 @@ def path(self):
elif platform_system == "Windows":
return self.windows_path
elif platform_system == "Darwin":
return self.osx_path
return self.macos_path

@path.setter
def path(self, path):
Expand All @@ -239,7 +239,7 @@ def path(self, path):
elif platform_system == "Windows":
self.windows_path = path
elif platform_system == "Darwin":
self.osx_path = path
self.macos_path = path

def is_in_repo(self, path):
"""Return True or False depending on the given is in this repo or not.
Expand All @@ -254,7 +254,7 @@ def is_in_repo(self, path):
return (
path.lower().startswith(self.windows_path.lower())
or path.startswith(self.linux_path)
or path.startswith(self.osx_path)
or path.startswith(self.macos_path)
)

def _to_path(self, path, replace_with):
Expand Down Expand Up @@ -288,8 +288,8 @@ def _to_path(self, path, replace_with):
return path.replace(self.windows_path, replace_with)
elif path.startswith(self.linux_path):
return path.replace(self.linux_path, replace_with)
elif path.startswith(self.osx_path):
return path.replace(self.osx_path, replace_with)
elif path.startswith(self.macos_path):
return path.replace(self.macos_path, replace_with)

return path

Expand All @@ -315,16 +315,16 @@ def to_windows_path(self, path):
"""
return self._to_path(path, self.windows_path)

def to_osx_path(self, path):
"""Return the OSX version of the given path.
def to_macos_path(self, path):
"""Return the macOS version of the given path.
Args:
path (str): The path that needs to be converted to OSX path.
path (str): The path that needs to be converted to macOS path.
Returns:
str: The OSX path.
str: The macOS path.
"""
return self._to_path(path, self.osx_path)
return self._to_path(path, self.macos_path)

def to_native_path(self, path):
"""Return the native version of the given path.
Expand Down Expand Up @@ -372,7 +372,7 @@ def find_repo(cls, path):
path.startswith(repo.path)
or path.lower().startswith(repo.windows_path.lower())
or path.startswith(repo.linux_path)
or path.startswith(repo.osx_path)
or path.startswith(repo.macos_path)
):
found_repo = repo
break
Expand Down Expand Up @@ -421,13 +421,14 @@ def __eq__(self, other):
Returns:
bool: True if the other object is equal to this one as an Entity, is a
Repository instance and has the same linux_path, osx_path, windows_path.
Repository instance and has the same linux_path, macos_path,
windows_path.
"""
return (
super(Repository, self).__eq__(other)
and isinstance(other, Repository)
and self.linux_path == other.linux_path
and self.osx_path == other.osx_path
and self.macos_path == other.macos_path
and self.windows_path == other.windows_path
)

Expand Down
2 changes: 1 addition & 1 deletion tests/benchmarks/task_total_logged_seonds.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
type=test_repository_type,
linux_path="/mnt/T/",
windows_path="T:/",
osx_path="/Volumes/T/",
macos_path="/Volumes/T/",
)


Expand Down
Loading

0 comments on commit 3753567

Please sign in to comment.