def cache_files(): # put all sound files in RAM drive for better performance, if not already there if os.path.exists("D:\\ptopc.mid"): dummy1=0 else: for filename in soundfiles: fromfile = "E:\\musician\\%s" % filename tofile = "D:\\%s" % filename e32.file_copy(tofile, fromfile)
def prepareMediaFile(filename): mdir = unicode(import_path + u'mp3\\'+ filename) adlres = abs(zlib.adler32(mdir)) newname = unicode(media_path + "%x" % (adlres) + ".wav") print "file: ",mdir, "hash: ", adlres, "new name: ", newname if not os.access(newname,os.F_OK): e32.file_copy(newname,mdir) #os.remove(mdir) listoffile.append(newname) return adlres
def test_file_copy(self): # Create two temp files to copy and read. fp = open(file_to_copy, 'w') fp.write(text) fp.close() e32.file_copy(file_copied_to, file_to_copy) fp = open(file_copied_to, 'r') content = fp.read() self.failUnlessEqual(content, text) fp.close() os.remove(file_copied_to) os.remove(file_to_copy)
def back(): folder = "E:\\Siraj\\" files = os.listdir(folder) target = 'E:\\Back\\' count = len(files) for i in range(count): t_file = folder + "\\" + files[i] e32.file_copy(target, t_file) appuifw.note(u"Backup complete!")
def saveMap(self): i=0 for f in os.listdir("e:"): if f=="myPlaces": i=1 if i==0: os.mkdir("e:\\myPlaces") word = appuifw.query(u"Enter a name for this map", 'text') source="e:\\tmp_map.jpg" target="e:\\myPlaces\\"+word+".jpg" try: e32.file_copy(target,source) appuifw.note(u'Map Saved','info') except: appuifw.note(u'Map Could Not Saved','info')
def runPhp(code, code_file_path): """Writes PHP code to a file, and runs the resulting script. php_output -- global variable that contains the output path of the CLI PHP. code -- the PHP code to run code_file_path -- the path to write the script to """ code_file = open( code_file_path, 'w' ) try: code_file.write( code ) finally: code_file.close() e32.start_exe( php_exe, ' -f ' + code_file_path + r' -c C:\Data\PHP\php-cli.ini', True ) def save_zend_log (): if os.path.isfile( zend_log ): e32.file_copy( code_file_path[:-4] + "_zend_log.txt", zend_log ) os.remove( zend_log ) if not os.path.isfile( php_output ): save_zend_log() return PHP_OUTPUT_NOT_FOUND_MESSAGE php_output_size = os.path.getsize( php_output ) if php_output_size > MAX_PHP_OUTPUT_SIZE: e32.file_copy( code_file_path[:-4] + "_output.txt", php_output ) save_zend_log() return 'PHP output "' + php_output + '" too big: '+ str( php_output_size ) + ' bytes.' try: php_output_file = open( php_output, 'r' ) return php_output_file.read() finally: php_output_file.close() e32.file_copy( code_file_path[:-4] + "_output.txt", php_output ) os.remove( code_file_path ) save_zend_log()
def import_scenario(): import_from=appuifw.query(u'import to:','text',os.path.splitdrive(appuifw.app.full_name())[0]+u'\\import.csv') if check(import_from,'r')==1: e32.file_copy(homecsv+os.path.split(import_from)[1],import_from)
def export_scenario(): export_from=homecsv+select_scenario() export_to=appuifw.query(u'export to:','text',os.path.splitdrive(appuifw.app.full_name())[0]+u'\\export.csv') if check(export_to,'w')==1: e32.file_copy(export_to,export_from)
def save_zend_log (): if os.path.isfile( zend_log ): e32.file_copy( code_file_path[:-4] + "_zend_log.txt", zend_log ) os.remove( zend_log )
def standalone_install(self, filename): def reverse(L): L.reverse(); return L def atoi(s): # Little-endian conversion from a 4-char string to an int. sum = 0L for x in reverse([x for x in s[0:4]]): sum = (sum << 8) + ord(x) return sum def itoa(x): # Little-endian conversion from an int to a 4-character string. L=[chr(x>>24), chr((x>>16)&0xff), chr((x>>8)&0xff), chr(x&0xff)] L.reverse() return ''.join(L) try: offset = int(file(os.path.join(self.python_drive(), self.APPMGR_PATH, 'uid_offset_in_app')).read(), 16) except: offset = None temp=appuifw.query(u'Application name:','text',unicode(os.path.splitext(os.path.split(filename)[1])[0])) if temp: app_rootname = str(temp) else: self.note_once(1, 1); return app_dir = os.path.join(self.python_drive(), self.APPS_PATH, app_rootname) uid_status=1; uid_text='0x1' while uid_status==1: script = open(filename).read() uidpos = script.find('SYMBIANUID')+10 try: uidpos += script[uidpos:uidpos+5].index('0x')+2 except ValueError: pass else: uid_text = '0x'+script[uidpos:uidpos+8] uid_input = appuifw.query(u'UID (8 digits hexadecimal)\n 0x12345678', 'text', unicode(uid_text)) if uid_input: try: uid = int(uid_input, 16) except: appuifw.note(u'Bad UID value', 'error') uid_text=uid_input else: try: crc1 = itoa(e32._uidcrc_app(uid)) except ValueError: appuifw.note(u'Bad UID value', 'error') else: uid_status = 2 else: uid_status = 0 if not uid_status: self.note_once(1, 1); return # copy the script to application's directory as default.py if not os.path.isdir(app_dir): os.mkdir(app_dir) try: e32.file_copy(unicode(os.path.join(app_dir, 'Default.py')), unicode(filename)) except SymbianError: self.note_once('File already in use', 0) # copy the template .app file to application directory with proper name # and set the UID and checksum fields suitably template_dotapp = file(os.path.join(self.python_drive(), self.APPMGR_PATH, 'pyapp_template.tmp')) dotapp_name = app_rootname + '.app' dotapp = file(os.path.join(app_dir, dotapp_name), 'w') appbuf = template_dotapp.read() csum = atoi(appbuf[24:28]) crc2 = itoa(( uid + csum ) & 0xffffffffL) if offset: temp = appbuf[0:8] + itoa(uid) + crc1 + appbuf[16:24] + crc2 +\ appbuf[28:offset] + itoa(uid) + appbuf[(offset+4):] else: temp = appbuf[0:8] + itoa(uid) + crc1 + appbuf[16:24] + crc2 + appbuf[28:] dotapp.write(temp) # copy the template .rsc file to application directory with proper name rsc_name = app_rootname + '.rsc' e32.file_copy(unicode(os.path.join(app_dir, app_rootname + '.rsc')), unicode(os.path.join(self.python_drive(), self.APPMGR_PATH, 'pyrsc_template.tmp')))
def do_copy(self, src, dst): if not os.path.isdir(dst): os.mkdir(os.path.split(dst)) try: e32.file_copy(unicode(dst), unicode(src)) except SymbianError: self.note_once('File already in use',0)
import appuifw, e32 select_list=[u'Menu: Backup',u'Menu: Restore'] i=appuifw.popup_menu(select_list) if not appuifw.query(u'Confirm\n'+select_list[i],'query'): i=None if i in (0,1): import appswitch dirs=r'E:\Backup\OS\Applications.dat',r'C:\System\Data\Applications.dat' if u'Menu' in appswitch.application_list(0): m = appuifw.popup_menu([u'End',u'Kill'],u'Menu') if m==0: appswitch.end_app(u'Menu') if m==1: appswitch.kill_app(u'Menu') if i==0: e32.file_copy(dirs[0],dirs[1]) if i==1: e32.file_copy(dirs[1],dirs[0]) if i>=0: appuifw.note(u'Done\n'+select_list[i],'conf')
def copy(x, y): e32.file_copy(x, y) print ('copy ' + y + '\r\nin ' + x + '\r\n'), print e32.ao_yield()
def standalone_install(filename): def reverse(L): L.reverse() return L def atoi(s): # Little-endian conversion from a 4-char string to an int. sum = 0L for x in reverse([x for x in s[0:4]]): sum = (sum << 8) + ord(x) return sum def itoa(x): # Little-endian conversion from an int to a 4-character string. L = [ chr(x >> 24), chr((x >> 16) & 0xff), chr((x >> 8) & 0xff), chr(x & 0xff) ] L.reverse() return ''.join(L) try: offset = int( file(os.path.join(python_drive(), APPMGR_PATH, 'uid_offset_in_app')).read(), 16) except: offset = None app_rootname = os.path.splitext(os.path.split(filename)[1])[0] app_dir = os.path.join(python_drive(), APPS_PATH, app_rootname) # # read the UID from the script file # script = file(filename, 'r').read() uidpos = script.find('SYMBIANUID=') if uidpos == -1: uid_text = appuifw.query(u'Give UID', 'text', u'0xXXXXXXXX') if not uid_text == None: uid = int(uid_text, 16) else: appuifw.note(u"Installation cancelled", "info") return else: uidpos = uidpos + len('SYMBIANUID=') while uidpos + 10 < len(script) and script[uidpos].isspace(): uidpos = uidpos + 1 if uidpos == len(script): appuifw.note(u"UID not found", "error") return else: uid = int(script[uidpos:uidpos + 10], 16) # # copy the script to application's directory as default.py # if not os.path.isdir(app_dir): os.mkdir(app_dir) e32.file_copy(unicode(os.path.join(app_dir, 'default.py')), unicode(filename)) # # copy the template .app file to application directory with proper name # and set the UID and checksum fields suitably # template_dotapp = file( os.path.join(python_drive(), APPMGR_PATH, 'pyapp_template.tmp')) dotapp_name = app_rootname + '.app' dotapp = file(os.path.join(app_dir, dotapp_name), 'w') appbuf = template_dotapp.read() csum = atoi(appbuf[24:28]) crc1 = itoa(e32._uidcrc_app(uid)) crc2 = itoa((uid + csum) & 0xffffffffL) if offset: temp = appbuf[0:8] + itoa(uid) + crc1 + appbuf[16:24] + crc2 +\ appbuf[28:offset] + itoa(uid) + appbuf[(offset+4):] else: temp = appbuf[0:8] + itoa( uid) + crc1 + appbuf[16:24] + crc2 + appbuf[28:] dotapp.write(temp) # # copy the template .rsc file to application directory with proper name # rsc_name = app_rootname + '.rsc' e32.file_copy( unicode(os.path.join(app_dir, app_rootname + '.rsc')), unicode(os.path.join(python_drive(), APPMGR_PATH, 'pyrsc_template.tmp')))
def do_copy(src, dst_dir): dst = os.path.join(dst_dir, os.path.split(src)[1]) if not os.path.isdir(dst_dir): os.mkdir(dst_dir) e32.file_copy(unicode(dst), unicode(src))
import e32 e32.file_copy(u"c:\\new.txt", u"e:\\new.txt") #把E盘new.txt复制到C盘
def copy_file(from_dir, to_dir): global running try: f = open(INIpath, 'r') Content = f.read() f.close() R = re.compile('\\[(.*?)->(.*?)\\]') ToBeRenamed = R.findall(Content) try: FN = re.compile('#\\[FileName:(.*?)]') Filename = FN.findall(Content)[0] MB = re.compile('#\\[MadeBy:(.*?)]') Madeby = MB.findall(Content)[0] CT = re.compile('#\\[Contact:(.*?)]') Contact = CT.findall(Content)[0] Filename = cn(Filename) Madeby = cn(Madeby) Contact = cn(Contact) if (running == 0): pt((u'%s\n' % Filename)) e32.ao_sleep(1) pt((cn('制作:') + (u'%s\n' % Madeby))) e32.ao_sleep(2) pt((cn('联系方式') + (u'%s' % Contact))) pt(cn('正在读取...')) running = 1 e32.ao_sleep(2) except: pt(cn('未发现作者相关信息')) except: ToBeRenamed = None All_files = os.listdir(en(from_dir)) pt((cn('创建文件夹:%s') % to_dir)) os.mkdir(en(to_dir)) for i in range(0, len(All_files)): if (ToBeRenamed != None): for ti in ToBeRenamed: if (ti[0].lower() == All_files[i].lower()): try: RenameTo = (ti[1] % ASK_path) except: RenameTo = ti[1] break else: RenameTo = All_files[i] else: RenameTo = All_files[i] if (os.path.isfile(((en(from_dir) + '\\') + All_files[i])) == 1): try: pt((cn('复制%s到%s') % (cn(All_files[i]), cn(RenameTo)))) except: pt((cn('复制%s到%s') % (cn(All_files[i]), RenameTo))) try: e32.file_copy(((to_dir + '\\') + cn(RenameTo)), ((from_dir + '\\') + cn(All_files[i]))) except: e32.file_copy(((to_dir + '\\') + RenameTo), ((from_dir + '\\') + cn(All_files[i]))) else: try: RenameTo1 = cn(RenameTo) except: RenameTo1 = RenameTo copy_file(((from_dir + '\\') + cn(All_files[i])), ((to_dir + '\\') + RenameTo1))