Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
Init.
Browse files Browse the repository at this point in the history
  • Loading branch information
why-not-try-calmer committed Feb 21, 2023
1 parent fd42a8d commit 4e3111a
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions pytransifex/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,21 @@ def create_project(
source_language_code: str = "en_GB",
private: bool = False,
**kwargs,
) -> None | Resource:
):
"""Create a project."""
source_language = tx_api.Language.get(code=source_language_code)
project_name = project_name or project_slug

try:
proj = tx_api.Project.create(
name=project_name,
slug=project_slug,
source_language=source_language,
private=private,
organization=self.organization,
**kwargs,
)
logger.info(f"Project created with name '{project_name}' !")
return proj

except JsonApiException as error:
if hasattr(error, "detail") and "already exists" in error.detail: # type: ignore
return self.get_project(project_slug=project_slug)
else:
logger.error(f"Unable to create project; API replied with {error}")
tx_api.Project.create(
name=project_name,
slug=project_slug,
source_language=source_language,
private=private,
organization=self.organization,
**kwargs,
)

logger.info(f"Project created with name '{project_name}' !")

@ensure_login
def delete_project(self, project_slug: str):
Expand Down Expand Up @@ -270,7 +263,7 @@ def project_exists(self, project_slug: str) -> bool:
try:
if not self.projects:
return False
elif self.projects.get(slug=project_slug):
elif self.get_project(project_slug=project_slug):
return True
else:
return False
Expand All @@ -283,7 +276,7 @@ def ping(self) -> bool:
Exposing this just for the sake of satisfying qgis-plugin-cli's expectations
There is no need to ping the server on the current implementation, as connection is handled by the SDK
"""
logger.info("'ping' is deprecated!")
logger.warning("'ping' is deprecated!")
return True

@ensure_login
Expand Down

0 comments on commit 4e3111a

Please sign in to comment.