#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2010 Eric Allen
#
# Author: Eric Allen <eric@hackerengineer.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

import dripbox
import re
import logging
import argparse
import sys

LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
REMOTE_REGEX = re.compile("(.*)@(.+):(.+)")

logging.basicConfig(level=logging.INFO)
# parse arguments
parser = argparse.ArgumentParser(
        description='Automatically sync local files to remote')
parser.add_argument('-p', '--remote-port',
        type=int, default=22, help="SSH port on remote system")
parser.add_argument('remote', nargs=1, metavar="USER@HOST:PATH")
args = parser.parse_args()

remote_parts = REMOTE_REGEX.match(args.remote[0])
username = remote_parts.group(1)
host = remote_parts.group(2)
remote_root = remote_parts.group(3)

dripbox.launch(username, host, args.remote_port, remote_root)

print("Hit ENTER to quit")
raw_input()
sys.exit(0)
