Beispiel #1
0
def renamePkg(pkg_file_path):
    try:
        pkgInfo = pkg_parser.getPkgInfo(pkg_file_path)

        if (pkgInfo):
            format_out = ''
            if (args.custom_format):
                # use custom formatting
                format_out = doDictFormat(args.custom_format, pkgInfo)
            elif (args.name_format):
                # format with readable name
                format_out = doDictFormat(NAME_FORMAT, pkgInfo)
            else:
                # use default sony format
                if pkgInfo['CONTENT_ID'] and pkgInfo['APP_VER'] and pkgInfo[
                        'VERSION']:
                    format_out = '{0}-A{1}-V{2}'.format(
                        pkgInfo['CONTENT_ID'],
                        pkgInfo['APP_VER'].replace('.', ''),
                        pkgInfo['VERSION'].replace('.', ''))
                else:
                    raise pkg_parser.MyError('parsing of param.sfo failed')
            format_out = format_out + '.pkg'

            print 'Renaming \'' + os.path.split(
                pkg_file_path)[1] + '\' to \'' + format_out + '\''
            if (args.testrun == False):
                if (os.path.split(pkg_file_path)[1] == format_out):
                    print '  Skipped, same filename already set.'
                else:
                    pkg_new_file_path = os.path.join(
                        os.path.dirname(os.path.abspath(pkg_file_path)),
                        format_out)
                    if os.path.exists(pkg_new_file_path):
                        raise pkg_parser.MyError('file \'' +
                                                 pkg_new_file_path +
                                                 '\' already exists!')
                    else:
                        os.rename(pkg_file_path, pkg_new_file_path)

    except pkg_parser.MyError as e:
        print 'ERROR:', e.message
    except:
        print u'ERROR: unexpected error:  {} ({})'.format(
            sys.exc_info()[0], pkg_file_path)
        traceback.print_exc(file=sys.stdout)
		s_u = s
	return s_u

## main code
# parse files


        
pkgInfos = {'app' : [], 'upd' : [], 'ps2' : [], 'err' : [], 'count' : 0}
for pkg_path in pkg_paths:
	for root, directories, files in os.walk(pkg_path):
		for file in files: 
			if file.lower().endswith('.pkg'):
				try:
					pkgInfos['count'] += 1
					pkgInfo = pkg_parser.getPkgInfo(os.path.join(root, file))
					# set worksheet
					if (pkgInfo['CATEGORY'] == 'gp'):
						# update
						pkgInfos['upd'].append(pkgInfo)
					elif (pkgInfo['CATEGORY'] == 'gpo'):
						# PS2
						pkgInfos['ps2'].append(pkgInfo)
					else:
						# Application / Game 'gd' and unknown
						pkgInfos['app'].append(pkgInfo)
				except:
					# failed to parse pkg
					pkgInfos['err'].append(file)
		if not (args.recursive):
			break