Skip to content

Commit

Permalink
set contact details only if not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Lindemann committed Dec 7, 2016
1 parent 8c8327b commit b6210eb
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions tools/osf_sync.py
Expand Up @@ -11,6 +11,7 @@ class OSFSync(object):
def __init__(self, osf_project_file = "osfsync.proj"):
""" If project file exists, use this & connect.
"""
self.clear_connection_details()
self.osf_project_file = path.realpath(osf_project_file)
if path.isfile(osf_project_file):
try:
Expand All @@ -23,6 +24,8 @@ def __init__(self, osf_project_file = "osfsync.proj"):
if self._project is not None:
print("Connected to OSF project '{0}'.".format(self._project.project_id))


def clear_connection_details(self):
self.osf_username = None
self.osf_project_id = None
self.sync_folder = None
Expand All @@ -33,30 +36,41 @@ def is_connected(self):
return self._project is not None


def set_connection_details(self,osf_username=None, osf_project_id=None, sync_folder=None):
"""Ask via command line for all required details that are specified.
"""
def set_username(self, osf_username=None):
"""Set usename if specified otherwise ask via command line if not yet defined."""

if osf_username is None:
if osf_username is None and self.osf_username is None:
osf_username = input("OSF Username: ")
self.osf_username = osf_username
if osf_username is not None:
self.osf_username = osf_username


if osf_project_id is None:
def set_connection_details(self, osf_username=None, osf_project_id=None, sync_folder=None):
"""Set connection details if specified otherwise ask via command line for all connection details
that are not yet defined."""

self.set_username(osf_username=osf_username)

if osf_project_id is None and self.osf_project_id is None:
osf_project_id = input("OSF project id: ")
self.osf_project_id = osf_project_id
if osf_project_id is not None:
self.osf_project_id = osf_project_id

if sync_folder is None:
if sync_folder is None and self.sync_folder is None:
sync_folder = input("Sync subfolder [default='data']: ")
if len(sync_folder)<1:
sync_folder = 'data'
self.sync_folder = path.realpath(sync_folder)
if sync_folder is not None:
self.sync_folder = path.realpath(sync_folder)


def get_auth_token(self, password=None):
"""Gets the auth token
see also pyosf documentation"""

self.set_username()

if password is None:
password = getpass.getpass()
try:
Expand All @@ -68,8 +82,7 @@ def get_auth_token(self, password=None):
def connect(self):
"""connect with OSF project"""

if self.osf_username is None:
self.set_connection_details()
self.set_connection_details()

try:
session = pyosf.Session(username=self.osf_username)
Expand Down

0 comments on commit b6210eb

Please sign in to comment.