Mercurial > hg > carton
comparison carton.py @ 11:e6a62ba0c24d
now respect the order sources are installed in
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 08 Jul 2011 15:02:44 -0700 |
parents | 79f332fb3275 |
children | 542b46ac4e28 |
comparison
equal
deleted
inserted
replaced
10:d1f090c5f291 | 11:e6a62ba0c24d |
---|---|
44 # virtualenv name | 44 # virtualenv name |
45 ENV='''%(ENV)s''' | 45 ENV='''%(ENV)s''' |
46 | 46 |
47 # packed files | 47 # packed files |
48 VIRTUAL_ENV='''%(VIRTUAL_ENV)s'''.decode('base64').decode('zlib') | 48 VIRTUAL_ENV='''%(VIRTUAL_ENV)s'''.decode('base64').decode('zlib') |
49 PACKAGE_SOURCES='''%(PACKAGE_SOURCES)s'''.decode('base64').decode('zlib') | 49 PACKAGE_SOURCES=%(PACKAGE_SOURCES)s |
50 | 50 |
51 # unpack virtualenv | 51 # unpack virtualenv |
52 tempdir = tempfile.mkdtemp() | 52 tempdir = tempfile.mkdtemp() |
53 buffer = StringIO() | 53 buffer = StringIO() |
54 buffer.write(VIRTUAL_ENV) | 54 buffer.write(VIRTUAL_ENV) |
66 print virtualenv | 66 print virtualenv |
67 | 67 |
68 # create the virtualenv | 68 # create the virtualenv |
69 call([sys.executable, virtualenv, ENV]) | 69 call([sys.executable, virtualenv, ENV]) |
70 | 70 |
71 # unpack the sources | |
72 srcdir = os.path.join(ENV, 'src') | |
73 os.mkdir(srcdir) | |
74 buffer = StringIO() | |
75 buffer.write(PACKAGE_SOURCES) | |
76 buffer.seek(0) | |
77 tf = tarfile.open(mode='r', fileobj=buffer) | |
78 tf.extractall(srcdir) | |
79 | |
80 # find the bin/scripts directory | 71 # find the bin/scripts directory |
81 for i in ('bin', 'Scripts'): | 72 for i in ('bin', 'Scripts'): |
82 scripts_dir = os.path.abspath(os.path.join(ENV, i)) | 73 scripts_dir = os.path.abspath(os.path.join(ENV, i)) |
83 if os.path.exists(scripts_dir): | 74 if os.path.exists(scripts_dir): |
84 break | 75 break |
91 if os.path.exists(python): | 82 if os.path.exists(python): |
92 break | 83 break |
93 else: | 84 else: |
94 raise Exception("python not found in " + scripts_dir) | 85 raise Exception("python not found in " + scripts_dir) |
95 | 86 |
96 # activate the virtualenv | 87 # unpack the sources and setup for development |
97 #activate = os.path.join(scripts_dir, 'activate_this.py') | 88 srcdir = os.path.join(ENV, 'src') |
98 #assert os.path.exists(activate), activate + " does not exist" | 89 os.mkdir(srcdir) |
99 #execfile(activate, dict(__file__=activate)) | 90 setup_pys = set() |
91 for source in PACKAGE_SOURCES: | |
92 source = source.decode('base64').decode('zlib') | |
93 buffer = StringIO() | |
94 buffer.write(source) | |
95 buffer.seek(0) | |
96 tf = tarfile.open(mode='r', fileobj=buffer) | |
97 tf.extractall(srcdir) | |
100 | 98 |
101 # setup the sources for development | 99 # setup sources for development if there are any new setup.py files |
102 for i in os.listdir(srcdir): | 100 for i in os.listdir(srcdir): |
103 subdir = os.path.join(srcdir, i) | 101 if i in setup_pys: |
104 if os.path.exists(os.path.join(srcdir, i, 'setup.py')): | 102 continue |
105 call([python, 'setup.py', 'develop'], cwd=subdir) | 103 subdir = os.path.join(srcdir, i) |
104 if os.path.exists(os.path.join(srcdir, i, 'setup.py')): | |
105 call([python, 'setup.py', 'develop'], cwd=subdir) | |
106 setup_pys.add(i) | |
106 | 107 |
107 # cleanup tempdir | 108 # cleanup tempdir # TODO (optionally?) |
108 # shutil.rmtree(tempdir) | 109 # shutil.rmtree(tempdir) |
109 | 110 |
110 # TODO: | 111 # TODO: |
111 # - add carton to the virtualenv (!) | 112 # - add carton to the virtualenv (!) |
112 # - add virtualenv to the virtualenv (!) | 113 # - add virtualenv to the virtualenv (!) |
132 # stop on .py; will add it in later | 133 # stop on .py; will add it in later |
133 environment = environment[:-3] | 134 environment = environment[:-3] |
134 sources = args[1:] | 135 sources = args[1:] |
135 | 136 |
136 # tar up the sources | 137 # tar up the sources |
137 source_buffer = StringIO() | 138 source_array = [] |
138 sources_tar = tarfile.open(mode="w:gz", fileobj=source_buffer) | |
139 for source in sources: | 139 for source in sources: |
140 buffer = None | |
140 | 141 |
141 if isURL(source): | 142 if isURL(source): |
142 # remote tarball | 143 # remote tarball |
143 raise NotImplementedError | 144 raise NotImplementedError |
144 else: | 145 else: |
145 # local directory or tarball | 146 # local directory or tarball |
146 sources_tar.add(source, arcname=os.path.basename(source)) | 147 # TODO: check for a tarball |
148 source_buffer = StringIO() | |
149 source_tar = tarfile.open(mode="w:gz", fileobj=source_buffer) | |
150 source_tar.add(source, arcname=os.path.basename(source)) | |
151 source_tar.close() | |
152 buffer = source_buffer.getvalue() | |
153 | |
147 # could use git, hg, etc repos. but probably shouldn't | 154 # could use git, hg, etc repos. but probably shouldn't |
148 sources_tar.close() | 155 |
156 source_array.append(buffer.encode('zlib').encode('base64')) | |
149 | 157 |
150 # tar up virtualenv if not available | 158 # tar up virtualenv if not available |
151 if options.virtualenv: | 159 if options.virtualenv: |
152 if isURL(options.virtualenv): | 160 if isURL(options.virtualenv): |
153 globals()['VIRTUAL_ENV'] = urllib2.urlopen(options.virtualenv).read() | 161 globals()['VIRTUAL_ENV'] = urllib2.urlopen(options.virtualenv).read() |
168 outfile = options.outfile | 176 outfile = options.outfile |
169 if outfile is None: | 177 if outfile is None: |
170 outfile = environment + '.py' | 178 outfile = environment + '.py' |
171 variables = {'VIRTUAL_ENV': VIRTUAL_ENV.encode('zlib').encode('base64'), | 179 variables = {'VIRTUAL_ENV': VIRTUAL_ENV.encode('zlib').encode('base64'), |
172 'ENV': environment, | 180 'ENV': environment, |
173 'PACKAGE_SOURCES': source_buffer.getvalue().encode('zlib').encode('base64')} | 181 'PACKAGE_SOURCES': repr(source_array)} |
174 f = file(outfile, 'w') | 182 f = file(outfile, 'w') |
175 f.write(template % variables) | 183 f.write(template % variables) |
176 f.close() | 184 f.close() |
177 try: | 185 try: |
178 os.chmod(outfile, 0755) | 186 os.chmod(outfile, 0755) |