Commit 34c13adc authored by Gaute Hope's avatar Gaute Hope

init local repo

parent 696e4da6
*.pyc
client_secret.json
.gmailieer.json
mail
......@@ -22,8 +22,8 @@ class Gmailieer:
parser = argparse.ArgumentParser ('Gmailieer', parents = [tools.argparser])
self.parser = parser
parser.add_argument ('action', choices = ['pull', 'push', 'auth'],
help = 'pull: get new e-mail and remote tag-changes, push: push local tag-changes, auth: authorize gmailieer with account')
parser.add_argument ('action', choices = ['pull', 'push', 'auth', 'init'],
help = 'pull: get new e-mail and remote tag-changes, push: push local tag-changes, auth: authorize gmailieer with account, init: initialize local repository')
parser.add_argument ('-c', '--credentials', type = str, default = 'client_secret.json',
help = 'credentials file for google api (default: client_secret.json)')
......@@ -32,13 +32,13 @@ class Gmailieer:
help = 'do not make any changes')
parser.add_argument ('-t', '--list-labels', action='store_true', default = False,
help = 'list all remote labels')
help = 'list all remote labels (pull)')
parser.add_argument ('-a', '--account', type = str, default = 'me',
help = 'GMail account to use (default: me, currently logged in user)')
parser.add_argument ('-f', '--force', action = 'store_true', default = False,
help = 'Force action')
help = 'Force action (auth)')
args = parser.parse_args (sys.argv[1:])
self.args = args
......@@ -56,6 +56,7 @@ class Gmailieer:
if self.dry_run:
print ("dry-run: ", self.dry_run)
self.local = Local (self)
self.remote = Remote (self)
if self.action == 'pull':
......@@ -69,6 +70,10 @@ class Gmailieer:
raise NotImplmentedError ()
elif self.action == 'init':
self.local.initialize_repository ()
def pull (self):
......
import os
import json
import mailbox
class Local:
def __init__ (self):
wd = None
class RepositoryException (Exception):
pass
class State:
def __init__ (self, state_f):
self.state_f = state_f
if os.path.exists (self.state_f):
with open (self.state_f, 'r') as fd:
self.json = json.load (fd)
else:
self.json = {}
def write (self):
with open (self.state_f, 'w') as fd:
json.dump (self.json, fd)
def __init__ (self, g):
self.gmailieer = g
self.wd = os.getcwd ()
# state file for local repository
self.state_f = os.path.join (self.wd, '.gmailieer.json')
# mail store
self.md = os.path.join (self.wd, 'mail')
def load_repository (self):
"""
Loads the current local repository
"""
if not os.path.exists (self.state_f):
raise Local.RepositoryException ('could not find state file')
if not os.path.exists (self.md):
raise Local.RepositoryException ('could not find mail dir')
self.state = Local.State (self.state_f)
def initialize_repository (self):
"""
Sets up a local repository
"""
print ("initializing repository in: %s.." % self.wd)
# check if there is a repository here already or if there is anything that will conflict with setting up one
if os.path.exists (self.state_f):
raise Local.RepositoryException ("'.gmailieer.json' exists: this repository seems to already be set up!")
if os.path.exists (self.md):
raise Local.RepositoryException ("'mail' exists: this repository seems to already be set up!")
self.state = Local.State (self.state_f)
self.state.write ()
os.makedirs (self.md)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment