Documente Academic
Documente Profesional
Documente Cultură
1. Introduction
Please complete the exercises described in the following sections using the Tcl or Python scripting
languages:
Python 2.x NOT Python 3.x (Python 2.7.x is the preferred version)
An Python script.
Correctness.
Maintainability.
Robustness.
Performance - which must be adequate and should not be an issue if you avoid gross
inefficiencies.
Please use a file system directory per exercise solution. When you have completed the homework,
W1:
Write a regular expression that only matches the string (wherever it occurs): ABC
W2:
Write a regular expression that matches any of the following, and no others: ABC ACC ADC
AXC
W3:
Write a regular expression that will only match the following string when it is on a line entirely
by itself: ABC
W4:
Write a regular expression that matches only the string that starts with 'A' and ends with 'B',
W5:
Write a regular expression that matches only the string that starts with 'A' and ends with 'B',
with a run of one or more of either 'XO' or 'OX' in-between. Make a note of any assumptions
you make.
If the test data matches the regular expression, by outputting: "MATCH:" followed by the
matched pattern.
The script should execute each regular expression sequentially (W1 to W5), announcing each one
before it is tested.
Example expected output:
Task W1:
ABC
MATCH: ABC
AABCC
MATCH: ABC
AAAC
NO MATCH
AXC
NO MATCH
Task W2:
...
It is up to you supply a suitable set of test data, and write the script that satisfies the requirements for
You have a big directory tree with many files and directories in it. Some of those files have the
extension '.inform'. Some of the files with that extension contain instances of the string 'port
Document any assumptions you make when completing the tasks below. You may make assumptions
at any stage.
3.1 Task F1
Searching only the files with the '.inform' extension, count the number of instances of each different
'port #nnnn' string, where nnnn is a four or more digit hexadecimal number to a maximum of 32-digits.
port freq
0000 1
1284 5
28f6 1
144ff 7
123abc 6
Ensure that each file (piece of data on the disk) is only scanned once, and that the strings in it are
The Linux file system allow symbolic links to files in a different directory location or with a different
name.
For extra credit; modify your program to deal with directory structures that contain such links, such
that there may be more than one path from the root to a given '.inform' file.
4. Password Task
Document any assumptions you make when completing the tasks below. You may make assumptions
at any stage.
4.1 Task P1
Query the user for their password twice, making sure the user enters the same password
in both instances.
Allowed characters: numbers, letters, '_' (underscore), '-' (dash) and '.' (fullstop).
For this task the “expect” module/package of your chosen language must be used.
It could be used to simply process and check the user inputting the password, or you could create a
separate script using “expect” that interacts with (and tests) your password script.
If the user name is not in the 'company database'(*), then reject it, otherwise continue.
If this is not the first time and if it is correct, ask the user to change their password.
(*)Note that we are not expecting a fully featured database design or password changing functionality.
The rules for the password are the same as for Task 1 (above), and in addition:
For Windows, the POSIX compatible pexpect module (as above) may be used with the Cygwin
(https://pypi.Python.org/pypi/winpexpect).
Hint
When running a Python script as an Expect sub-process, the script may need to be executed in
unbuffered
mode: