The goal is pretty straightforward. There’s a list of dotfiles from my home directory. It loops through them and rsyncarsyncs all file to a Dropbox folder for backup purposes. A cron job runs this nightly. Code has workworked well so far.
#!/usr/bin/python
import os
from os.path import expanduser
import sys
import subprocess
dotfiles = [
'.ackrc',
'.tmux.conf',
'.vimrc',
'.zshrc',
'.gitconfig',
'.ssh/config',
'.zsh/MyAntigen.hs',
'.vim/colors/dracula.vim'
]
home = expanduser("~")
src = home + '/'
dest = home + '/Dropbox/Dotfiles'
rsync = 'rsync --times'
if sys.stdout.isatty():
rsync = rsync + ' --progress'
for item in dotfiles:
src_file = os.path.join(src + item)
cmd = rsync + ' ' + src_file + ' ' + dest
process = subprocess.Popen(cmd, shell=True)
process.wait()
This is my very first Python script (first time using rsyncrsync too) and I just started very recently. I’ve put this together based on trial and error and a lot of Stack Overflow. So I’m here for some genuine feedback. Thanks in advance!