Tips and tricks for the developer

I thought we might collect together some helpful tips related to developing plugins and other code on an OctoPrint installation. Feel free to add your own here.

Add an alias for that virtual environment command

I find myself typing this command a lot so I decided to add a shell alias for it.

Before:

source ~/oprint/bin/activate

After:

begin

Instructions

I'll be describing this for a Raspbian install since that's what I'm using.

nano ~/.bashrc

Look for the "Alias definitions" section and add this line.

alias begin='source ~/oprint/bin/activate'

Exit and then ssh back into your Raspberry and you now have this new alias (macro).

4 Likes

Great tip...adding "begin" now.

Here's my contribution, which may be more of a "beginner tip"

If you install a plugin that completely fubars Octoprint (so you can't get into the UI), you can un-install the plugin with this command:

For Raspbian, ssh in:

pi@octoprusa:~ $ ~/oprint/bin/pip uninstall (full plugin name)

ie:

pi@octoprusa:~ $ ~/oprint/bin/pip uninstall Octoprint-FilamentWatch

1 Like

I'd add to this...

...having first run that begin (or source ~/oprint/bin/activate) to bring up the virtual environment.

Since I'm slightly lazy, I don't love retyping commands. I often allow the history command to help me repeat something I do. So I'll type history|grep tail which would show me a few times when I've done this. Bash then lets me type in something like !123 to repeat the command which was 123rd in that list.

So here, I introduce a combining of history + grep (find) = fistory as a new alias. Like before, edit your ~/.bashrc to add:

alias fistory='history | grep '

(Remember to include the space after "grep" there.

After:

fistory tail
# Output follows:
  435  tail -f ~/.octoprint/logs/octoprint.log
  442  fistory tail
!435  # So then I can re-run the earlier command

But then again, why not just create an alias for this as well while we're at it?

alias octocat='cat ~/.octoprint/logs/octoprint.log'
alias octotail='tail -f ~/.octoprint/logs/octoprint.log'

After

octotail # tail's the octoprint.log so that you can watch the progress

Problem

Having just replaced your Raspberry Pi with another (moving the microSD over) you get a terse error when attempting to remote into it:

"WARNING: POSSIBLE DNS SPOOFING DETECTED"
etc

Usual manual behavior

Edit the ~/.ssh/known_hosts file to remove the problematic entry.

Script version

Here's another script which I have in my workstation's path. This one will just delete the offending record in that file.

nukeop

#!/bin/sh

sed -i '' '/octopi\.local/d' ~/.ssh/known_hosts

I don't know if there is anybody else doing this, but you don't need a extra Raspiberry Pi to run your development system. I created a Lubuntu virtual machine in VMware and installed Octoprint in it following this tutorial: https://www.youtube.com/watch?v=fimVwRXarf4 .
The advantages are:

  1. it's free;
  2. it's faster;
  3. you can create a copy of that machine for each project you have.