From: stack Date: Sun, 8 Jul 2012 23:33:20 +0000 (+0200) Subject: profiling switching works on linux and maybe on osx, not yet tested X-Git-Url: https://v.licheni.net/stack/code/dboxswitch.git/commitdiff_plain/6387024f16be8f34ace846b605a8cf05938cd849?ds=inline;hp=3e7de2135e7a5ea09bfc8de537eed95c3be0325c profiling switching works on linux and maybe on osx, not yet tested --- diff --git a/profhandler.py b/profhandler.py index 5ef71e5..19a6b97 100755 --- a/profhandler.py +++ b/profhandler.py @@ -36,6 +36,7 @@ import re import shutil import os import errno +import signal from apperror import AppError from settings import appconf @@ -117,14 +118,20 @@ class ProfHandler(): 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") @@ -139,6 +146,30 @@ class ProfHandler(): else: raise NotImplementedError, "Not implemented yet." + def stopDropbox(self): + """ Stop dropbox Daemon """ + pl = platform.system() + 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):