CS 100  Programming I
Project 1

Revision Date: January 8, 2017

Printable Version


You may develop your code anywhere, but you must ensure it runs correctly under a Linux distribution before submission.

Bad Disks, Smart Logs.

Welcome to LogSoft! Here at Logsoft we specialize in designing and maintaining logging software.

What does loggin software do you ask? As your computer or server goes about doing various things we would like to keep track of who is doing what, and at what time. Inorder to do this, we write information to a file as the system is running.

Our most recent breakthrough allows a log to continue writing even if it encounters a bad section of a disk. Through some clever software design, if a file is about to enter bad disk space, a line containing "--" is entered into the file and the log continues to write to a 2nd file while the 1st is moved. If the 2nd file encounters a bad section of disk, a line containing "--" is entered and the log continues to write back on the 1st file. This process is repeated.

What we need you to do, is to write a utility that can merge these two files correctly, and return information about user activity.

Here is an example from the first file:

    12:03:01 Michael Logged In
    12:06:12 Mary Logged In
    13:12:05 Michael Opened Terminal
    14:33:52 Serena Opened Firefox
    14:42:27 Serena Logged Out

Here is an example from the second file:

    13:30:07 Mary Opened Terminal
    13:45:11 Serena Logged In
    14:24:32 Michael Logged Out
    15:02:00 Mary Opened Evolution
    15:31:16 Mary Logged Out

Your task is to create a tool that takes as its parameters, two file names and a user name. This tool will then merge the two lists and, in chronological order, print out the activites of the given user.

    12:06:12 Mary Logged In
    13:30:07 Mary Opened Terminal
    15:02:00 Mary Opened Evolution
    15:31:16 Mary Logged Out

Getting the Data

Your main program should be placed in a file named mergelog.py. The program should accept three command-line arguments. The first two should be the file names of the two log files to merge. The third will represent the username that we are curious about.

Here is an example call:

        python3 mergelog.py log1.txt log2.txt Mary

The file names are just examples; you will need to invent your own data and place into files named by your choosing.

Command-line arguments

Here is a short python program that checks if there are three command-line arguments and, if so, prints out the three arguments:

    import sys

    def main():
         # check to see if there are three arguments
         # look at the length of sys.argv
         # sys.argv holds the name of the program plus the arguments

         if len(sys.argv) != 4: 
            print("incorrect number of arguments, should be 3")

        print("the name of the program is",sys.argv[0])
        print("argument 1 is", sys.argv[1])
        print("argument 2 is", sys.argv[2])
        print("argument 3 is", sys.argv[3])


Submission Instructions

Change to the directory containing your assignment. Do an ls command to make sure you are in the correct place. You should see, at least, your mergelog.py file. Extra files are OK. Submit your program like this:

    submit cs100 xxxxx project1

Remember to replace xxxxx with your instructor name.