Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: scripts/newbitmaps/make_bmp_from_components.py

Issue 6598091: Bitmap generator for components files (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.git@master
Patch Set: cl feedback Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « scripts/newbitmaps/HWID.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python2.6
2 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 # Call on a directory with components_XXX_XXX files, to create
7 # bitmaps with the appropriate names and contents.
8
9 import sys
10 import glob
11 import os
12 import re
13 import tempfile
14
15
16 if len(sys.argv) < 2:
17 print "usage: %s autotest/../hardware_Components/" % sys.argv[0]
18 sys.exit(1)
19
20
21 def MakeBmp(hwid, geom, bmp, directory):
22 """ Create the bitmap for this file. """
23 tmpdir = tempfile.mkdtemp()
24 tmpfile = os.path.join(tmpdir, "hwid.txt")
25 tmpbmpname = os.path.join(tmpdir, "hwid.bmp")
26 f = open(tmpfile, "w")
27 f.write(hwid)
28 f.close()
29
30 # Call bitmap making tools.
31 txt_to_bmp = ("~/trunk/src/platform/vboot_reference/"
32 "scripts/newbitmaps/strings/text_to_bmp")
33 imagedir = os.path.join(
34 "~/trunk/src/platform/vboot_reference/scripts/newbitmaps/images", geom)
35 yamlfile = os.path.join(imagedir, "unknown.yaml")
36 newyamlfile = os.path.join(imagedir, "hwid.yaml")
37 outputbmp = os.path.join(directory, bmp)
38
39 os.system("%s %s > /dev/null" % (txt_to_bmp, tmpfile))
40 os.system("cat %s | sed 's#hwid_unknown.bmp#%s#' > %s" % (
41 yamlfile, tmpbmpname, newyamlfile))
42 os.system("pushd %s >/dev/null; bmpblk_utility -c %s %s; popd >/dev/null" % (
43 imagedir, newyamlfile, outputbmp))
44 os.system("rm -rf %s" % tmpdir)
45
46 def ProcessDir(directory):
47 """ Find all the components file in this dir. """
48 # Regex to find the values we want.
49 re_bmp = re.compile(r'\'data_bitmap_fv\': \[\'(?P<bmp>.*)\'\],')
50 re_hwid = re.compile(r'\'part_id_hwqual\': \[\'(?P<hwid>.*)\'\],')
51 re_geom = re.compile(r'\'data_display_geometry\': \[\'(?P<geom>.*)\'\],')
52
53 # Find the components files.
54 files = glob.glob(os.path.join(directory, "data_*/components_*"))
55 for file in files:
56 # Scan for the values.
57 f = open(file, "r")
58 bmp = None
59 hwid = None
60 geom = None
61 for line in f.readlines():
62 m = re_bmp.search(line)
63 if m:
64 bmp = m.group('bmp')
65
66 m = re_hwid.search(line)
67 if m:
68 hwid = m.group('hwid')
69
70 m = re_geom.search(line)
71 if m:
72 geom = m.group('geom')
73 f.close()
74 if not ( bmp and hwid and geom):
75 print "Corrupt HWID configuration"
76 sys.exit(1)
77 print "HWID: %s, %s, %s" % (hwid, geom, bmp)
78 MakeBmp(hwid, geom, bmp, directory)
79
80 def main():
81 directory = os.path.abspath(sys.argv[1])
82 print "Generating HWID bmp based on %s" % directory
83 ProcessDir(directory)
84
85 if __name__ == '__main__':
86 main()
OLDNEW
« no previous file with comments | « scripts/newbitmaps/HWID.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698