예제 #1
0
 def run_previous_uninstaller(self):
     if not self.info.previous_uninstaller_path \
     or not os.path.isfile(self.info.previous_uninstaller_path):
         return
     previous_uninstaller = self.info.previous_uninstaller_path.lower()
     uninstaller = self.info.previous_uninstaller_path
     command = [uninstaller, "--uninstall"]
     # Propagate noninteractive mode to the uninstaller
     if self.info.non_interactive:
         command.append("--noninteractive")
     if 0 and previous_uninstaller.lower() == self.info.original_exe.lower():
         # This block is disabled as the functionality is achived via pylauncher
         if self.info.original_exe.lower().startswith(self.info.previous_target_dir.lower()):
             log.debug("Copying uninstaller to a temp directory, so that we can delete the containing directory")
             uninstaller = tempfile.NamedTemporaryFile()
             uninstaller.close()
             uninstaller = uninstaller.name
             copy_file(self.info.previous_uninstaller_path, uninstaller)
         log.info("Launching asynchronously previous uninstaller %s" % uninstaller)
         run_nonblocking_command(command, show_window=True)
         return True
     elif get_file_md5(self.info.original_exe) == get_file_md5(self.info.previous_uninstaller_path):
         log.info("This is the uninstaller running")
     else:
         log.info("Launching previous uninestaller %s" % uninstaller)
         subprocess.call(command)
         # Note: the uninstaller is now non-blocking so we can just as well quit this running version
         # TBD: make this call synchronous by waiting for the children process of the uninstaller
         self.application.quit()
         return True
예제 #2
0
파일: backend.py 프로젝트: isek/mint4win
 def run_previous_uninstaller(self):
     if not self.info.previous_uninstaller_path \
     or not os.path.isfile(self.info.previous_uninstaller_path):
         return
     previous_uninstaller = self.info.previous_uninstaller_path.lower()
     uninstaller = self.info.previous_uninstaller_path
     if 0 and previous_uninstaller.lower() == self.info.original_exe.lower():
         # This block is disabled as the functionality is achived via pylauncher
         if self.info.original_exe.lower().startswith(self.info.previous_target_dir.lower()):
             log.debug("Copying uninstaller to a temp directory, so that we can delete the containing directory")
             uninstaller = tempfile.NamedTemporaryFile()
             uninstaller.close()
             uninstaller = uninstaller.name
             copy_file(self.info.previous_uninstaller_path, uninstaller)
         log.info("Launching asynchronously previous uninstaller %s" % uninstaller)
         run_nonblocking_command([uninstaller, "--uninstall"], show_window=True)
         return True
     elif get_file_md5(self.info.original_exe) == get_file_md5(self.info.previous_uninstaller_path):
         log.info("This is the uninstaller running")
     else:
         log.info("Launching previous uninestaller %s" % uninstaller)
         subprocess.call([uninstaller, "--uninstall"])
         # Note: the uninstaller is now non-blocking so we can just as well quit this running version
         # TBD: make this call synchronous by waiting for the children process of the uninstaller
         self.application.quit()
         return True
예제 #3
0
파일: backend.py 프로젝트: Ando02/wubiuefi
 def check_metalink(self, metalink, base_url, associated_task=None):
     if self.info.skip_md5_check:
         return True
     url = base_url + "/" + self.info.distro.metalink_md5sums
     metalink_md5sums = downloader.download(url,
                                            self.info.install_dir,
                                            web_proxy=self.info.web_proxy)
     url = base_url + "/" + self.info.distro.metalink_md5sums_signature
     metalink_md5sums_signature = downloader.download(
         url, self.info.install_dir, web_proxy=self.info.web_proxy)
     if not verify_gpg_signature(metalink_md5sums,
                                 metalink_md5sums_signature,
                                 self.info.trusted_keys):
         log.error("Could not verify signature for metalink md5sums")
         return False
     md5sums = read_file(metalink_md5sums)
     log.debug("metalink md5sums:\n%s" % md5sums)
     md5sums = dict(
         [reversed(line.split()) for line in md5sums.split('\n') if line])
     md5sum = md5sums.get(os.path.basename(metalink))
     md5sum2 = get_file_md5(metalink)
     if md5sum != md5sum2:
         log.error("The md5 of the metalink does match")
         return False
     return True
예제 #4
0
파일: backend.py 프로젝트: isek/mint4win
 def check_file(self, file_path, relpath, md5sums, associated_task=None):
     log.debug("  checking %s" % file_path)
     if associated_task:
         associated_task.description = _("Checking %s") % file_path
     relpath = relpath.replace("\\", "/")
     md5line = find_line_in_file(md5sums, "./%s" % relpath, endswith=True)
     if not md5line:
         raise Exception("Cannot find md5 in %s for %s" % (md5sums, relpath))
     reference_md5 = md5line.split()[0]
     md5  = get_file_md5(file_path, associated_task)
     log.debug("  %s md5 = %s %s %s" % (file_path, md5, md5 == reference_md5 and "==" or "!=", reference_md5))
     return md5 == reference_md5
