Overview
For this weeks lab we were tasked with adding two new features to our project, and working with multiple branches and merging them back to main. This was good practice for me as I was always a little intimidated to work with branches and just worked off of main for all my projects, but it turns out it's not hard at all.
Features
The two features I chose to add to this project were adding a --verbose
flag to print detailed information, and displaying the 'last modified' time and date for each file.
Adding a verbose mode flag
To add detailed information with the --verbose
flag, I chose to use the `logging' library to have access to a ready made event logging system. This avoided me having to make an if statement that checks if the argument for verbose is true for every print statement. Instead I just needed to set up the basic configuration in main:
logging.basicConfig(
level=logging.INFO if args.verbose else logging.WARNING,
format="%(levelname)s: %(message)s"
)
Example of a log info statement that only prints if the verbose flag is added:
logging.info("Finished analyzing structure for: %s", absolute_path)
Adding last modified timestamp
This feature was very quick to add. I was already using the time
library to check which files were recently modified, so it was just a few lines of code utilizing that same library to print a date string in the desired format:
try:
# Get last modified time (epoch seconds)
time_seconds = os.path.getmtime(file_path)
# Format into human‑readable string
modified_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time_seconds))
except Exception as e:
logging.error("Could not retrieve modification time for %s: %s", file_path, e)
modified_time = "Unknown"
Working with Branches and Parallel Commits
I created two separate branches called issue-8
and issue-9
to work on the new features, then merged them both at once. Luckily there were no merge conflicts and it ended up being a smooth process.
With this experience, I don't think I'll ever go back to working off main. Creating and merging branches turned out to be pretty painless and worth doing to keep things clean and separated.
Top comments (0)