Skip to main content
留学咨询

辅导案例-INFO1112 2019-Assignment 1

By May 15, 2020No Comments

  INFO1112 2019 ​Assignment 1  Due Week 9, Monday 7th October at 11:59PM (Midnight) This assignment is worth 10% of your overall grade for the course. Assessment The assignment will be marked with an automatic testing system on Ed. An automatic mark will be given based on a percentage of tests passed (6%) and a manual mark will be given for overall style, quality, readability, etc (2%). You are expected to write your own tests and submit them with your code, and a mark will be given based on coverage and manual inspection of your tests (2%). Marks will be allocated for​: ● basic directory traversal ● regular expression ● executing external commands ● argument parsing ● test coverage ● code layout, readability, overall quality, etc Other behaviours will not be assessed. This assignment involves writing a command to scan the file system looking for a name that matches a given regular expression and then executing another command. It is to be developed using the Python language. The specification for the command is given below. INFO1112 2019 Assignment 1 1 The Find Command All Unix-like systems (Linux, etc) have a command called “find”. This command allows you to search the file system name-space for a file that satisfies some criteria. For example, you might search for a file with a particular name (exact match), or you might search for a file with a name that matches a regular expression pattern. You might search for a file that has certain characteristics such as created after a particular date or has certain permissions (eg writable). You can see the detailed specification of this command using the Unix man command, eg “​man find​”. Assignment Specification You are to implement a ​very ​ simplified version of the Unix find command. The syntax for your command is: myfind.py ​[–regex=pattern | –name=filename] directory [command]    myfind.py​ is the command name directory​ is a required argument for the path to the directory to traverse filename​ is the exact filename to match against when traversing the directory pattern​ is the regular expression pattern to match against when traversing the directory Only one of ​–regex=​pattern​ or ​–name=​filename​ ​should be provided. If neither are provided, then list all files found during the traversal. These flags may be located anywhere in the argument list. command​ is an optional argument which is a Unix command that has ​{}​ in the command string replaced by the file name that is currently being executed on. If this argument is not provided, then just list the file paths of the discovered files. This string should be a simple command with an argument list (e.g. no redirections or pipes). Error handling and assumptions If invalid command line arguments are provided, your program should output the following to standard error and exit with a non-zero exit code. You should also print this for ​pattern​ is invalid or ​directory​ does not exist. Usage: myfind.py [–regex=pattern | –name=filename] directory  [command]  INFO1112 2019 Assignment 1 2 If any of the child processes could not be started, your program should print the following to standard error and exit with a non-zero exit code. An example is provided in the last usage example. Error: Unable to start process ”  You may assume that flags are always provided in the form ​–flag=value​. Usage Examples List all files in the home directory tree  $ myfind.py ~    Here is an example of a short Bash session using this command (note that the order of the command output is not guaranteed): $ ls ~  2019-calendar 2018-calendar INFO1112  $ ls -l ~/INFO1112 2019-lecture-1.pdf 2018-lecture-1.pdf  $ myfind.py ~  /home/bob  /home/bob/2019-calendar  /home/bob/2018-calendar  /home/bob/INFO1112  /home/bob/INFO1112/2019-lecture-1.pdf  /home/bob/INFO1112/2018-lecture-1.pdf  List files in the current directory tree that are named ​’config’  $ myfind.py . –name=config  List files in the ‘Code’ directory tree that end in ​’.sh’  $ myfind.py Code –regex=”\.sh$”  Run ​’wc’​ on files in the user ‘bob’s home directory tree  This will run a separate ​wc​ process for every file discovered while traversing the directory. $ myfind.py ~bob “wc {}”  Run ​’ls -l’​ on files in the home directory tree which start with ​’^2019’  This will run a separate ​ls​ process for every matching file discovered while traversing the directory. $ myfind.py ~ –regex=”^2019″ “ls -l {}”    Here is an example of a short Bash session using this command (note that the order of the command output is not guaranteed): INFO1112 2019 Assignment 1 3 $ ls ~  2019-calendar 2018-calendar INFO1112  $ ls -l ~/INFO1112 2019-lecture-1.pdf 2018-lecture-1.pdf  $ myfind.py ~ –regex=”^2019″ “ls -l {}”  -rw-r–r–@ 1 bob 502 0 14 Sep 20:03 2019-calendar  -rw-r–r–@ 1 bob 502 0 14 Sep 20:04 INFO1112/2019-lecture-1.pdf If a process could not be opened for the command for the calendar file, then the output may be the following (the calendar line may come first): -rw-r–r–@ 1 bob 502 0 14 Sep 20:04 INFO1112/2019-lecture-1.pdf  Error: Unable to start process ‘ls -l 2019-calender’    Please note, further clarifications to this specification may be posted on Ed. Implementation The assignment is to be implemented in Python as a script which handles command line arguments. A scaffold file will be provided. You are expected to write legible code following the ​PEP-8​ style guide. It is expected that your program uses sub-processes to handle the ​command argument. It is suggested that you use the ​os.walk​ function and the ​re​ module. You must implement the assignment without using ​os.system​ or the ​subprocess module. The only Python modules which you are allowed to import are ​os​, ​sys​, and ​re​. If you want to use an additional module which will not trivialize the assignment, ask your tutor, and the allowed library list may be extended. Argument parsing libraries such as ​argparse​ will not be permitted. Testing You are expected to write a number of test cases for your program. These should be simple input/output tests. An example test will be included in the scaffold. You are expected to test every execution path of your code. You’re suggested to write a simple testing script in Bash to run your input/output tests to simplify and automate the testing process. INFO1112 2019 Assignment 1 4 Submitting your code An Ed assessment workspace will be available soon for you to submit your code. Public and hidden test cases will be released in batches until Sunday the 29th of September. Additionally, there will be a set of unreleased test cases which will be run against your code after the due date. Any attempt to deceive the automatic marking system will be subject to academic dishonesty proceedings. Academic Declaration By submitting this assignment you declare the following: I declare that I have read and understood the University of Sydney Student Plagiarism: Coursework Policy and Procedure, and except where specifically acknowledged, the work contained in this assignment/project is my own work, and has not been copied from other sources or been previously submitted for award or assessment. I understand that failure to comply with the Student Plagiarism: Coursework Policy and Procedure can lead to severe penalties as outlined under Chapter 8 of the University of Sydney By-Law 1999 (as amended). These penalties may be imposed in cases where any significant portion of my submitted work has been copied without prop
er acknowledgement from other sources, including published works, the Internet, existing programs, the work of other students, or work previously submitted for other awards or assessments. I realise that I may be asked to identify those portions of the work contributed by me and required to demonstrate my knowledge of the relevant material by answering oral questions or by undertaking supplementary work, either written or in the laboratory, in order to arrive at the final assessment mark. I acknowledge that the School of Computer Science, in assessing this assignment, may reproduce it entirely, may provide a copy to another member of faculty, and/or communicate a copy of this assignment to a plagiarism checking service or in-house computer program, and that a copy of the assignment may be maintained by the service or the School of Computer Science for the purpose of future plagiarism checking. INFO1112 2019 Assignment 1 5

admin

Author admin

More posts by admin