~vbkaisetsu/+junk/renpy-vertical-text

« back to all changes in this revision

Viewing changes to makeupdate.py

  • Committer: Tom
  • Date: 2010-09-07 03:45:41 UTC
  • Revision ID: pytom@bishoujo.us-20100907034541-0gv4x25qp2to9len
Integrate updater support w/ launcher.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
import sys
4
4
sys.path.append('/home/tom/ab/keys/')
5
5
 
6
 
import argparse
7
6
import os
8
 
import zlib
9
7
import bz2
10
8
import hashlib
11
9
import public
12
10
import private
13
 
import time
 
11
import shutil
14
12
 
15
13
def sha(s):
16
14
    """
22
20
    return hash.hexdigest()
23
21
 
24
22
 
25
 
ap = argparse.ArgumentParser()
26
 
ap.add_argument("root")
27
 
args = ap.parse_args()
28
 
 
29
 
root = args.root
30
 
 
31
 
# A list of command strings.
32
 
commands = [ ]
33
 
 
34
 
for dir, dirs, files in os.walk(root):
35
 
 
36
 
    for fn in dirs + files:
37
 
 
38
 
        path = os.path.join(dir, fn)
39
 
        relpath = os.path.relpath(path, root)
40
 
 
41
 
        if relpath in [ "version", "catalog1.bz2" ]:
42
 
            continue
43
 
        
44
 
        if os.path.isdir(path):
45
 
            commands.append(('dir', "base", relpath))
46
 
 
47
 
        elif relpath.endswith(".bz2"):
48
 
 
49
 
            hash = sha(bz2.BZ2File(path, "r").read())
50
 
            size = "%d" % (os.path.getsize(path))
51
 
 
52
 
            commands.append(('file', hash, size, "base", relpath[:-4]))
53
 
 
54
 
            if os.access(path, os.X_OK):
55
 
                commands.append(('xbit', relpath[:-4]))
56
 
            
57
 
        else:
58
 
            print "Unknown non-directory, non-bz2-file:", path
59
 
 
60
 
out = bz2.BZ2File(os.path.join(root, "catalog1.bz2"), "w")
61
 
hash = hashlib.sha256()
62
 
 
63
 
for i in commands:
64
 
 
65
 
    line = "\t".join(i) + "\n"
66
 
    hash.update(line)
67
 
    out.write(line)
68
 
 
69
 
unsigned = int("01" + hash.hexdigest(), 16)
70
 
signed = pow(unsigned, private.exponent, public.modulus)
71
 
 
72
 
out.write("-\n")
73
 
out.write("signature\t%x\n" % signed)
74
 
 
75
 
out.close()
76
 
            
77
 
f = file(os.path.join(root, "version"), "w")
78
 
f.write(str(int(time.time())))
79
 
f.write("\n")
80
 
f.write("Test Update.")
81
 
f.close()
 
23
def make_update(root, version):
 
24
 
 
25
    # A list of command strings.
 
26
    commands = [ ]
 
27
 
 
28
    for dir, dirs, files in os.walk(root):
 
29
        for fn in files:
 
30
            fn = os.path.join(dir, fn)
 
31
 
 
32
            oldf = file(fn, "rb")
 
33
            bzf = bz2.BZ2File(fn + ".bz2", "wb")
 
34
            bzf.write(oldf.read())
 
35
            bzf.close()
 
36
            oldf.close()
 
37
 
 
38
            shutil.copymode(fn, fn + ".bz2")
 
39
            os.unlink(fn)
 
40
            
 
41
    for dir, dirs, files in os.walk(root):
 
42
 
 
43
        for fn in dirs + files:
 
44
 
 
45
            path = os.path.join(dir, fn)
 
46
            relpath = os.path.relpath(path, root)
 
47
 
 
48
            if relpath in [ "version", "catalog1.bz2" ]:
 
49
                continue
 
50
 
 
51
            if os.path.isdir(path):
 
52
                commands.append(('dir', "base", relpath))
 
53
 
 
54
            elif relpath.endswith(".bz2"):
 
55
 
 
56
                hash = sha(bz2.BZ2File(path, "r").read())
 
57
                size = "%d" % (os.path.getsize(path))
 
58
 
 
59
                commands.append(('file', hash, size, "base", relpath[:-4]))
 
60
 
 
61
                if os.access(path, os.X_OK):
 
62
                    commands.append(('xbit', relpath[:-4]))
 
63
 
 
64
 
 
65
    out = bz2.BZ2File(os.path.join(root, "catalog1.bz2"), "w")
 
66
    hash = hashlib.sha256()
 
67
 
 
68
    for i in commands:
 
69
 
 
70
        line = "\t".join(i) + "\n"
 
71
        hash.update(line)
 
72
        out.write(line)
 
73
 
 
74
    unsigned = int("01" + hash.hexdigest(), 16)
 
75
    signed = pow(unsigned, private.exponent, public.modulus)
 
76
 
 
77
    out.write("-\n")
 
78
    out.write("signature\t%x\n" % signed)
 
79
    out.close()
 
80
 
 
81
    f = file(os.path.join(root, "version"), "w")
 
82
    f.write(version)
 
83
    f.write("\n")
 
84
    f.write("Ren'Py")
 
85
    f.close()
82
86