import shutil
import os
import errno
+import signal
from apperror import AppError
from settings import appconf
raise AppError('Profile Name not valid')
print("Profile "+profileName+" created.")
+ def isCurrentProfile(self, ppath):
+ """ Returns true if the current profile path is currently activated """
+
+ pl = platform.system()
+ if pl in ('Linux','Darwin'):
+ if os.path.exists(self.getDropboxDirectory()):
+ return True if os.readlink(self.getDropboxDirectory()) == ppath else False
+ else:
+ return False
+
def isValidProfileName(self, pname):
+
if self.reg.match(pname) is not None:
return True
else:
return False
def activateProfile(self, ppath):
+ pl = platform.system()
if ppath in self.getProfilesList():
self.stopDropbox()
try:
- with open(ppath) as pdir:
- os.unlink(self.getDropboxDirectory())
+ print self.getDropboxDirectory()
+ print ppath
+ if pl in ('Linux','Darwin'):
+ if os.path.exists(self.getDropboxDirectory()):
+ os.unlink(self.getDropboxDirectory())
os.symlink(ppath, self.getDropboxDirectory())
+ else:
+ raise NotImplementedError, "Not implemented yet."
except IOError as e:
- raise AppError('Error on activating Profile: '+ppath)
+ raise AppError('Error on activating Profile: '+ os.path.basename(ppath))
self.startDropbox()
else:
raise AppError("Trying to acrivate non existant profile")
else:
raise NotImplementedError, "Not implemented yet."
+ def stopDropbox(self):
+ """ Stop dropbox Daemon """
+ pl = platform.system()
+ if pl == 'Linux':
+ os.system("dropbox stop")
+ if pl in ('Linux','Darwin'):
+ pidfile = os.path.expanduser("~/.dropbox/dropbox.pid")
+ try:
+ with open(pidfile, "r") as f:
+ pid = int(f.read())
+ os.kill(pid, signal.SIGTERM)
+ except:
+ pass
+
+ def startDropbox(self):
+ """ Sart dropbox Daemon """
+
+ pl = platform.system()
+ if pl == 'Linux':
+ try:
+ os.system("dropbox start -i")
+ except:
+ raise AppError(u"Could not start dropbox.")
+ elif pl == 'Darwin':
+ os.system("/Applications/Dropbox.app/Contents/MacOS/Dropbox &")
+
__CSL = None
def winsymlink(source, link_name):