예제 #5
0
 def check_file(self, file_path, relpath, md5sums, associated_task=None):
     log.debug("  checking %s" % file_path)
     if associated_task:
         associated_task.description = _("Checking %s") % file_path
     relpath = relpath.replace("\\", "/")
     md5line = find_line_in_file(md5sums, "./%s" % relpath, endswith=True)
     if not md5line:
         raise Exception("Cannot find md5 in %s for %s" % (md5sums, relpath))
     reference_md5 = md5line.split()[0]
     md5  = get_file_md5(file_path, associated_task)
     log.debug("  %s md5 = %s %s %s" % (file_path, md5, md5 == reference_md5 and "==" or "!=", reference_md5))
     return md5 == reference_md5
예제 #6
0
 def create_by_upload_file(cls, uploaded_file):
     rst = uploaded_file
     with open(rst.path) as f:
         filemd5 = get_file_md5(f)
         uploaded_file = cls.get_by_md5(filemd5)
         if uploaded_file:
             os.remove(rst.path)
             return uploaded_file
     filestat = os.stat(rst.path)
     rst.size = filestat.st_size
     rst.filemd5 = filemd5
     return rst
예제 #7
0
 def create_by_upload_file(cls, uploaded_file):
     rst = uploaded_file
     with open(rst.path) as f:
         filemd5 = get_file_md5(f)
         uploaded_file = cls.get_by_md5(filemd5)
         if uploaded_file:
             os.remove(rst.path)
             return uploaded_file
     filestat = os.stat(rst.path)
     rst.size = filestat.st_size
     rst.filemd5 = filemd5
     return rst
예제 #8
0
 def create_by_upload_file(cls, uploaded_file):
     rst = cls(uploaded_file.filename, uploaded_file.mimetype, 0)
     uploaded_file.save(rst.path)
     with open(rst.path, 'rb') as f:
         filemd5 = get_file_md5(f)
         uploaded_file = cls.get_by_md5(filemd5)
         if uploaded_file:
             os.remove(rst.path)
             return uploaded_file
     filestat = os.stat(rst.path)
     rst.size = filestat.st_size
     rst.filemd5 = filemd5
     return rst
예제 #9
0
 def create_by_upload_file(cls, upload_file):
     rst = cls(upload_file.filename, upload_file.mimetype, 0)
     upload_file.save(rst.path)
     with open(rst.path, 'rb') as f:
         filemd5 = get_file_md5(f)
         upload_file = cls.get_by_md5(filemd5)
         if upload_file:
             os.remove(rst.path)
             return upload_file
     filestat = os.stat(rst.path)
     rst.size = filestat.st_size
     rst.filemd5 = filemd5
     return rst
예제 #10
0
 def create_by_upload_file(cls, uploaded_file):
     rst = cls(uploaded_file.filename, uploaded_file.mimetype, 0)
     # 创建PasteFile实例前会先保存文件,保存的文件名是rst.path。如果通过被上传文件的md5值判断的文件之前已经上传过,则直接删掉这个文件,并返回之前创建的文件
     uploaded_file.save(rst.path)
     with open(rst.path, 'rb') as f:
         filemd5 = get_file_md5(f)
         uploaded_file = cls.get_by_md5(filemd5)
         if uploaded_file:
             os.remove(rst.path)
             return uploaded_file
     filestat = os.stat(rst.path)
     rst.size = filestat.st_size
     rst.filemd5 = filemd5
     return rst
예제 #11
0
    def post(self):
        """上传资源包"""
        (resource, ) = get_params([
            Argument('file', type=FileStorage, location=('files',),
                     required=True),
        ])
        base_path = upload_resource.config.destination
        md5 = get_file_md5(resource)
        file_exp = resource.filename
        filename, exp = os.path.splitext(file_exp)

        if not os.path.exists(os.path.join(base_path, md5)):
            # 解压到指定目录,因为要避免解压压缩包名与解压出来的根文件名不一致,需要先读取根文件名
            file_handle = FileHandle(md5, base_path)
            z_dir = file_handle.unpack_archive(resource, base_path)

            # 将根目录文件名修改为md5作为文件名
            rename_src = '{0}/{1}'.format(base_path, z_dir)
            rename_dst = '{0}/{1}'.format(base_path, md5)
            file_handle.dir_rename(rename_src, rename_dst)

            # 压缩到download_path
            file_handle.make_archive(os.path.join(base_path, md5),
                                     os.path.join(base_path, md5))
            # 转为md5命名
            md5_name = md5 + exp

            file = Model.FileInfo.new(
                name=md5_name,
                path=os.path.join(base_path, md5_name),
                size=len(resource.read()),
                md5=md5,
                exp=exp
            )
        else:
            file = FileInfo.get_by_md5(md5)

        file_handle = ResourcePackHandle(md5)
        Model.ResourcePack.new(
            name=file_handle.get_config_name() if file_handle.get_config_name() else filename,
            file_id=file.id,
            url=md5,
            cover_image=file_handle.get_cover_image(),
        )

        db.session.commit()

        return Response()
