~facundo/ubuntuone-client/fix-failure-handling

« back to all changes in this revision

Viewing changes to ubuntuone/platform/tools/windows.py

  • Committer: Tarmac
  • Author(s): Manuel de la Pena
  • Date: 2012-05-29 09:16:13 UTC
  • mfrom: (1245.1.11 unify-tools)
  • Revision ID: tarmac-20120529091613-p3v1mgi0548fq2w5
- Refactored the tools code so that it is shared between windows and darwin (LP: #1002994).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#
 
3
# Copyright 2012 Canonical Ltd.
 
4
#
 
5
# This program is free software: you can redistribute it and/or modify it
 
6
# under the terms of the GNU General Public License version 3, as published
 
7
# by the Free Software Foundation.
 
8
#
 
9
# This program is distributed in the hope that it will be useful, but
 
10
# WITHOUT ANY WARRANTY; without even the implied warranties of
 
11
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
12
# PURPOSE.  See the GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License along
 
15
# with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
#
 
17
# In addition, as a special exception, the copyright holders give
 
18
# permission to link the code of portions of this program with the
 
19
# OpenSSL library under certain conditions as described in each
 
20
# individual source file, and distribute linked combinations
 
21
# including the two.
 
22
# You must obey the GNU General Public License in all respects
 
23
# for all of the code used other than OpenSSL.  If you modify
 
24
# file(s) with this exception, you may extend this exception to your
 
25
# version of the file(s), but you are not obligated to do so.  If you
 
26
# do not wish to do so, delete this exception statement from your
 
27
# version.  If you delete this exception statement from all source
 
28
# files in the program, then also delete it here.
 
29
"""SyncDaemon Tools windows implementation."""
 
30
 
 
31
import errno
 
32
import os
 
33
import sys
 
34
 
 
35
from _winreg import OpenKey, HKEY_LOCAL_MACHINE, QueryValueEx
 
36
 
 
37
 
 
38
U1_REG_PATH = r'Software\\Ubuntu One'
 
39
SD_INSTALL_PATH = 'SyncDaemonInstallPath'
 
40
 
 
41
# ugly trick to stop pylint for complaining about
 
42
# WindowsError on Linux
 
43
if sys.platform != 'win32':
 
44
    WindowsError = None
 
45
 
 
46
 
 
47
def get_sd_install_path():
 
48
    """Return the path where the sd script was installed."""
 
49
    # look in the reg to find the path of the .exe to be executed
 
50
    # to launch the sd on windows
 
51
    key = OpenKey(HKEY_LOCAL_MACHINE, U1_REG_PATH)
 
52
    path = QueryValueEx(key, SD_INSTALL_PATH)[0]
 
53
    if not os.path.exists(path):
 
54
        raise WindowsError(errno.ENOENT,
 
55
            'Could not start syncdaemon: File not found %s' % path)
 
56
    return path