Esempio n. 1
0
 def _extractStaticFiles(self, bdata, hash_value, urlPrefix,
                         contentServiceType):
     '''
     Extract static files into ezappStaticdir
     '''
     try:
         tfile = utils.getTempfile()
         with open(tfile, "w+b") as f:
             f.write(bdata)
         url_hash = str(urlPrefix + "_" + hash_value)
         if contentServiceType == ContentServiceType.HYBRID:
             filelist = [
                 archive.Archive(path_to_extract=os.path.join(
                     self._buildDir, url_hash, urlPrefix,
                     self._staticPathInLocation),
                                 archive_file=tfile)
             ]
         else:
             filelist = [
                 archive.Archive(path_to_extract=os.path.join(
                     self._buildDir, url_hash, urlPrefix),
                                 archive_file=tfile)
             ]
         filesToExtract = archive.openArchive(filelist)
         self._logger.debug(
             'Extracting archive_file "{0}" into path "{1}"'.format(
                 filelist[0].archive_file, filelist[0].path_to_extract))
         archive.extractArchive(filesToExtract)
         utils.remove_file_if_exists(tfile)
         return True
     except Exception as e:
         utils.remove_file_if_exists(tfile)
         self._logger.exception(
             'Exception while Extracting: urlPrefix {0}}'.format(urlPrefix))
         return False
def is_data_archive(data):
    '''
    Check if the data blob is in archive format
    '''
    status = False
    try:
        tfile = utils.getTempfile()
        f = open(tfile,'wb')
        f.write(data)
        f.close()       
        status = is_archive(tfile)
    except IOError:
        "Should not happen"
        status = False
    finally:
        utils.remove_file_if_exists(tfile)
        return status
 def _extractStaticFiles(self, bdata, hash_value, urlPrefix, contentServiceType):
     '''
     Extract static files into ezappStaticdir
     '''
     try:
         tfile = utils.getTempfile()
         with open(tfile, "w+b") as f:
             f.write(bdata)
         url_hash = str(urlPrefix + "_" + hash_value)
         if contentServiceType == ContentServiceType.HYBRID:
             filelist = [archive.Archive(path_to_extract=os.path.join(self._buildDir, url_hash, urlPrefix, self._staticPathInLocation), archive_file=tfile)]
         else:
             filelist = [archive.Archive(path_to_extract=os.path.join(self._buildDir, url_hash, urlPrefix), archive_file=tfile)]
         filesToExtract = archive.openArchive(filelist)
         self._logger.debug('Extracting archive_file "{0}" into path "{1}"'.format(filelist[0].archive_file, filelist[0].path_to_extract))
         archive.extractArchive(filesToExtract)
         utils.remove_file_if_exists(tfile)
         return True
     except Exception as e:
         utils.remove_file_if_exists(tfile)
         self._logger.exception('Exception while Extracting: urlPrefix {0}}'.format(urlPrefix))
         return False