Beispiel #1
0
def unzip_plugin(target_file, target_folder):
    """ Unzip a plugin that is packaged in a zip. """
    with ZipFile(target_file, 'r') as zipped:
        folders = [x for x in zipped.namelist()
                   if x.endswith('/')]
        jars = [x for x in zipped.namelist()
                if x.endswith('.jar')]

        strip_folder = False
        if len(jars) == 0 and len(folders) > 0:
            folder = folders[0]
            # All jars in folder
            jars = [x for x in zipped.namelist()
                    if x.endswith('.jar')
                    and x.startswith(folder)]
            strip_folder = folder

        for jar in jars:
            destination = target_folder
            if strip_folder:
                destination += jar.split(strip_folder, 1)[1]
            else:
                destination += jar

            common.extract_file(zipped, jar, destination)
Beispiel #2
0
 def test_extract_sub_file(self):
     """ Test common.extract_file with file in subfolder. """
     common.extract_file(self.zipfile, 'herp/bar/baz.txt',
                         self.test_folder + 'herp/bar/baz.txt')
     assert os.path.isdir(self.test_folder + 'herp')
     assert os.path.isdir(self.test_folder + 'herp/bar')
     with open(self.test_folder + 'herp/bar/baz.txt', 'r') as file:
         assert file.readline() == 'baz\n'
Beispiel #3
0
 def test_extract_sub_file(self):
     """ Test common.extract_file with file in subfolder. """
     common.extract_file(self.zipfile, 'herp/bar/baz.txt',
                         self.test_folder + 'herp/bar/baz.txt')
     assert os.path.isdir(self.test_folder + 'herp')
     assert os.path.isdir(self.test_folder + 'herp/bar')
     with open(self.test_folder + 'herp/bar/baz.txt', 'r') as file:
         assert file.readline() == 'baz\n'
Beispiel #4
0
def unzip_plugin(target_file, target_folder):
    """ Unzip a plugin that is packaged in a zip. """
    with ZipFile(target_file, 'r') as zipped:
        folders = [x for x in zipped.namelist() if x.endswith('/')]
        jars = [x for x in zipped.namelist() if x.endswith('.jar')]

        strip_folder = False
        if len(jars) == 0 and len(folders) > 0:
            folder = folders[0]
            # All jars in folder
            jars = [
                x for x in zipped.namelist()
                if x.endswith('.jar') and x.startswith(folder)
            ]
            strip_folder = folder

        for jar in jars:
            destination = target_folder
            if strip_folder:
                destination += jar.split(strip_folder, 1)[1]
            else:
                destination += jar

            common.extract_file(zipped, jar, destination)
Beispiel #5
0
 def test_extract_sub_folder(self):
     """ Test common.extract_file with folder in subfolder. """
     common.extract_file(self.zipfile, 'herp/bar/',
                         self.test_folder + 'herp/bar/')
     assert os.path.isdir(self.test_folder + 'herp')
     assert os.path.isdir(self.test_folder + 'herp/bar')
Beispiel #6
0
 def test_extract_base_folder(self):
     """ Test common.extract_file with folder in base of zip. """
     common.extract_file(self.zipfile, 'herp/', self.test_folder + 'herp/')
     assert os.path.isdir(self.test_folder + 'herp')
Beispiel #7
0
 def test_extract_base_file(self):
     """ Test common.extract_file with file in base of zip. """
     common.extract_file(self.zipfile, 'foo.txt',
                         self.test_folder + 'foo.txt')
     with open(self.test_folder + 'foo.txt', 'r') as file:
         assert file.readline() == 'foo\n'
Beispiel #8
0
 def test_extract_sub_folder(self):
     """ Test common.extract_file with folder in subfolder. """
     common.extract_file(self.zipfile, 'herp/bar/',
                         self.test_folder + 'herp/bar/')
     assert os.path.isdir(self.test_folder + 'herp')
     assert os.path.isdir(self.test_folder + 'herp/bar')
Beispiel #9
0
 def test_extract_base_folder(self):
     """ Test common.extract_file with folder in base of zip. """
     common.extract_file(self.zipfile, 'herp/', self.test_folder + 'herp/')
     assert os.path.isdir(self.test_folder + 'herp')
Beispiel #10
0
 def test_extract_base_file(self):
     """ Test common.extract_file with file in base of zip. """
     common.extract_file(self.zipfile, 'foo.txt',
                         self.test_folder + 'foo.txt')
     with open(self.test_folder + 'foo.txt', 'r') as file:
         assert file.readline() == 'foo\n'