File: PackLibDir.py

package info (click to toggle)
python2.1 2.1.3dfsg-1sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 38,028 kB
  • ctags: 64,228
  • sloc: python: 186,023; ansic: 184,754; xml: 43,435; sh: 12,381; makefile: 3,523; perl: 3,108; lisp: 2,460; cpp: 106; sed: 2
file content (49 lines) | stat: -rw-r--r-- 1,346 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#
# Turn a pyc file into a resource file containing it in 'PYC ' resource form
from Res import *
import Res
from Resources import *
import os
import macfs
import sys
import py_resource

error = 'mkpycresourcefile.error'

def mkpycresourcefile(src, dst):
	"""Copy pyc file/dir src to resource file dst."""
	
	if not os.path.isdir(src) and src[-4:] <> '.pyc':
			raise error, 'I can only handle .pyc files or directories'
	fsid = py_resource.create(dst)
	if os.path.isdir(src):
		handlesubdir(src)
	else:
		id, name = py_resource.frompycfile(src)
		print 'Wrote %d: %s %s'%(id, name, src)
	CloseResFile(fsid)
			
def handlesubdir(srcdir):
	"""Recursively scan a directory for pyc files and copy to resources"""
	src = os.listdir(srcdir)
	for file in src:
		file = os.path.join(srcdir, file)
		if os.path.isdir(file):
			handlesubdir(file)
		elif file[-4:] == '.pyc':
			id, name = py_resource.frompycfile(file)
			print 'Wrote %d: %s %s'%(id, name, file)
	
if __name__ == '__main__':
	args = sys.argv[1:]
	if not args:
		ifss, ok = macfs.GetDirectory('Select root of tree to pack:')
		if not ok:
			sys.exit(0)
		args = [ifss.as_pathname()]
	for ifn in args:
		ofss, ok = macfs.StandardPutFile('Output for '+os.path.split(ifn)[1])
		if not ok:
			sys.exit(0)
		mkpycresourcefile(ifn, ofss.as_pathname())
	sys.exit(1)			# So we can see something...