[Tutor] Fwd: Embedding resources
diliup gabadamudalige
diliupg at gmail.com
Wed Aug 20 15:45:41 CEST 2014
Hi Danny!
The routine works fine and so does this one.
http://www.pygame.org/pcr/zipshow/index.php
The only problem with all these are that that the time taken to read these
files and to either make a list or send to screen is WAY TOO LONG.
The only one that works without much delay is in the file I have attached.
It is a bit of code that I wrote with verbose print statements to follow
the program in action while testing. As this uses base64 only there is no
secure encryption. Please have a look at it and try to improve it.
Am I doing this correctly? Are these messages getting to the community?
On Wed, Aug 20, 2014 at 1:18 PM, diliup gabadamudalige <diliupg at gmail.com>
wrote:
> Hi Danny!
>
> You are always there to lend a helping hand I've noticed! Thanks for the
> quick response! Let me try the code and get back to you.
>
>
>
> On Wed, Aug 20, 2014 at 1:02 PM, Danny Yoo <dyoo at hashcollision.org> wrote:
>
>>
>> On Aug 19, 2014 11:53 PM, "diliup gabadamudalige" <diliupg at gmail.com>
>> wrote:
>> >
>> > Hi all!
>> >
>> > Is there any way I can bundle all my graphics only using Python and
>> Pygame so that the user may not be able to read them out of the program?
>>
>> (Changing subject line to more descriptive title)
>>
>> Would something like http://www.pygame.org/pcr/image2py/index.php apply
>> to your problem?
>>
>
>
>
> --
> Diliup Gabadamudalige
>
> http://www.diliupg.com
> http://soft.diliupg.com/
>
>
> **********************************************************************************************
> This e-mail is confidential. It may also be legally privileged. If you are
> not the intended recipient or have received it in error, please delete it
> and all copies from your system and notify the sender immediately by return
> e-mail. Any unauthorized reading, reproducing, printing or further
> dissemination of this e-mail or its contents is strictly prohibited and may
> be unlawful. Internet communications cannot be guaranteed to be timely,
> secure, error or virus-free. The sender does not accept liability for any
> errors or omissions.
>
> **********************************************************************************************
>
>
--
Diliup Gabadamudalige
http://www.diliupg.com
http://soft.diliupg.com/
**********************************************************************************************
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**********************************************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140820/f53db542/attachment-0001.html>
-------------- next part --------------
"""
Author: Diliup Gabadamudalige. diliupg at gmail.com>
Copyright: If you wish to use this code please keep this multiline comment,
along with function source. Thank you.
read the files in the current directory and get all files except ones in the exempt list or directories..
Get the file extension.
and convert them by using maketrans without file extensions.
When converting from original files with file extensions, remove the file extension(with the .), reverse it and add it to the begining of the filename.
encode the file.
add new file ext "@lm".
eg: file name -> picture.tiff -> ffit.picture ->AFKDiO$1#&mL at lm.
encoded files added to a directory "coded" which is created if not exist.
decoded files added to a directory "decoded" which is created if not exist.
path = your path where the files are
run = True -> encode
run = False -> decode
"""
import os
import string
import base64
from master_vars import alpha, coder
def main(path, code = None, ex = [".wpr", ".wpu", ".py", ".pyc", ". at lm"]):
getfiles = []
path = path
code = code #
exclude = ex
items = os.listdir(path)
if code: # if code = True then encode
mode = "encode"
if not os.path.exists("coded"):
os.makedirs("coded")
else: # else decode
mode = "decode"
## if decode mode and coded folder does not exist exit program
if not os.path.exists("coded"):
print "nothing to decode."
elif not os.path.exists("decoded") and os.path.exists("coded"):
os.makedirs("decoded")
elif os.path.exists("decoded"):
items = os.listdir(path + "\\" + "coded")
## get the names of the files in the path which are not in the exclude list
## encode or decode either way this works correct
for n in items:
if code:
fpath = path + "\\" + n
if os.path.isfile(fpath): # check if file is not a directory
if n[n.index("."):] not in exclude:
getfiles.append(n)
else:
fpath = path + "\\coded\\" + n
if n.endswith(". at lm"): # get only the converted files
getfiles.append(n)
print "file names to process:", getfiles
print
for f in getfiles:
if code:
## decode and reverse file name
namea = f.translate(string.maketrans(alpha,coder))
nameb = namea[::-1] + ". at lm"
code_to_dir = path + "\\coded\\" + nameb
read_file = path + "\\" + f
else:
## drop the file ext. decode and reverse
namea = f[:-4].translate(string.maketrans(coder, alpha))
## file name + reversed
nameb = namea [::-1]
decode_to_dir = path + "\\decoded\\" + nameb
read_file = path + "\\coded\\" + f
print "new file name not invert no ext:", namea
print "new file name:", nameb
print "old file name:", f
print
with open(read_file , "rb") as from_disk:
if code:
str1 = base64.b64encode(from_disk.read())
with open(code_to_dir, "wb") as to_disk:
to_disk.write(str1)
else:
str1 = base64.b64decode(from_disk.read())
with open(decode_to_dir, "wb") as to_disk:
to_disk.write(str1)
print mode + "ed ", len(getfiles), " files."
if __name__=='__main__':
path = "d:\PYTHON\diliupg\SoftwareDG\Educational\Learn_music\encode_decode"
# if path not supplied use the current working directory
if not path:
path = os.getcwd()
code = True
main(path, code)
More information about the Tutor
mailing list