diff options
| author | Richard Purdie <richard@openedhand.com> | 2007-11-25 14:03:49 +0000 |
|---|---|---|
| committer | Richard Purdie <richard@openedhand.com> | 2007-11-25 14:03:49 +0000 |
| commit | 84e1d7cc07bce1194b890c57664b453f36c0308c (patch) | |
| tree | ec3ed211ae255f87464467ddd4868a5c05de37fe /meta | |
| parent | 2f2de3f3a109cfe9179ff5165dd47c9f32416f04 (diff) | |
| download | poky-84e1d7cc07bce1194b890c57664b453f36c0308c.tar.gz | |
Add stage-manager-native
git-svn-id: https://svn.o-hand.com/repos/poky/trunk@3229 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'meta')
| -rwxr-xr-x | meta/packages/stage-manager/files/stage-manager | 120 | ||||
| -rw-r--r-- | meta/packages/stage-manager/stagemanager-native_0.0.1.bb | 23 |
2 files changed, 143 insertions, 0 deletions
diff --git a/meta/packages/stage-manager/files/stage-manager b/meta/packages/stage-manager/files/stage-manager new file mode 100755 index 0000000000..733a0a4f72 --- /dev/null +++ b/meta/packages/stage-manager/files/stage-manager | |||
| @@ -0,0 +1,120 @@ | |||
| 1 | #!/usr/bin/env python | ||
| 2 | |||
| 3 | # Copyright (C) 2006-2007 Richard Purdie | ||
| 4 | # | ||
| 5 | # This program is free software; you can redistribute it and/or modify it under | ||
| 6 | # the terms of the GNU General Public License version 2 as published by the Free | ||
| 7 | # Software Foundation; | ||
| 8 | # | ||
| 9 | # This program is distributed in the hope that it will be useful, but WITHOUT | ||
| 10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 11 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
| 12 | |||
| 13 | import optparse | ||
| 14 | import os, sys, stat | ||
| 15 | |||
| 16 | __version__ = "0.0.1" | ||
| 17 | |||
| 18 | |||
| 19 | def write_cache(cachefile, cachedata): | ||
| 20 | fd = open(cachefile, 'w') | ||
| 21 | for f in cachedata: | ||
| 22 | s = f + '|' + str(cachedata[f]['ts']) + '|' + str(cachedata[f]['size']) | ||
| 23 | fd.write(s + '\n') | ||
| 24 | fd.close() | ||
| 25 | |||
| 26 | def read_cache(cachefile): | ||
| 27 | cache = {} | ||
| 28 | f = open(cachefile, 'r') | ||
| 29 | lines = f.readlines() | ||
| 30 | f.close() | ||
| 31 | for l in lines: | ||
| 32 | data = l.split('|') | ||
| 33 | cache[data[0]] = {} | ||
| 34 | cache[data[0]]['ts'] = int(data[1]) | ||
| 35 | cache[data[0]]['size'] = int(data[2]) | ||
| 36 | return cache | ||
| 37 | |||
| 38 | def mkdirhier(dir): | ||
| 39 | """Create a directory like 'mkdir -p', but does not complain if | ||
| 40 | directory already exists like os.makedirs | ||
| 41 | """ | ||
| 42 | try: | ||
| 43 | os.makedirs(dir) | ||
| 44 | except OSError, e: | ||
| 45 | if e.errno != 17: raise e | ||
| 46 | |||
| 47 | if __name__ == "__main__": | ||
| 48 | parser = optparse.OptionParser( version = "Metadata Stage Manager version %s" % ( __version__ ), | ||
| 49 | usage = """%prog [options]\n\nPerforms mamagement tasks on a metadata staging area.""" ) | ||
| 50 | |||
| 51 | parser.add_option( "-p", "--parentdir", help = "the path to the metadata parent directory", | ||
| 52 | action = "store", dest = "parentdir", default = None) | ||
| 53 | |||
| 54 | parser.add_option( "-c", "--cachefile", help = "the cache file to use", | ||
| 55 | action = "store", dest = "cachefile", default = None) | ||
| 56 | |||
| 57 | parser.add_option( "-d", "--copydir", help = "copy changed files to this directory", | ||
| 58 | action = "store", dest = "copydir", default = None) | ||
| 59 | |||
| 60 | parser.add_option( "-u", "--update", help = "update the cache file", | ||
| 61 | action = "store_true", dest = "update", default = False) | ||
| 62 | |||
| 63 | (options, args) = parser.parse_args() | ||
| 64 | |||
| 65 | if options.parentdir is None: | ||
| 66 | print("Error, --parentdir option not supplied") | ||
| 67 | sys.exit(1) | ||
| 68 | |||
| 69 | if options.cachefile is None: | ||
| 70 | print("Error, --cachefile option not supplied") | ||
| 71 | sys.exit(1) | ||
| 72 | |||
| 73 | if not options.parentdir.endswith('/'): | ||
| 74 | options.parentdir = options.parentdir + '/' | ||
| 75 | |||
| 76 | cache = {} | ||
| 77 | if os.access(options.cachefile, os.F_OK): | ||
| 78 | cache = read_cache(options.cachefile) | ||
| 79 | |||
| 80 | found = False | ||
| 81 | |||
| 82 | for root, dirs, files in os.walk(options.parentdir): | ||
| 83 | for f in files: | ||
| 84 | path = os.path.join(root, f) | ||
| 85 | if not os.access(path, os.R_OK): | ||
| 86 | continue | ||
| 87 | fstamp = os.stat(path) | ||
| 88 | if path not in cache: | ||
| 89 | print "new file %s" % path | ||
| 90 | cache[path] = {} | ||
| 91 | cache[path]['ts'] = fstamp[stat.ST_MTIME] | ||
| 92 | cache[path]['size'] = fstamp[stat.ST_SIZE] | ||
| 93 | if options.copydir: | ||
| 94 | copypath = os.path.join(options.copydir, path.replace(options.parentdir, '', 1)) | ||
| 95 | mkdirhier(os.path.split(copypath)[0]) | ||
| 96 | os.system("mv " + path + " " + copypath) | ||
| 97 | found = True | ||
| 98 | else: | ||
| 99 | if cache[path]['ts'] != fstamp[stat.ST_MTIME] or cache[path]['size'] != fstamp[stat.ST_SIZE]: | ||
| 100 | print "file %s changed" % path | ||
| 101 | cache[path] = {} | ||
| 102 | cache[path]['ts'] = fstamp[stat.ST_MTIME] | ||
| 103 | cache[path]['size'] = fstamp[stat.ST_SIZE] | ||
| 104 | if options.copydir: | ||
| 105 | copypath = os.path.join(options.copydir, path.replace(options.parentdir, '', 1)) | ||
| 106 | mkdirhier(os.path.split(copypath)[0]) | ||
| 107 | os.system("mv " + path + " " + copypath) | ||
| 108 | found = True | ||
| 109 | |||
| 110 | if options.update: | ||
| 111 | print "Updating" | ||
| 112 | mkdirhier(os.path.split(options.cachefile)[0]) | ||
| 113 | write_cache(options.cachefile, cache) | ||
| 114 | |||
| 115 | if found: | ||
| 116 | sys.exit(5) | ||
| 117 | sys.exit(0) | ||
| 118 | |||
| 119 | |||
| 120 | |||
diff --git a/meta/packages/stage-manager/stagemanager-native_0.0.1.bb b/meta/packages/stage-manager/stagemanager-native_0.0.1.bb new file mode 100644 index 0000000000..7074d37307 --- /dev/null +++ b/meta/packages/stage-manager/stagemanager-native_0.0.1.bb | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | DESCRIPTION = "Helper script for packaged-staging.bbclass" | ||
| 2 | PR = "r1" | ||
| 3 | |||
| 4 | SRC_URI = "file://stage-manager" | ||
| 5 | LICENSE = "GPLv2" | ||
| 6 | |||
| 7 | PACKAGE_ARCH = "all" | ||
| 8 | |||
| 9 | inherit native | ||
| 10 | |||
| 11 | DEPENDS = " " | ||
| 12 | PACKAGE_DEPENDS = " " | ||
| 13 | PATCHTOOL = "" | ||
| 14 | INHIBIT_DEFAULT_DEPS = "1" | ||
| 15 | |||
| 16 | do_install() { | ||
| 17 | install -d ${STAGING_BINDIR} | ||
| 18 | install -m 0755 ${WORKDIR}/stage-manager ${STAGING_BINDIR} | ||
| 19 | } | ||
| 20 | |||
| 21 | do_stage() { | ||
| 22 | : | ||
| 23 | } | ||
