Assignment 2 - Simple Nautilus
This assignment is worth 20% of your overall grade for the course.
Due: Week 8, Thursday, September 22nd at 23:59:00, Sydney local time.
You are going to be writing an interactive application in Python that allows the user to send commands to a file management application and receive outputs. The application largely mocks common Unix commands such as ls , cd , pwd , and so on.
You will need to implement and thoroughly test your solution. On the high level, the application is capable of:
1. interpret commands received on standard input.
2. produce messages on standard output.
3. maintain some data structure that keeps track of a virtual name space.
4. create, delete and move virtual files and folders during program run time. 5. support user and permission management in addition to file management.
In Linux system, you can interact with the Terminal prompt to navigate in the file system using
cd , to perform actions to create, move, delete and copy files using touch mv rm cp , to alter the
ownership and permission of files by chmod and to add or remove users by adduser deluser .
In this assignment, you need to write a Python program which provides an interactive prompt as if a Linux Terminal. Human users can interact with the Python program via standard input and standard output. One can input commands, and as a result, the program may print out feedback messages due to certain input.
Note that the system is incapable of storing content but purely the file system structure. This is an intensional design and therefore the size of a file is not defined and is omitted in the system. Similarly, the concept of time and group is omitted intentional. Please see the whole specification for more details.
The assignment has three tasks that you will need to implement and thoroughly test. You will be provided a test suite to assist in developing your solutions.
The three tasks are:
1. Implement a minimal Simple Nautilus. 2. Implement a simplified Simple Nautilus. 3. Implement a full Simple Nautilus.
Please read the whole specification to better understand these tasks. * Nautilus: a file manager for GNOME.
Formatting Syntax
It is very common that command strings are written in a simple template language: characters are usually interpreted literally into themselves, but format specifiers, which are enclosed by parentheses, indicate the location and method to translate a piece of placeholder to characters.
In Simple Nautilus, the following formatting is used:
chown
Formatted arguments enclosed in sharp brackets < and > can be replaced by any single syntactically valid string.
Formatted arguments enclosed in square brackets [ and ] can be replaced by zero or one syntactically valid string.
Example
A formatted string
can be extended by
<a>, <b>, <c> and [d] are extended to Never, " Gonna ", "Give You" and "up". or
<a> , <b> and <c> are extended to Among , Us , yo and [d] is omitted.
Permission and Ownership
Like in Unix, this system supports user and permission management. However, the concept of group is omitted and therefore the mode string for permission is shorted than its form in Unix.
To view the permissions for all files in a directory, use the ls command with the -l option. For example, if you enter:
You should see output similar to the following:
The first column indicates the file type and the permission information The second column indicates the owner of the file or directory.
The third column indicates the name of the file or directory.
The first character in the first column indicates whether the listed object is a file or a directory. Directories are indicated by a ( d ); files are indicated by a dash ( - ), which is the absence of a d at the beginning of the first line. Then, there are two sets of three characters that represent different levels of ownership. Hence, myfile.txt is a file and Example is a directory.
The letters rwx represent different permission levels:
Permission Files Directories
r can read the file can ls the directory
For example,
drwxr-x : d being the first character indicates directory; the owner permissions are rwx , indicating that the owner can view, modify, and enter the directory; other (anyone other than the owner) can view as well as enter the directory. (Group is not defined, therefore there are no group permissions.)
-rw-r-- : - being the first character indicates file; the owner permissions are rw- , indicating that the owner can read and write to the file but can't execute it as a program; other (anyone other than the owner) can only read the file. (Again, group is not defined, therefore there are no group permissions.)
Default setting and lifetime
The default user upon starting the program is root with the initial working directory being the root directory ( / ).
Whenever the program starts, the initial effective user root and an empty virtual name space are created; whenever the program exits, the whole virtual user space and virtual name space are lost.
root user is the most powerful user in this system. When the current effective user is root , they can ignore all permission requirements stated below. In other words, root will face no
Prompt Formation
The input prompt should have the following formation, where the leading prompt is ended by a dollar symbol and a single white space:
White spaces that come after a valid command should be ignored.
If there are only whitespace characters being inputted by the user as a commond string, nothing will happen when the user executes this command.
Example
If user root is at path / , the prompt printed before any input should be:
If bob enter a command pwd , then the combination of the input and prompt forms the line:
Valid character set
User names, file names and directory names are valid when it only contains:
All alphanumeric characters, a to z, A to Z, and 0 to 9; the Space character, ;
the Hyphen character, - ;
the Underscore character, _ .
Special path dot
A dot component in a path refer to the preceding component.
For a path a/b/c/./d/. , the preceding component of the first (left-most) dot is a/b/c . The preceding component of the second (right-most) dot is a/b/c/./d , which shall evaluate to
a/b/c/d . The whole path shall evaluate to a/b/c/d . dot-dot
A dot-dot component in a path refer to the parent of the preceding component. That is, it moved up one level toward the root / .
For a path a/b/c/../d/.. , the preceding component of the first (left-most) dot-dot is a/b/c . The preceding component of the second (right-most) dot-dot is a/b/c/../d , which shall evaluate to
Example
Assume there exists a tree of directories /a/b/c/d/e , where a to e are valid directories. There are no other files or directories on the system.
Commands
Please note that all format string to be printed should be expended by the real parameter in- place.
exit
To quit the program. Print:
bye, <current_user>
pwd
Print name of current working virtual directory.
cd <dir>
Change the working directory to <dir> .
Require current effective user's execute bit x on <dir> . If does not exist, print:
Implementation
The assignment is to be implemented in Python. A set of scaffold files will be provided. You are expected to write legible code with good style, e.g. PEP 8.
You are NOT allowed to import ANY Python modules. You are free to use all builtin functions of Python. If you want to use an additional module which will not trivialize the assignment, please ask on Ed. The allowed library list may be extended. Related announcement should be posted accordingly.
e2e_tests/
<name>.out
drwxr-x root .
bob:/$ ls -d -l /
drwxr-x root /
bob:/$ ls -l folder1
ls: Permission denied bob:/$ ls -l folder1/folder2 ls: Permission denied bob:/$ su
root:/$ chmod o=x folder1 root:/$ su bob
bob:/$ ls -l folder1
ls: Permission denied
bob:/$ ls -l folder1/folder2 bob:/$ ls -a -l folder1/folder2 drwxr-x root .
drwx--x root ..
bob:/$ ls -d -l folder1 drwx--x root folder1
bob:/$ ls -d -l folder1/folder2 drwxr-x root folder1/folder2 bob:/$ exit
bye, bob
You must NOT create, access or delete any actual files on disk. You must NOT preserve any data temporarily or permanently in any actual files on disk, but the memory.
Please be mindful: breaching the above restrictions will result in harsh deduction for the entire assignment.