diff --git a/pytransifex/api.py b/pytransifex/api.py index fd4ee90..ebf2798 100644 --- a/pytransifex/api.py +++ b/pytransifex/api.py @@ -84,12 +84,14 @@ def get_project(self, project_slug: str) -> None | Resource: return None @ensure_login - def list_resources(self, project_slug: str) -> list[Resource]: + def list_resources(self, project_slug: str) -> list[Any]: """List all resources for the project passed as argument""" - if self.projects: - res = self.projects.filter(slug=project_slug) - logging.info("Obtained these resources:") - return res + if project := self.get_project(project_slug=project_slug): + if resources := project.fetch("resources"): + return list(resources.all()) + else: + return [] + raise Exception( f"Unable to find any project under this organization: '{self.organization}'" ) @@ -109,8 +111,8 @@ def create_resource( if project := self.get_project(project_slug=project_slug): resource = tx_api.Resource.create( project=project, - name=resource_name, - slug=resource_slug, + name=resource_name or resource_slug, + slug=resource_slug or resource_name, i18n_format=tx_api.I18nFormat(id=self.i18n_type), ) @@ -305,7 +307,7 @@ def push( logging.info(f"Slug: {slug}. Resources: {resources}.") if not slug in resources: logging.info( - f"{project_slug} is missing {slug}. Created it from {path}." + f"{project_slug} is missing {slug}. Creating it from {path}." ) self.create_resource( project_slug=project_slug, path_to_file=path, resource_slug=slug diff --git a/pytransifex/utils.py b/pytransifex/utils.py index f125295..ea28b14 100644 --- a/pytransifex/utils.py +++ b/pytransifex/utils.py @@ -19,16 +19,16 @@ def concurrently( args: list[Any] | None = None, partials: list[Any] | None = None, ) -> list[Any]: - if args and len(args) == 0: - return [] - if partials and len(partials) == 0: - return [] with ThreadPoolExecutor() as pool: - if partials: + if not partials is None: + assert args is None and fn is None futures = [pool.submit(p) for p in partials] - elif fn and args: + elif (not args is None) and (not fn is None): + assert partials is None futures = [pool.submit(fn, *a) for a in args] else: - raise Exception("Either partials or fn and args!") + raise ValueError( + "Exactly 1 of 'partials' or 'args' must be defined. Found neither was when calling concurrently." + ) return [f.result() for f in as_completed(futures)]