31
31
32
32
@dc .dataclass
33
33
class PackageFile (PackageURL ):
34
+ unpack : bool = None
34
35
35
36
def update (self , update_info : UpdateInfo ) -> ProjInfo :
36
37
from .project_info_reader import ProjectInfoReader
@@ -44,39 +45,38 @@ def update(self, update_info : UpdateInfo) -> ProjInfo:
44
45
info : ProjInfo = ProjectInfoReader (pkg_dir ).read ()
45
46
46
47
return info
48
+
49
+ def _install (self , pkg_src , pkg_path ):
50
+ if self .src_type in (".tar.gz" , ".tar.xz" , ".tar.bz2" ):
51
+ self ._install_tgz (pkg_src , pkg_path )
52
+ elif self .src_type in (".jar" , ".zip" ):
53
+ self ._install_zip (pkg_src , pkg_path )
54
+ else :
55
+ raise Exception ("Unsupported src_type: %s" % self .src_type )
47
56
48
- def _install_tgz (self , pkg , pkg_path ):
57
+ def _install_tgz (self , pkg_src , pkg_path ):
49
58
cwd = os .getcwd ()
50
- os .chdir (self .packages_dir )
59
+ try :
60
+ os .chdir (os .path .dirname (pkg_path ))
51
61
52
- tf = tarfile .open (pkg_path )
53
-
54
- for fi in tf :
55
- if fi .name .find ("/" ) != - 1 :
56
- fi .name = fi .name [fi .name .find ("/" )+ 1 :]
57
- tf .extract (fi , path = pkg .name )
58
- tf .close ()
62
+ tf = tarfile .open (pkg_src )
59
63
60
- os .chdir (cwd )
64
+ for fi in tf :
65
+ if fi .name .find ("/" ) != - 1 :
66
+ fi .name = fi .name [fi .name .find ("/" )+ 1 :]
67
+ tf .extract (fi , path = os .path .basename (pkg_path ))
68
+ tf .close ()
69
+ finally :
70
+ os .chdir (cwd )
61
71
62
- def _install_zip (self , pkg , pkg_path ):
63
- ext = os .path .splitext (pkg .name )[1 ]
64
-
65
- if ext == "" :
66
- if self .debug :
67
- print ("_install_zip: %s %s" % (str (pkg ), str (pkg_path )))
72
+ def _install_zip (self , pkg_src , pkg_path ):
68
73
cwd = os .getcwd ()
69
- os .chdir (self .packages_dir )
70
- sys .stdout .flush ()
71
- with ZipFile (pkg_path , 'r' ) as zipObj :
72
- zipObj .extractall (pkg .name )
73
- os .chdir (cwd )
74
- else :
75
- # Copy the .zip file to the destination
76
- if self .debug :
77
- print ("_install_zip: copy file" )
78
- shutil .copyfile (
79
- pkg_path ,
80
- os .path .join (self .packages_dir , pkg .name ))
74
+ try :
75
+ os .chdir (os .path .dirname (pkg_path ))
76
+ sys .stdout .flush ()
77
+ with ZipFile (pkg_src , 'r' ) as zipObj :
78
+ zipObj .extractall (os .path .basename (pkg_path ))
79
+ finally :
80
+ os .chdir (cwd )
81
81
82
82
0 commit comments