new matrix-rootfs script replaces the "rootfs" action of matrix
authorTimo Savola <tsavola@movial.fi>
Tue, 29 Apr 2008 12:27:51 +0000 (15:27 +0300)
committerTimo Savola <tsavola@movial.fi>
Tue, 29 Apr 2008 12:27:51 +0000 (15:27 +0300)
the rootfs module now uses the optparse module.

bin/matrix-rootfs [new file with mode: 0755]
matrix/matrix.py
matrix/rootfs.py

diff --git a/bin/matrix-rootfs b/bin/matrix-rootfs
new file mode 100755 (executable)
index 0000000..7734890
--- /dev/null
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+
+moduledir = '@MODULEDIR@'
+
+import sys
+from os.path import dirname, abspath
+
+if moduledir.startswith('@'):
+       moduledir = dirname(dirname(abspath(sys.argv[0])))
+
+sys.path.insert(0, moduledir)
+
+from matrix import rootfs, log
+
+try:
+       rootfs.main()
+
+except RuntimeError, e:
+       msg = str(e)
+       if msg:
+               log.error(msg)
+
+except KeyboardInterrupt:
+       log.message('Interrupted')
+
+if log.dump():
+       sys.exit(1)
index 33b0eab..f534f20 100644 (file)
@@ -14,7 +14,6 @@ import config
 import git
 import log
 from build import build, build_only
-from rootfs import RootFS
 
 Error = RuntimeError
 
@@ -63,8 +62,6 @@ def main():
                changes(targets)
        elif command == 'source-dist':
                source_dist(targets)
-       elif command == 'rootfs':
-               build_rootfs(**params)
        else:
                raise Error('Invalid command: ' + command)
 
@@ -101,11 +98,6 @@ Commands and parameters:
        pull            Update repositories from server by merging.
        changes         Show commits which are not on the server.
        source-dist     Download and package the component sources.
-       rootfs          Build a rootfs from the current target installation.
-               -n              Do not clean env.faked and stripped directory.
-               -r              Only generate a stripped rootfs.
-               -j              Only generate a jffs2 image
-               -d              Only generate a rootstrap (development rootfs).
 ''' % {'progname': args[0]}
 
 def parse_args(args):
@@ -145,19 +137,6 @@ def parse_args(args):
                                        sys.exit(0)
                                else:
                                        raise Error('Bad option: ' + args[i])
-                       elif command == 'rootfs':
-                               if args[i] == '-n':
-                                       i += 1
-                                       params['clean'] = False
-                               elif args[i] == '-r':
-                                       i += 1
-                                       params['rootfs_only'] = True
-                               elif args[i] == '-j':
-                                       i += 1
-                                       params['jffs2_only'] = True
-                               elif args[i] == '-d':
-                                       i += 1
-                                       params['devrootfs_only'] = True
                        else:
                                raise Error('Command takes no parameters')
                elif not command:
@@ -299,31 +278,3 @@ def dist_sources(c, location):
                os.remove(path)
 
        c.source.archive(name, path)
-
-def build_rootfs(clean=True, rootfs_only=False, jffs2_only=False, devrootfs_only=False):
-       config.parse('rootfs')
-
-       f = os.popen('sb-conf cu')
-       target = f.read()
-       f.close()
-
-       rootfs = RootFS(target.strip())
-       rootfs.include_paths(config.include_paths)
-       rootfs.include_files(config.include_files)
-       rootfs.filter_paths(config.exclude_paths)
-       rootfs.filter_files(config.exclude_files)
-       rootfs.filter_expressions(config.exclude_expressions)
-       rootfs.add_paths(config.created_paths)
-       rootfs.set_devices(config.devices)
-       rootfs.set_change_owner(config.change_owner)
-       rootfs.set_erase_size(config.boards[config.board].flash_erase_size)
-       rootfs.set_pad_size(config.boards[config.board].flash_pad_size)
-
-       if rootfs_only:
-               rootfs.generate(clean, build_target="rootfs")
-       elif jffs2_only:
-               rootfs.generate(clean, build_target="jffs2")
-       elif devrootfs_only:
-               rootfs.generate(clean, build_target="devrootfs")
-       else:
-               rootfs.generate(clean, build_target="all")
index fda6df3..323e37a 100644 (file)
@@ -1,15 +1,85 @@
-#!/usr/bin/env python
-#
 # Copyright (C) 2007-2008 Movial Oy
 # Authors: Kalle Vahlman <kalle.vahlman@movial.fi>
+#          Timo Savola <tsavola@movial.fi>
 
 import errno
+import optparse
 import os
 import re
 import shutil
 import sys
 
-class RootFS(object):
+import config
+
+supported_types = (
+       'jffs2',
+)
+default_type = 'jffs2'
+
+def main():
+       parser = optparse.OptionParser(usage='%s [<options>]' % sys.argv[0])
+
+       parser.add_option(
+               '-n', '--no-clean',
+               help='do not clean env.faked and stripped directory',
+               dest='clean', action='store_false', default=True)
+
+       parser.add_option(
+               '-i', '--image-only',
+               help='generate only a filesystem image',
+               dest='image_only', action='store_true')
+
+       parser.add_option(
+               '-T', '--image-type',
+               help='type of generated filesystem image [%s]' % default_type,
+               dest='type', choices=supported_types, default=default_type)
+
+       parser.add_option(
+               '-r', '--rootfs-only',
+               help='generate only a stripped archive',
+               dest='rootfs_only', action='store_true')
+
+       parser.add_option(
+               '-d', '--devrootfs-only',
+               help='generate only an archive with development files',
+               dest='devrootfs_only', action='store_true')
+
+       opts, args = parser.parse_args()
+       if args:
+               parser.print_help()
+               sys.exit(1)
+
+       config.parse('config.local')
+       config.parse('config')
+       config.parse('boards')
+       config.parse('rootfs')
+
+       f = os.popen('sb-conf cu')
+       target = f.read()
+       f.close()
+
+       build = Builder(target.strip())
+       build.include_paths(config.include_paths)
+       build.include_files(config.include_files)
+       build.filter_paths(config.exclude_paths)
+       build.filter_files(config.exclude_files)
+       build.filter_expressions(config.exclude_expressions)
+       build.add_paths(config.created_paths)
+       build.set_devices(config.devices)
+       build.set_change_owner(config.change_owner)
+       build.set_erase_size(config.boards[config.board].flash_erase_size)
+       build.set_pad_size(config.boards[config.board].flash_pad_size)
+
+       if opts.rootfs_only:
+               build.generate(opts.clean, build_target="rootfs")
+       elif opts.image_only:
+               build.generate(opts.clean, build_target=opts.type)
+       elif opts.devrootfs_only:
+               build.generate(opts.clean, build_target="devrootfs")
+       else:
+               build.generate(opts.clean, build_target="all")
+
+class Builder(object):
        builddir = "/tmp"
        target = None
 
@@ -227,15 +297,3 @@ class RootFS(object):
                        print "Cleaning up"
                        os.remove("/tmp/env.faked")
                        os.system("rm -rf %s/%s" % (self.builddir, self.target))
-
-
-#rootfs = RootFS("ROOTFS")
-#rootfs.include_paths(include_paths)
-#rootfs.include_files(include_files)
-#rootfs.filter_paths(exclude_paths)
-#rootfs.filter_files(exclude_files)
-#rootfs.filter_expressions(exclude_expressions)
-#rootfs.add_paths(created_paths)
-#rootfs.set_devices(devices)
-
-#rootfs.generate()