Permalink
Browse files

Added README, improved logging and POST fields

  • Loading branch information...
joar committed Sep 23, 2012
1 parent b1d59ad commit f7be852d526096cb068887d449733af2d135707e
Showing with 85 additions and 3 deletions.
  1. +57 −0 README.rst
  2. +23 −3 automgtic/__init__.py
  3. +5 −0 run.py
View
@@ -0,0 +1,57 @@
+===========
+ automgtic
+===========
+
+automgtic is an automatic media uploader for GNU MediaGoblin.
+
+----------
+ Features
+----------
+
+automgtic authenticates to the GNU MediaGoblin server via `OAuth draft v2.25`_.
+
+automgtic uses a local database to keep track of the files where it stores:
+
+- An MD5 digest of the file to prevent multiple uploads of the same file due to
+ filesystem changes.
+- The filename of the file when it was uploaded.
+- The metadata returned by the GNU MediaGoblin server when the file was posted.
+
+.. _`oauth draft v2.25`: http://tools.ietf.org/html/draft-ietf-oauth-v2-25
+
+--------------
+ Installation
+--------------
+
+To install automgtic, download the files or clone the repo, then ``cd`` to the
+directory containing the ``automgtic.ini`` file and run::
+
+ virtualenv . # Create a new python virtualenv
+ . bin/activate # Activate the virtualenv
+ python setup.py develop # Fetch all the dependencies into your virtualenv
+ # !! - This is a single command split up on two lines
+ python -c "from automgtic.models import Base, engine
+ Base.metadata.create_all(engine)" # Create the DB tables
+
+
+-------
+ Usage
+-------
+
+Once you have installed the dependencies, you need to have an OAuth client
+registered on the GNU MediaGoblin instance, you can register one at
+``instance.example/oauth/client/register``.
+
+Once you have registered your OAuth client you need the client identifier in
+your config.
+
+.. warning::
+ Before you start editing your config, do ``cp automgtic.ini
+ automgtic_local.ini``, this to separate the version-controlled
+ ``automgtic.ini`` from your local settings.
+
+When the ``client_id`` is set, run ``./run.py --authorize``, then follow the
+instructions provided. This will update your ``.ini`` with the ``access_token``
+field and you will be ready to upload media with automgtic.
+
+To upload media from a directory, simply run ``./run.py --run <directory>``.
View
@@ -37,6 +37,7 @@ def load_config():
interpolation='ConfigParser')
validator = Validator()
+ # TODO: Add validation error handling
validation_result = config.validate(validator, preserve_errors=True)
app_config = config['automgtic']
@@ -51,18 +52,37 @@ def load_config():
def walk_files(directory):
for root, directories, files in os.walk(directory):
for f in files:
- yield os.path.join(root, f)
+ path = os.path.join(root, f)
+
+ if not os.path.isfile(path):
+ continue
+
+ file_extension = os.path.splitext(path)[-1][1:]
+ _log.debug('file extension: {0}'.format(file_extension))
+
+ if file_extension and \
+ file_extension.lower() in app_config.get('file_extensions'):
+ yield path
def upload_if_not_exist(path, digest):
media = Media.query.filter(Media.digest == unicode(digest)).first()
if media:
- _log.debug('Contents of {0} already exist on the server'.format(path))
+ _log.info('Contents of {0} already exist on the server as {1}'.format(
+ path,
+ media.name))
return
_log.info('Uploading {0}...'.format(path))
- datagen, headers = multipart_encode({'file': open(path, 'rb')})
+ fields = {
+ 'file': open(path, 'rb'),
+ 'title': os.path.split(path)[-1],
+ 'description': '',
+ 'license': '',
+ 'tags': ''}
+
+ datagen, headers = multipart_encode(fields)
request = Request(mg_config['server'] + '/api/submit?access_token=' \
+ mg_config['access_token'],
View
5 run.py
@@ -25,9 +25,14 @@
const=True,
action='store_const',
help='Run the autouploader')
+ parser.add_argument(
+ '--level',
+ help='Logging level, one of [ CRITICAL | ERROR | WARNING | INFO | DEBUG ], default: INFO')
args = parser.parse_args()
+ root_log.setLevel(getattr(logging, args.level or 'INFO'))
+
root_log.debug(args)
if args.authorize:

0 comments on commit f7be852

Please sign in to comment.