Skip to content

Commit

Permalink
apio install: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Obijuan committed Mar 13, 2024
1 parent fee97a6 commit 4c029aa
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions apio/managers/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import re
import shutil

from os import rename
from os.path import isdir
from pathlib import Path
import click
Expand Down Expand Up @@ -300,15 +299,22 @@ def _install_package(self, dlpath: Path):
# -- Remove it!
shutil.rmtree(package_dir)

# -- If there is a folder name for uncompressing the tarball
# -- Ex. 'apio-examples-0.0.35'
# -- The packages that have the property uncompressed_name
# -- have a folder (with that name) inside the compresssed file
# -- Ex. The package examples has the folder apio-examples-0.0.35
# -- Because of this, it should be unpacked directly in the
# -- packages folder (Ex. /home/obijuan/.paio/packages) and then
# -- rename the folder to the package name
# -- (Ex. apio-examples-0.0.35 -> examples)
if self.uncompressed_name:

# -- Uncompress it!!
# -- Ex. folder: /home/obijuan/.apio/packages
self._unpack(dlpath, self.packages_dir)

# -- Use the calculated destination file
# -- In this other case the package is directly
# -- unpack in the package_dir folder
# -- Ex. packages/tools-oss-cad-suite
else:
self._unpack(dlpath, package_dir)

Expand All @@ -334,22 +340,23 @@ def _rename_unpacked_dir(self):
"""Change the name of the downloaded file to the final one
Ex. '/home/obijuan/.apio/packages/apio-examples-0.0.35'
---> '/home/obijuan/.apio/packages/examples'
Only for packages that has the property uncompressed_name
"""

if self.compressed_name:
if self.uncompressed_name:

# -- Build the names
# -- src folder (the one downloaded and installed)
# -- Ex. '/home/obijuan/.apio/packages/apio-examples-0.0.35'
unpack_dir = self.packages_dir / self.compressed_name
unpack_dir = self.packages_dir / self.uncompressed_name

# -- New folder
# -. Ex, '/home/obijuan/.apio/packages/examples'
package_dir = self.packages_dir / self.package_name

# -- Rename it!
if unpack_dir.is_dir():
rename(unpack_dir, package_dir)
unpack_dir.rename(package_dir)

def uninstall(self):
"""DOC: TODO"""
Expand Down

0 comments on commit 4c029aa

Please sign in to comment.