5 def try_make_dir(dirname
):
7 Not yet a mkdirhier and not handling exception and not
8 testing if that file is really a dir...
10 if os
.path
.exists(dirname
):
14 def module_dir_name(module_name
):
15 return module_name
.replace('_', '-')
17 def package_dir_name(module_name
, package_suffix
):
18 base_name
= module_dir_name(module_name
)
19 dir_name
= "%s-%s" % (base_name
, package_suffix
)
20 return os
.path
.join(base_name
, dir_name
)
22 def expand(base
, name
):
23 return base
.replace("${PN}", name
)
25 def prepare_qtopia_tree(modules
):
27 Create directories for the modules under the current working directory.
29 for (module_name
, module
) in modules
:
30 base_name
= module_dir_name(module_name
)
31 try_make_dir(base_name
)
32 for package_name
in module
.keys():
33 dir = package_dir_name(module_name
, package_name
)
35 os
.system("cd %s; git-init" % dir)
36 os
.system("cd %s; rm -rf *" % dir)
39 def copy_qtopia_tree(modules
, source_tree
):
41 For every package copy the files given in the dir glob of the package
42 from the source_tree to the new location.
43 We substitute variables like ${PN} with the current package name, copy some
44 default files (e.g. license and build system boilerplate) into the package.
46 We return a list of filenames relative to the source_tree that we have used
47 to fill the package. We do not move from the source_tree for two reasons:
48 1.) Two packages might need the same file
49 2.) We might want to split the tree more than once
53 for (module_name
, module
) in modules
:
54 base_name
= module_dir_name(module_name
)
55 try_make_dir(base_name
)
56 for package_name
in module
.keys():
57 package_module
= module
[package_name
]
58 assert "dir" in package_module
59 source_path
= expand(package_module
["dir"], package_name
)
61 dir_name
= package_dir_name(module_name
, package_name
)
62 # Inefficient but who cares?
64 for root
, dirs
, files
in os
.walk(source_tree
):
65 if source_path
in root
and (root
.endswith(source_path
) or root
[root
.find(source_path
)+len(source_path
)] == '/'):
67 try_make_dir(os
.path
.join(dir_name
, "src"))
69 print source_path
, root
70 base_path
= root
[root
.find(source_path
)+len(source_path
)+1:]
71 #try_make_dir(os.path.join(dir_name, base_path))
72 #try_make_dir(os.path.join(dir_name, "src", base_path))
75 try_make_dir(os
.path
.join(dir_name
, base_path
, dir))
76 try_make_dir(os
.path
.join(dir_name
, "src", base_path
, dir))
78 source_file
= os
.path
.join(root
, file)
79 (_
, extension
) = os
.path
.splitext(file)
81 if extension
in [".cpp", ".c", ".h", ".ui", ".rc"]:
82 file_name
= os
.path
.join("src", file)
83 destination_file
= os
.path
.join(dir_name
, "src", base_path
, file)
84 elif extension
in [".pro", ".pri"]:
87 destination_file
= os
.path
.join(dir_name
, base_path
, file)
89 handled_files
[source_file
] = 1
90 shutil
.copyfile(source_file
, destination_file
)
93 print "Not found", dir_name
, source_path
99 def patch_packages(modules
):
101 Enrich the newly build packages with some more data or apply
107 def verify_tree(touched_files
, source_tree
, files_to_ignore
):
109 Compare which files we have touched with the ones available in the source tree
112 for root
, dirs
, files
in os
.walk(source_tree
):
114 path
= os
.path
.join(root
, file)
115 (_
, extension
) = os
.path
.splitext(file)
116 if extension
in [".pro", ".pri"]:
118 elif "qtopiacore/qt" in path
:
120 if not path
in touched_files
and not path
in files_to_ignore
:
121 print "Not handled the following file: '%s'" % path
123 def tar_packages(modules
):
125 Tar all directories up so they can be put somewhere or imported into git.
127 for (module_name
, module
) in modules
:
128 for package_name
in module
.keys():
129 dir = package_dir_name(module_name
, package_name
)
130 os
.system("cd %s; git-add *" % dir)
131 os
.system("cd %s; git-commit -a -m 'Updated the source tree'" % dir)
136 parser
= optparse
.OptionParser(version
="Qtopia Split Tree 0.1",
137 usage
= """%prog [options]
139 Split up a given Qtopia Source tree into smaller chunks and enrich them
140 with patches and an alternative buildsystem
143 parser
.add_option("-s", "--source", help="The Qtopia Source Tree", action
="store", dest
="source", default
=None)
144 options
, args
= parser
.parse_args(argv
)
146 if not options
.source
:
147 print "You need to specify a Qtopia Source tree"
150 # Now start to do the work
154 # 4.) Remove the copied files
155 # 5.) check what is left and complain
159 modules
= [(x
,getattr(config
,x
)) for x
in dir(config
) if x
.startswith('qtopia_')]
160 prepare_qtopia_tree(modules
)
161 used_files
= copy_qtopia_tree(modules
, options
.source
)
162 patch_packages(modules
)
163 verify_tree(used_files
, options
.source
, config
.IGNORE_LIST
)
164 tar_packages(modules
)
167 if __name__
== "__main__":