mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-25 08:55:50 +00:00
Init
This commit is contained in:
commit
be81b48060
3 changed files with 101 additions and 0 deletions
29
vdirsyncer/cli.py
Normal file
29
vdirsyncer/cli.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import os
|
||||
import ConfigParser
|
||||
from vdirsyncer.cli_utils import path
|
||||
from vdirsyncer.sync import sync_classes
|
||||
|
||||
def get_config_parser(env):
|
||||
fname = env.get('VDIRSYNCER_CONFIG', path('~/.vdirsyncer/config'))
|
||||
c = ConfigParser.SafeConfigParser()
|
||||
c.read(fname)
|
||||
return dict((c, c.items(c)) for c in c.sections())
|
||||
|
||||
def main():
|
||||
env = os.environ
|
||||
cfg = get_config_parser(env)
|
||||
_main(env, cfg)
|
||||
|
||||
def _main(env, file_cfg):
|
||||
app = argvard.Argvard()
|
||||
|
||||
sync = argvard.Command()
|
||||
@sync_command.main('[accounts...]')
|
||||
def sync_main(accounts=None):
|
||||
if accounts is None:
|
||||
accounts = list(file_cfg.keys())
|
||||
for account in accounts:
|
||||
account_cfg = dict(file_cfg[account])
|
||||
del account_cfg['type']
|
||||
syncer = sync_classes[account_cfg['type']](**account_cfg)
|
||||
syncer.run()
|
||||
37
vdirsyncer/cli_utils.py
Normal file
37
vdirsyncer/cli_utils.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
watdo.cli_utils
|
||||
~~~~~~~~~
|
||||
|
||||
This module contains helper functions that should be useful for arbitrary
|
||||
CLI interfaces.
|
||||
|
||||
:copyright: (c) 2013 Markus Unterwaditzer
|
||||
:license: MIT, see LICENSE for more details.
|
||||
'''
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def bail_out(msg):
|
||||
print(msg)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def check_directory(path):
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
|
||||
|
||||
def path(p):
|
||||
p = os.path.expanduser(p)
|
||||
p = os.path.abspath(p)
|
||||
return p
|
||||
|
||||
|
||||
def confirm(message='Are you sure? (Y/n)'):
|
||||
inp = raw_input(message).lower().strip()
|
||||
if not inp or inp == 'y':
|
||||
return True
|
||||
return False
|
||||
35
vdirsyncer/sync/base.py
Normal file
35
vdirsyncer/sync/base.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
class Syncer(object):
|
||||
def list_items(self):
|
||||
'''
|
||||
:returns: list of (href, etag)
|
||||
'''
|
||||
raise NotImplementedError()
|
||||
|
||||
def get_items(self, hrefs):
|
||||
'''
|
||||
:param hrefs: list of hrefs to fetch
|
||||
:returns: list of (object, href, etag)
|
||||
'''
|
||||
raise NotImplementedError()
|
||||
|
||||
def item_exists(self, href):
|
||||
'''
|
||||
check if item exists
|
||||
'''
|
||||
raise NotImplementedError()
|
||||
|
||||
def upload(self, obj):
|
||||
'''
|
||||
Upload a new object, raise error if it already exists.
|
||||
:returns: (href, etag)
|
||||
'''
|
||||
raise NotImplementedError()
|
||||
|
||||
def update(self, obj, etag):
|
||||
'''
|
||||
Update the object, raise error if the etag on the server doesn't match
|
||||
the given etag.
|
||||
|
||||
:returns: etag on the server
|
||||
'''
|
||||
raise NotImplementedError()
|
||||
Loading…
Reference in a new issue