Partial Scripting & You

While I was browsing Hacker News, I came across a blog post by Dan Slimmon explaining something he called “do-nothing scripting.” The premise of a “do-nothing script” is that it does nothing other than tell the user what to do at each step of a process. These types of scripts are great for helping communicate a series of manual steps that someone has to perform in a specific order. Even though I don’t necessarily write any of my own “do-nothing scripts,” this idea has helped me realize where I could utilize what I call “partial scripts.”

What Is a Partial Script?

When automating a series of repetitive tasks, it’s easy to think that it’s not worth writing a script unless you can automate the entire process from start to finish. Often, the amount of effort required to write that script is too high to justify, so it never gets written. This is where a partial script comes into play.

If it’s easy to automate a few parts of a process and more difficult for others, start by writing a script that automates the easy parts. Partial automation is better than no automation!

A partial script is made up of three components:

  1. Some initial automated steps
  2. A manual process (verification, using another tool, etc.)
  3. The rest of the automated steps

So what does this look like in practice?

Partial Scripting in Action

While working on a recent Android app, my team ended up changing the minimum Android SDK version from KitKat to Marshmallow. The Android project contained over 90 SVG assets for various icons used throughout the app, and they weren’t officially supported in Android until Lollipop.

Since we had previously supported every Android version all the way back to KitKat, we used a third-party library to convert the SVGs into the various PNG assets for different phone sizes. Each SVG would generate four PNGs to accommodate displays on different sizes of phones.

With support for KitKat dropped, we could now start using Vector Assets from within Android Studio instead of the variously-sized PNG files. For each of the 90+ SVG files, I wanted to:

  1. Determine the file paths of the associated PNG files for the SVG file
  2. Using Android Studio, import the SVG as a Vector Asset and verify that it works as expected
  3. Delete the associated PNG files
  4. Commit all of the changes with a relevant commit message

There is a lot of busywork in cleaning up the assets in the project, which makes it a great candidate for automation! Unfortunately, Step 2 would be particularly difficult to script, especially since there’s no CLI tool for doing the import of an SVG as a Vector Asset in Android Studio. It would also be difficult to perform the verification without some manual intervention.

This is where we can utilize the power of partial scripting!


NOT_SUPPORTED_LIST = [
  # If you have identified certain SVG files that contain elements 
  # that are unsupported by Vector Assets, you can list them here
].freeze

files = Dir['app/src/main/assets/svg/*']

def wait_for_enter
  loop do
    puts "\nPress \'ENTER\' to continue..."
    break if gets == "\n"
  end
end

files.each do |file|
  modified_filename = file
                      .gsub('.svg', '')
                      .gsub('app/src/main/assets/svg/', '')

  png_files = []

  png_files << "app/src/main/res/drawable-mdpi/#{modified_filename}.png"
  png_files << "app/src/main/res/drawable-hdpi/#{modified_filename}.png"
  png_files << "app/src/main/res/drawable-xhdpi/#{modified_filename}.png"
  png_files << "app/src/main/res/drawable-xxhdpi/#{modified_filename}.png"

  next if Dir[png_files[0]].empty? || NOT_SUPPORTED_LIST.include?(modified_filename)

  # Wait here until the manual tasks are complete
  puts "File: #{modified_filename}"
  wait_for_enter

  # Switch to false for debugging
  do_it = true

  png_files.each do |f|
    puts "Deleting file: #{f}"
    system("rm #{f}") if do_it
  end

  puts 'Committing changes to git'
  system('git add app/') if do_it
  system("git commit -m 'Converting #{modified_filename} to vector asset'") if do_it

  puts ''
end

With the help of this partial script, I was able to complete the cleanup of the 90+ SVG assets in our Android project in about an hour.

Commit log of executing the partial script.
Commit log showing the result of executing the partial script.

Do you think partial scripting is beneficial? What sorts of tasks are you planning to partially automate?

Conversation
  • Kunal Diyali says:

    Hello Alex,

    Do you have more details on this scripting part, example what language is used or who to execute partial scripting. I have an interview tomorrow and the Business unit uses partial scripting in Optum to check the performance of the design. Example – will there be bug or performance issue or anything else.

    It would be great if you could help me with more details

    Thank you,
    Kunal Diyali.

    • Alex Zurek Alex Zurek says:

      Hello Kunal,

      In the post I gave an example of using the Ruby programming language for a task that I needed to accomplish, but the specific scripting language that you use doesn’t really matter. Regardless of the scripting language, you should be able to follow this pattern of “partial scripting” to automate the easy parts of the workflow while still relying on a manual process for the parts that would be too costly to automate.

      I’m not familiar with Optum, but I don’t see why you wouldn’t be able to apply this pattern of “partial scripting” to finding performance issues. I hope this helps clarify a few things for you. Good luck on the interview!

  • Comments are closed.