예제 #12
0
def upload_ec():
    upload_file = request.files['file']
    file_path = get_file_path(hash_filename(upload_file.filename))
    upload_file.save(file_path)
    with open(file_path, 'rb') as f:
        for line in f:
            filemd5 = get_file_md5(line)
            uploaded_file = ECR.get_file_bymd5(filemd5)
            if not uploaded_file:
                _tmp = json.loads(line)
                creditcode = _tmp.get('ReportHeader')[0].get('CreditCode')
                ecr = ECR(creditcode=creditcode,
                          File_content=line,
                          Size=getsizeof(line),
                          File_md5=filemd5)
                db.session.add(ecr)
                db.session.commit()
    return "EC Data Upload Success!"
예제 #13
0
파일: backend.py 프로젝트: isek/mint4win
 def check_metalink(self, metalink, base_url, associated_task=None):
     #if self.info.skip_md5_check:
     return True
     url = base_url +"/" + self.info.distro.metalink_md5sums
     metalink_md5sums = downloader.download(url, self.info.install_dir, web_proxy=self.info.web_proxy)
     url = base_url +"/" + self.info.distro.metalink_md5sums_signature
     metalink_md5sums_signature = downloader.download(url, self.info.install_dir, web_proxy=self.info.web_proxy)
     if not verify_gpg_signature(metalink_md5sums, metalink_md5sums_signature, self.info.trusted_keys):
         log.error("Could not verify signature for metalink md5sums")
         return False
     md5sums = read_file(metalink_md5sums)
     log.debug("metalink md5sums:\n%s" % md5sums)
     md5sums = dict([reversed(line.split()) for line in md5sums.split('\n') if line])
     md5sum = md5sums.get(os.path.basename(metalink))
     md5sum2 = get_file_md5(metalink)
     if md5sum != md5sum2:
         log.error("The md5 of the metalink does match")
         return False
     return True
예제 #14
0
def upload_ic():
    upload_file = request.files['file']
    file_path = get_file_path(hash_filename(upload_file.filename))
    upload_file.save(file_path)
    with open(file_path, 'rb') as f:
        for line in f:
            filemd5 = get_file_md5(line)
            uploaded_file = ICR.get_file_bymd5(filemd5)
            if not uploaded_file:
                _tmp = json.loads(line)
                Name = _tmp.get('ICRHeader')[0].get('Name')
                Certno = _tmp.get('ICRHeader')[0].get('Certno')
                icr = ICR(Name=Name,
                          Cert_no=Certno,
                          File_content=line,
                          Size=getsizeof(line),
                          File_md5=filemd5)
                db.session.add(icr)
                db.session.commit()
    return "IC Data Upload Success!"
예제 #15
0
파일: main.py 프로젝트: shuai132/loop_bgm
def wav_2_mp3(wav_file, mp3_file, xml_file, mid_file):
    for file in [wav_file, xml_file, mid_file]:
        if not os.path.isfile(file):
            print("error: 缺少文件:", file)
            return

    try:
        tempo, duration = process_score.get_score_info(xml_file, mid_file)
    except Exception as e:
        print("error: 请处理异常:", e)
        traceback.print_exc(file=sys.stdout)
        return

    wav_md5 = utils.get_file_md5(wav_file)
    info = config.WAV_INFO.get(wav_md5)
    if info is None:
        print("error: 缺少md5配置:", wav_file, wav_md5)
        return

    rate = tempo/info["tempo"]

    print("开始转换:", wav_file, rate, duration)
    process_wav.convert_wav(wav_file, mp3_file, rate, duration)
예제 #16
0
import utils
import os
import decompiler
import scanner
import constant

file_list = []

for files in os.walk(constant.APK_SOURCES_DIR):
    file_list = files[2]  # get a apk name list

for i in range(0, file_list.__len__(), 1):
    file_name = file_list[i]
    src_path = constant.APK_SOURCES_DIR + file_name
    file_md5 = utils.get_file_md5(src_path)

    file_size = os.path.getsize(src_path)
    file_size /= float(1024 * 1024)
    file_size = round(file_size, 2)
    print('1. file_md5: ' + file_md5)
    print('2. file_name: ' + file_name)
    print('3. file_size: ' + str(file_size) + 'MB')
    dst_path = constant.OUTCOMES_DIR + file_md5 + '/'

    try:
        utils.make_dir(dst_path)
    except OSError:
        print('3. The Num.' + str(i) + ' apk workspace has existed')
    else:
        print('>> The Num.' + str(i) +
              ' workspace is been created in outcomes successfully')
예제 #17
0
 def get_file_md5(self):
     if not self.apk_md5:
         self.apk_md5 = utils.get_file_md5(self.apk_file)
     return self.apk_md5