Exemplo n.º 1
0
def main():
    try:
        client = Trovebox()
        client.configure(api_version=2)

    except IOError, e:
        print
        print '!! Could not initialize Trovebox connection.'
        print '!! Check that ~/.config/trovebox/default exists and contains proper information.'
        print
        raise e
Exemplo n.º 2
0
 def __init__(self, root='/home/ceda/trovebox'):
     self.client = Trovebox()
     self._storageDir = os.path.join(root, 'raw')
     self._dateDir = os.path.join(root, 'date')
     self._tagsDir = os.path.join(root, 'tags')
     self._albumsDir = os.path.join(root, 'albums')
     self._tags_to_ignore = 'autoupload,January,February,March,April,May,June,July,August,September,October,November,December'.split(
         ',')
Exemplo n.º 3
0
 def test_host_override(self):
     """ Ensure that specifying a host overrides the default config """
     self.create_config("default", "Test Default Host")
     client = Trovebox(host="host_override")
     auth = client.auth
     self.assertEqual(auth.host, "host_override")
     self.assertEqual(auth.consumer_key, "")
     self.assertEqual(auth.consumer_secret, "")
     self.assertEqual(auth.token, "")
     self.assertEqual(auth.token_secret, "")
Exemplo n.º 4
0
 def test_default_config(self):
     """ Ensure the default config is loaded """
     self.create_config("default", "Test Default Host")
     client = Trovebox()
     auth = client.auth
     self.assertEqual(client.host, "Test Default Host")
     self.assertEqual(auth.consumer_key, "default_consumer_key")
     self.assertEqual(auth.consumer_secret, "default_consumer_secret")
     self.assertEqual(auth.token, "default_token")
     self.assertEqual(auth.token_secret, "default_token_secret")
Exemplo n.º 5
0
 def test_full_config_path(self):
     """ Ensure a full custom config path can be loaded """
     self.create_config("path", "Test Path Host")
     full_path = os.path.abspath(CONFIG_PATH)
     client = Trovebox(config_file=os.path.join(full_path, "path"))
     auth = client.auth
     self.assertEqual(client.host, "Test Path Host")
     self.assertEqual(auth.consumer_key, "path_consumer_key")
     self.assertEqual(auth.consumer_secret, "path_consumer_secret")
     self.assertEqual(auth.token, "path_token")
     self.assertEqual(auth.token_secret, "path_token_secret")
Exemplo n.º 6
0
 def test_custom_config(self):
     """ Ensure a custom config can be loaded """
     self.create_config("default", "Test Default Host")
     self.create_config("custom", "Test Custom Host")
     client = Trovebox(config_file="custom")
     auth = client.auth
     self.assertEqual(client.host, "Test Custom Host")
     self.assertEqual(auth.consumer_key, "custom_consumer_key")
     self.assertEqual(auth.consumer_secret, "custom_consumer_secret")
     self.assertEqual(auth.token, "custom_token")
     self.assertEqual(auth.token_secret, "custom_token_secret")
Exemplo n.º 7
0
 def test_partial_config_file(self):
     """ Test that an incomplete config file causes default values to be set """
     self.create_config("incomplete",
                        host=None)  # Don't write the host line
     client = Trovebox(config_file="incomplete")
     auth = client.auth
     self.assertEqual(auth.host, "localhost")
     self.assertEqual(auth.consumer_key, "incomplete_consumer_key")
     self.assertEqual(auth.consumer_secret, "incomplete_consumer_secret")
     self.assertEqual(auth.token, "incomplete_token")
     self.assertEqual(auth.token_secret, "incomplete_token_secret")
Exemplo n.º 8
0
Created by Magnus Wahlberg on 2013-11-27.
Copyright (c) 2012 Wahlberg Research And Development. All rights reserved.
"""

import os
import sys
import imghdr
import hashlib
import argparse
from trovebox import Trovebox
from trovebox.errors import TroveboxError, TroveboxDuplicateError

# Init
try:
    client = Trovebox()
    client.configure(api_version=2)

except IOError, E:
    print 'Could not connect to Trovebox'
    print 'Please check ~/.config/trovebox/default.'
    print 'More info: https://github.com/photo/openphoto-python'
    raise E

def is_folder(path):
    return os.path.isdir(path)


def image_uploaded(photo, return_data=False):
    res = client.photos.list(hash=hash_file(photo))
Exemplo n.º 9
0
  parser.add_argument('--host', help="Hostname of the Trovebox server (overrides config_file)")
  parser.add_argument('--consumer-key')
  parser.add_argument('--consumer-secret')
  parser.add_argument('--token')
  parser.add_argument('--token-secret')
  parser.add_argument('--disable-ssl-verify', help="Disable ssl check for server with self signed certificate", action="store_true")
  parser.add_argument('--debug', help="Print extra debug information", action="store_true")
  config = parser.parse_args()

  if config.debug:
    logging.basicConfig(level=logging.DEBUG)

  # Host option overrides config file settings
  if config.host:
    client = Trovebox(host=config.host, consumer_key=config.consumer_key,
                      consumer_secret=config.consumer_secret,
                      token=config.token, token_secret=config.token_secret)
  else:
    try:
      client = Trovebox(config_file=config.config)
    except IOError as error:
      print error
      print
      print "You must create a configuration file in ~/.config/trovebox/default"
      print "with the following contents:"
      print "    host = your.host.com"
      print "    consumerKey = your_consumer_key"
      print "    consumerSecret = your_consumer_secret"
      print "    token = your_access_token"
      print "    tokenSecret = your_access_token_secret"
      print
Exemplo n.º 10
0
    parser.add_argument('--consumer-secret')
    parser.add_argument('--token')
    parser.add_argument('--token-secret')
    parser.add_argument('--debug',
                        help="Print extra debug information",
                        action="store_true")
    config = parser.parse_args()

    if config.debug:
        logging.basicConfig(level=logging.DEBUG)

    # Host option overrides config file settings
    if config.host:
        client = Trovebox(host=config.host,
                          consumer_key=config.consumer_key,
                          consumer_secret=config.consumer_secret,
                          token=config.token,
                          token_secret=config.token_secret)
    else:
        try:
            client = Trovebox(config_file=config.config)
        except IOError as error:
            print error
            print
            print "You must create a configuration file in ~/.config/trovebox/default"
            print "with the following contents:"
            print "    host = your.host.com"
            print "    consumerKey = your_consumer_key"
            print "    consumerSecret = your_consumer_secret"
            print "    token = your_access_token"
            print "    tokenSecret = your_access_token_secret"
Exemplo n.º 11
0
 def test_host_and_config_file(self):
     """ It's not valid to specify both a host and a config_file """
     self.create_config("custom", "Test Custom Host")
     with self.assertRaises(ValueError):
         Trovebox(config_file="custom", host="host_override")
Exemplo n.º 12
0
 def test_missing_config_files(self):
     """ Ensure that missing config files raise exceptions """
     with self.assertRaises(IOError):
         Trovebox()
     with self.assertRaises(IOError):
         Trovebox(config_file="custom")