Python代写 - INFO1112 2020 Assignment 1

INFO1112 2020 Assignment 1 (version 2 - 6th Oct) 
Due Week 8, Friday 23rd October at 5pm 
This assignment is worth 20% of your overall grade for the course. 

The assignment will be marked with an automatic testing system on Ed as well as
manual inspection by a tutor. An automatic mark will be given based on the
number of tests passed (10%) and a manual mark will be given for overall style,
quality, readability, etc (5%). 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 (5%).

There will be public test cases made available for you to test against, but there will
also be extra non-public tests used for marking. Success with the public tests
doesn't guarantee your program will pass the private tests.

This assignment involves developing a system to run programs at scheduled times.
This is similar to the Unix and Linux "cron" system.

Your program will read a configuration file that specifies what programs are to be run
and when. You will be able to specify that a given program is run periodically at
particular times, for example every Tuesday at 1pm, run a certain script. Alternatively
you could specify that a program be run at 8am, 12noon, 2pm and 4pm everyday.

Your system will consist of two programs:

● A program ( that will run in the background, reading the
configuration file that specifies what programs (with parameters) it should run
and when they should be started. Normally would be started
when the system is initialised, but for this assignment you can run the
program as a background process..
● The second command ( that is designed to get the current
status from and send it to the standard output.

Programs like are normally called "daemons" (pronounced the same
as "demon") and run in the background. There are many examples of daemons in
INFO1112 2020 Assignment 1 1
Linux, for example a printer daemon will manage a queue of files to send to the
printer. The configuration file for will be named $HOME/.runner.conf
and contains a list of programs to start, what time to start them and if they should be
run at that time regularly. The configuration file is described in more detail below.
The program should keep information about the current status: what
programs need to be run, what time they last ran, and when they are next due to be
run. If receives the SIGUSR1 signal it should open the file
$HOME/.runner.status and write the status information in a human readable
form to it, then close the file. This will be read by

At startup, should write its process ID into the file
$HOME/ and check that the status file $HOME/.runner.status
exists. If the status file does not exist it should be created by

The second command ( is designed to get the current status from
the system. It should send the SIGUSR1 signal to the program (using
the PID stored in $HOME/ and then open and read the status file
$HOME/.runner.status and send the contents to the standard output. Then
close the status file, reopen it in write mode to truncate it to zero length, close it
again and finally terminate. It should give an error message if anything fails, such as
$HOME/ or $HOME/.runner.status missing, or nothing appears
in the file $HOME/.runner.status after 5 seconds. See error handling section

Configuration File 
The configuration file for will contain one line for each program that is to be
run. Each line has the following parts:

timespec program-path parameters

❏ timespec is the specification of the time that the program should be run
❏ program-path is a full path name of a program to run and the specified
❏ parameters are the parameters for the program.

The timespec has the following format:

[every|on day[,day…]] at HHMM[,HHMM…] run
INFO1112 2020 Assignment 1 2

Square brackets mean the term is optional, vertical bar means alternative, three dots
means repeated. Terms in bold are keywords. Times are in 24 hour clock format.
Days are full day names that are case sensitive and start with capital letter.


every Tuesday at 1100 run /bin/echo hello
- every tuesday at 11am run "echo hello"
on Tuesday at 1100 run /bin/echo hello
- on the next tuesday only, at 11am run "echo hello"
every Monday,Wednesday,Friday at 0900,1200,1500 run
- every monday, wednesday and friday at 9am, noon and 3pm run
at 0900,1200 run /home/bob/myprog
- runs /home/bob/myprog at 9am and noon only. If 9am is already passed then

Status Messages 

Status messages are
● a line of text for each time a program has been run or there was an error
● a line showing the next time it will be run.

The format for the output lines is:

ran date-time program-path parameters
error date-time program-path parameters
will run at date-time program-path parameters

where words in bold are fixed, date-time is a string in python time.ctime() format,
program-path is the full path of the program and parameters are the parameters

Error handling 
Your program should do detailed error checking. In particular,
● if you cannot open the configuration file you should print "configuration file not
INFO1112 2020 Assignment 1 3
● if an error is detected in the configuration file you should print "error in
configuration: line" where line is the line of the file containing the error
● if the configuration file is empty, you should print "configuration file empty"
● if an error occurs during the fork/exec of a program, this should be noted in
the time record and the "error date-time program-path parameters" message
produced in the status
● if a file such as or .runner.status cannot be created or is not found,
or has some other error you should print: "file file-name error-message" where
file-name is the file that caused the error and error-message is an informative
● if the status does not arrive in 5 seconds print "status timeout"
● if has no programs to run (this will eventually occur if there are no
"every" lines in the configuration) then print the message "nothing left to run"
and terminate.

Your programs should never crash. If an error occurs a suitable message or status
produced. All error messages should be sent to stderr.

If any error is detected you need to report it. This includes failures of fork/exec,
creating a file, not finding a file that should be there etc.

An experienced programmer checks for as many error conditions as they can.
Thinking that "this can never happen therefore I won't check for it" is a bad idea.

You can assume processes finish inside 60 seconds and wait for each process to
complete before running the next. [Note that this would not be acceptable for a real
"cron" program. In order to handle all cases you would need to use the "waitpid"
function that is non-blocking, and check regularly.]

Please note, further clarifications to this specification may be posted on Ed
and new editions of the specification published on Canvas.

The assignment is to be implemented in two Python programs. A scaffold file will be
provided. You are expected to write legible code following the PEP-8 style guide.

The only Python modules which you are allowed to import are os, sys, time, enum,
stat, datetime, signal and re. The os.system function is not permitted - use fork/exec
and wait to run programs. If you want to use an additional module which will not
INFO1112 2020 Assignment 1 4
trivialize the assignment, ask your tutor, and the allowed library list may be extended.

You are expected to write a number of test cases for your program. These should be
simple input/output tests. An example test configuration file will be included in the
scaffold. You are expected to test every execution path of your code.
You will need to test with different configuration files and show that your program can
handle errors for incorrect input.
You should write a simple testing script in Bash to run your input/output tests to
simplify and automate the testing process.
Submitting your code
An Ed assessment workspace will be available for you to submit your code.
Public and hidden test cases will be released in batches until Monday 19th October.
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
integrity proceedings.

INFO1112 2020 Assignment 1 5
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

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
proper 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

INFO1112 2020 Assignment 1 6