コード例 #1
0
ファイル: admin.py プロジェクト: plutokamin/pujiahh
def make_cntxt(modeladmin, request, queryset):
    for project in queryset:
        project_dir = os.path.dirname(__file__) + '/games/%s/jp/'%project.project_name
        fl = Pluto.walk(project_dir)
        for fn in fl:
            if not fnmatch.fnmatch(fn,'*.pickle'):
                continue
            fp = open(fn,'rb')
            sid_list = cPickle.load(fp)
            fp.close()
            headlist = []
            jplines = codecs.open(fn.replace('.pickle','.txt'), 'rb', 'utf16').readlines()
            for line in jplines:
                if u'####' in line:
                    headlist.append(line)

            strings = String.objects.filter(id__in=sid_list)
            dic = dict([(s.id, s) for s in strings])
            dest = codecs.open(fn.replace('.pickle','.txt').replace('/jp/','/cn/'), 'wb', 'utf16')
            for index,sid in enumerate(sid_list):
                string = dic[sid]
                dest.write('%s%s\r\n\r\n'%(headlist[index], string.dest))
            dest.close()
        import zipfile, random
        i = random.randint(1000000000000000,9999999999999999)
        z = zipfile.ZipFile(os.path.dirname(__file__).replace('projects','') + \
                            '/static/files/%s_%s_%d.zip'%(project.project_name, datatime, i), 'w', zipfile.ZIP_DEFLATED)
        fl = Pluto.walk(os.path.dirname(__file__) + '/games/%s/cn/'%project.project_name)
        for fn in fl:
            z.write(str(fn), str(fn.replace(project_dir.replace('/jp/','/cn/'),'')))
        z.close()
コード例 #2
0
ファイル: admin.py プロジェクト: plutokamin/pujiahh
def add_string(modeladmin, request, queryset):
    try:
        newstring = String.objects.select_related().order_by('-id')[0]
        sid = newstring.id + 1
    except:
        sid = 1
    updateuser = User.objects.get(id=41)
    for project in queryset:
        project_dir = os.path.dirname(__file__) + '/games/%s/jp/'%project.project_name
        fl = Pluto.walk(project_dir)
        allstring = String.objects.select_related().filter(project_name=project.project_name, state__in=['1','2'])
        for fn in fl:
            if not fnmatch.fnmatch(fn,'*.txt'):
                continue
            if os.path.exists(fn.replace('.txt','')+'.pickle'):
                continue
            lines = codecs.open(fn,'rb','utf16').readlines()
            strjp = makestr(lines)
            sidlist = []
            file_name = fn.replace(project_dir,'').replace('.txt','')
            for i,string in enumerate(strjp):
                sidlist.append(sid)
                sl = allstring.filter(src=string)
                if sl:
                    s = String(id=sid, src=string, dest=sl[0].dest, project_name=project.project_name,\
                        file_name=file_name, updata_time=nowtime, state=sl[0].state, name=updateuser)
                else:
                    s = String(id=sid, src=string, dest=string, project_name=project.project_name, \
                           file_name=file_name, updata_time=nowtime, state=0, name=updateuser)
                s.save()
                sid += 1
            dest = open(fn[:-4]+'.pickle','wb')
            cPickle.dump(sidlist,dest)
            dest.close()
コード例 #3
0
ファイル: admin.py プロジェクト: plutokamin/pujiahh
def update_project(modeladmin, request, queryset):
    for project in queryset:
        pn = project.project_name
        fn_dir = os.path.dirname(__file__) + '/games/%s/jp/'%pn
        fl = Pluto.walk(fn_dir)
        for fn in fl:
            if not fnmatch.fnmatch(fn,'*.pickle'):
                continue
            fp = open(fn, 'rb')
            sid_list = cPickle.load(fp)
            fp.close()
            String.objects.filter(id__in=sid_list).update(project_name = pn)
コード例 #4
0
ファイル: admin.py プロジェクト: plutokamin/pujiahh
def import2project(modeladmin, request, queryset):
    for project in queryset:
        pid  = project.id
        project_dir = os.path.dirname(__file__) + '/games/%s/jp/'%project.project_name
        fl = Pluto.walk(project_dir)
        for fn in fl:
            if not fnmatch.fnmatch(fn,'*.pickle'):
                continue
            fp = open(fn,'rb')
            sid_list = cPickle.load(fp)
            fp.close()
            length = len(set(sid_list))
            fn = fn.replace(project_dir,'').replace('.pickle','')
            if Files.objects.filter(item=pid, filename=fn):
                continue
            f = Files(item_id=pid, filename=fn, length=length, length_tran=0, rate=0)
            f.save()
コード例 #5
0
ファイル: admin.py プロジェクト: plutokamin/pujiahh
def update_remarks(modeladmin, request, queryset):
    for project in queryset:
        update_string_dir = os.path.dirname(__file__) + '/games/%s/remarks/'%project.project_name
        fl = Pluto.walk(update_string_dir)
        for fn in fl:
            if not fnmatch.fnmatch(fn,'*.txt'):
                continue
            lines = codecs.open(fn,'rb','utf16').readlines()
            update_string = makestr(lines)
            fp = open(fn.replace('.txt','').replace('/remarks/','/jp/') + '.pickle', 'rb')
            sid_list = cPickle.load(fp)
            strings = String.objects.filter(id__in=sid_list)
            dic = dict([(s.id, s) for s in strings])
            strings = [dic[sid] for sid in sid_list]
            fp.close()
            for i,string in enumerate(update_string):
                tarstring = strings[i]
                tarstring.remarks = string
                tarstring.save()
コード例 #6
0
ファイル: intodb.py プロジェクト: plutokamin/pujia8
import sqlite3,Pluto
conn = sqlite3.connect('translate.db')
cu = conn.cursor()
fl = Pluto.walk('webappimg')
for i,fn in enumerate(fl):
    cu.execute('insert into webapp_chungu values(%d,"%s","name",3,3,3,3,"shuoming",1)'%(i+1,fn.replace('\\','/')))
conn.commit()
コード例 #7
0
ファイル: check.py プロジェクト: plutokamin/pujiahh
def makestr(lines):
    string_list = []
    num = len(lines)
    for index,line in enumerate(lines):
        if u'####' in line:
            i = 1
            string = ''
            while True:
                if index+i >= num:
                    break
                if '####' in lines[index+i]:
                    break
                string += lines[index+i]
                i += 1
            string_list.append(string[:-4])
    return string_list

fl = Pluto.walk('jingujisaburo')
for fn in fl:
    if not fnmatch.fnmatch(fn,'*.txt'):
        continue
    #print fn
    lines = codecs.open(fn,'rb','utf16').readlines()
    lines_cn = codecs.open(fn.replace('\\jp\\','\\update\\'),'rb','utf16').readlines()
    lenjp = len(makestr(lines))
    lencn = len(makestr(lines_cn))
    if lenjp != lencn:
        print fn, lenjp, lencn