• May 15, 2020

INFO1112Assignment1课业解析题意: 写一个类似linux里find命令的简化版本python脚本 解析: find命令能够让我们在文件系统空间中搜索满足某些条件的文件比如某些特定名称(完全匹配)、名称与正则表达式模式匹配的文件(部分匹配)。还需要实现显示搜索文件的某些特征(比如特定日期后者读写权限等),python可使用os.walk对目录进行遍历,还需对文件名和扩展名进行遍历,可将文件名和扩展名以列表呈现,查找时对列表进行遍历即可。当遇到无效的命令行参数时应进行错误处理。 涉及知识点: python编程,os.walk、re模块 更多可加微信讨论微信号:IT_51zuoyejunpdf

INFO1112 2019 Assignment 1Due Week 9, Monday 7th October at 11:59PM (Midnight)This assignment is worth 10% of your overall grade for the course.AssessmentThe assignment will be marked with an automatic testing system on Ed. Anautomatic mark will be given based on a percentage of tests passed (6%) and amanual mark will be given for overall style, quality, readability, etc (2%). You areexpected to write your own tests and submit them with your code, and a mark willbe 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, etcOther behaviours will not be assessed.This assignment involves writing a command to scan the file system looking for aname that matches a given regular expression and then executing anothercommand. It is to be developed using the Python language. The specification for thecommand is given below.INFO1112 2019 Assignment 1 1The Find CommandAll Unix-like systems (Linux, etc) have a command called “find”. This commandallows 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 youmight search for a file with a name that matches a regular expression pattern. Youmight search for a file that has certain characteristics such as created after aparticular date or has certain permissions (eg writable).You can see the detailed specification of this command using the Unix mancommand, eg ” man find “.Assignment SpecificationYou are to implement a very simplified version of the Unix find command.The syntax for your command [–regex=pattern | –name=filename] directory [command]myfind.pyis the command namedirectoryis a required argument for the path to the directory to traversefilenameis the exact filename to match against when traversing the directorypatternis the regular expression pattern to match against when traversing thedirectoryOnly one of –regex=patternor –name=filenameshould be provided. Ifneither are provided, then list all files found during the traversal. These flags may belocated anywhere in the argument list.commandis an optional argument which is a Unix command that has {}in thecommand string replaced by the file name that is currently being executed on. If thisargument is not provided, then just list the file paths of the discovered files. Thisstring should be a simple command with an argument list (e.g. no redirections orpipes).Error handling and assumptionsIf invalid command line arguments are provided, your program should output thefollowing to standard error and exit with a non-zero exit code.Usage: [–regex=pattern | –name=filename] directory[command]INFO1112 2019 Assignment 1 2If any of the child processes could not be started, your program should print thefollowing to standard error and exit with a non-zero exit code. An example isprovided in the last usage example.Error: Unable to start process ‘‘You may assume that flags are always provided in the form –flag=value.Usage ExamplesList all files in the home directory tree$ ~Here is an example of a short Bash session using this command (note that the orderof the command output is not guaranteed):$ ls ~2019-calendar 2018-calendar INFO1112$ ls -l ~/INFO11122019-lecture-1.pdf 2018-lecture-1.pdf$ ~/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.pdfList files in the current directory tree that are named ‘config’$ . –name=configList files in the ‘Code’ directory tree that end in ‘.sh’$ Code –regex=”\.sh$”Run ‘wc’on files in the user ‘bob’s home directory treeThis will run a separate wcprocess for every file discovered while traversing thedirectory.$ ~bob “wc {}”Run ‘ls -l’on files in the home directory tree which start with ‘^2019’This will run a separate lsprocess for every matching file discovered whiletraversing the directory.$ ~ “^2019” “ls -l {}”Here is an example of a short Bash session using this command (note that the orderof the command output is not guaranteed):INFO1112 2019 Assignment 1 3$ ls ~2019-calendar 2018-calendar INFO1112$ ls -l ~/INFO11122019-lecture-1.pdf 2018-lecture-1.pdf$ ~ –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.pdfIf a process could not be opened for the command for the calendar file, then theoutput 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.pdfError: Unable to start process ‘ls -l 2019-calender’Please note, further clarifications to this specification may be posted on Ed.ImplementationThe assignment is to be implemented in Python as a script which handles commandline arguments. A scaffold file will be provided. You are expected to write legiblecode following the PEP-8 style guide.It is expected that your program uses sub-processes to handle the commandargument.It is suggested that you use the os.walkfunction and the remodule.You must implement the assignment without using os.systemor the subprocessmodule.The only Python modules which you are allowed to import are os, sys, and re. Ifyou want to use an additional module which will not trivialize the assignment, askyour tutor, and the allowed library list may be extended. Argument parsing librariessuch as argparsewill not be permitted.TestingYou are expected to write a number of test cases for your program. These should besimple input/output tests. An example test will be included in the scaffold. You areexpected to test every execution path of your code.You’re suggested to write a simple testing script in Bash to run your input/outputtests to simplify and automate the testing process.INFO1112 2019 Assignment 1 4Submitting your codeAn 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 ofSeptember. Additionally, there will be a set of unreleased test cases which will berun against your code after the due date.Any attempt to deceive the automatic marking system will be subject to academicdishonesty proceedings.Academic DeclarationBy submitting this assignment you declare the following:I declare that I have read and understood the University of Sydney StudentPlagiarism: Coursework Policy and Procedure, and except where specificallyacknowledged, the work contained in this assignment/project is my own work, andhas not been copied from other sources or been previously submitted for award orassessment.I understand that failure to comply with the Student Plagiarism: Coursework Policyand Procedure can lead to severe penalties as outlined under Chapter 8 of theUniversity of Sydney By-Law 1999 (as amended). These penalties may be imposedin cases where any significant portion of my submitted work has been copied withoutproper acknowledgement from other sources, including published works, theInternet, existing programs, the work of other students, or work previously submittedfor other awards or assessments.I realise that I may be asked to identify those portions of the work contributed by meand required to demonstrate my knowledge of the relevant material by answeringoral questions or by undertaking supplementary work, either written or in thelaboratory, 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/orcommunicate a copy of this assignment to a plagiarism checking service or in-housecomputer program, and that a copy of the assignment may be maintained by theservice or the School of Computer Science for the purpose of future plagiarismchecking.INFO1112 2019 Assignment 1 5  



Close Bitnami banner