Merge lp:~james-w/linaro-image-tools/fix-package-regex into lp:linaro-image-tools/11.11

Proposed by James Westby
Status: Merged
Approved by: Michael Hudson-Doyle
Approved revision: 142
Merged at revision: 81
Proposed branch: lp:~james-w/linaro-image-tools/fix-package-regex
Merge into: lp:linaro-image-tools/11.11
Prerequisite: lp:~james-w/linaro-image-tools/add-other-relations-to-packages-file
Diff against target: 91 lines (+27/-12)
4 files modified
hwpack/config.py (+1/-1)
hwpack/tests/test_config.py (+8/-0)
hwpack/tests/test_script.py (+8/-4)
linaro-hwpack-create (+10/-7)
To merge this branch: bzr merge lp:~james-w/linaro-image-tools/fix-package-regex
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle (community) Approve
Zygmunt Krynicki (community) Needs Information
Review via email: mp+35285@code.launchpad.net

Description of the change

Hi,

A small change to correct a typo in the name regex that was being
used.

Thanks,

James

To post a comment you must log in.
141. By James Westby

Merged add-other-relations-to-packages-file into fix-package-regex.

Revision history for this message
Zygmunt Krynicki (zyga) wrote :

9 + NAME_REGEX = "[a-z0-9][a-z0-9+-.]+$"
                                        ^
This seems wrong:
Look at the part underlined with ^, it is a range expression from '+' to '.'
Is that what you wanted?

review: Needs Information
Revision history for this message
James Westby (james-w) wrote :

Good catch, thanks!

It happens to pass the test as "-" is one of the characters
between "+" and "." in ASCII/unicode.

Thanks,

James

142. By James Westby

Specify a literal "-" in the regex. Thanks Zygmunt.

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Looks fine. I think I'd double up the backslash or use a r'..' string, but it's not required.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hwpack/config.py'
2--- hwpack/config.py 2010-09-02 19:12:53 +0000
3+++ hwpack/config.py 2010-09-13 21:19:07 +0000
4@@ -11,7 +11,7 @@
5
6 MAIN_SECTION = "hwpack"
7 NAME_KEY = "name"
8- NAME_REGEX = "[a-z0-9][a-z0-9+0.]+"
9+ NAME_REGEX = "[a-z0-9][a-z0-9+\-.]+$"
10 INCLUDE_DEBS_KEY = "include-debs"
11 SUPPORT_KEY = "support"
12 SOURCES_ENTRY_KEY = "sources-entry"
13
14=== modified file 'hwpack/tests/test_config.py'
15--- hwpack/tests/test_config.py 2010-09-02 19:08:32 +0000
16+++ hwpack/tests/test_config.py 2010-09-13 21:19:07 +0000
17@@ -132,6 +132,14 @@
18 + "\n[ubuntu]\nsources-entry = foo bar\n")
19 self.assertEqual(None, config.validate())
20
21+ def test_validate_valid_config_with_dash_in_package_name(self):
22+ config = self.get_config(
23+ "[hwpack]\nname = ahwpack\n"
24+ "packages = u-boot\n"
25+ "architectures = armel\n\n"
26+ "[ubuntu]\nsources-entry = foo bar\n")
27+ self.assertEqual(None, config.validate())
28+
29 def test_name(self):
30 config = self.get_config(
31 "[hwpack]\nname = ahwpack\npackages = foo\n"
32
33=== modified file 'hwpack/tests/test_script.py'
34--- hwpack/tests/test_script.py 2010-09-13 21:19:07 +0000
35+++ hwpack/tests/test_script.py 2010-09-13 21:19:07 +0000
36@@ -55,13 +55,17 @@
37 self.assertEqual("", stdout)
38
39 def test_errors_on_missing_configfile_argument(self):
40- stdout, stderr = self.run_script([], expected_returncode=1)
41- self.assertEqual("Requires arguments CONFIG_FILE VERSION\n", stderr)
42+ stdout, stderr = self.run_script([], expected_returncode=2)
43+ self.assertEqual(
44+ "usage: linaro-hwpack-create [-h] CONFIG_FILE VERSION\n"
45+ "linaro-hwpack-create: error: too few arguments\n", stderr)
46 self.assertEqual("", stdout)
47
48 def test_errors_on_missing_version_argument(self):
49- stdout, stderr = self.run_script(["somefile"], expected_returncode=1)
50- self.assertEqual("Requires arguments CONFIG_FILE VERSION\n", stderr)
51+ stdout, stderr = self.run_script(["somefile"], expected_returncode=2)
52+ self.assertEqual(
53+ "usage: linaro-hwpack-create [-h] CONFIG_FILE VERSION\n"
54+ "linaro-hwpack-create: error: too few arguments\n", stderr)
55 self.assertEqual("", stdout)
56
57 def test_builds_a_hwpack(self):
58
59=== modified file 'linaro-hwpack-create'
60--- linaro-hwpack-create 2010-09-13 21:19:07 +0000
61+++ linaro-hwpack-create 2010-09-13 21:19:07 +0000
62@@ -1,19 +1,22 @@
63 #!/usr/bin/python
64
65-from optparse import OptionParser
66+import argparse
67 import sys
68
69 from hwpack.builder import ConfigFileMissing, HardwarePackBuilder
70
71
72 if __name__ == '__main__':
73- parser = OptionParser()
74- opts, args = parser.parse_args()
75- if len(args) < 2:
76- sys.stderr.write("Requires arguments CONFIG_FILE VERSION\n")
77- sys.exit(1)
78+ parser = argparse.ArgumentParser()
79+ parser.add_argument(
80+ "CONFIG_FILE",
81+ help="The configuration file to take the hardware pack information "
82+ "from.")
83+ parser.add_argument(
84+ "VERSION", help="The version of the hardware pack to create.")
85+ args = parser.parse_args()
86 try:
87- builder = HardwarePackBuilder(args[0], args[1])
88+ builder = HardwarePackBuilder(args.CONFIG_FILE, args.VERSION)
89 except ConfigFileMissing, e:
90 sys.stderr.write(str(e) + "\n")
91 sys.exit(1)

Subscribers

People subscribed via source and target branches