home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2012 January / maximum-cd-2012-01.iso / DiscContents / digsby_setup.exe / lib / stdpaths.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-10-05  |  8.4 KB  |  263 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import config
  5. import sys
  6. from path import path
  7. inited = False
  8. if config.platform == 'win':
  9.     import ctypes
  10.     SHGFP_TYPE_DEFAULT = 1
  11.     MAX_PATH = 260
  12.     u_buffer = ctypes.create_unicode_buffer(MAX_PATH)
  13.     s_buffer = ctypes.create_string_buffer(MAX_PATH)
  14.     SHGetFolderPath = ctypes.windll.shell32.SHGetFolderPathW
  15.     
  16.     def GetSpecialFolder(csidl):
  17.         SHGetFolderPath(None, csidl, None, SHGFP_TYPE_DEFAULT, ctypes.byref(u_buffer))
  18.         return u_buffer.value
  19.  
  20.     
  21.     class SHItemID(ctypes.Structure):
  22.         _fields_ = [
  23.             ('cb', ctypes.c_ushort),
  24.             ('abID', ctypes.POINTER(ctypes.c_byte))]
  25.  
  26.     
  27.     class ItemIDList(ctypes.Structure):
  28.         _fields_ = [
  29.             ('mkid', SHItemID)]
  30.  
  31.     SHGetFolderLocation = ctypes.windll.shell32.SHGetFolderLocation
  32.     SHGetPathFromIDList = ctypes.windll.shell32.SHGetPathFromIDList
  33.     
  34.     def GetFolderLocation(csidl):
  35.         idl = ItemIDList()
  36.         idl.mkid.cb = ctypes.sizeof(ctypes.c_ushort)
  37.         pidl = ctypes.pointer(idl)
  38.         
  39.         try:
  40.             if SHGetFolderLocation(0, csidl, 0, 0, ctypes.byref(pidl)):
  41.                 raise WindowsError(ctypes.GetLastError())
  42.             SHGetFolderLocation(0, csidl, 0, 0, ctypes.byref(pidl))
  43.             if not SHGetPathFromIDList(pidl, s_buffer):
  44.                 raise WindowsError(ctypes.GetLastError())
  45.             SHGetPathFromIDList(pidl, s_buffer)
  46.         except WindowsError:
  47.             return GetSpecialFolder(csidl)
  48.  
  49.         return s_buffer.value
  50.  
  51.  
  52.  
  53. def init(reinit = False):
  54.     global inited
  55.     if inited and not reinit:
  56.         return None
  57.     inited = True
  58.     init_wx()
  59.     sys.is_portable = False
  60.     if not (sys.DEV) or sys.opts.allow_portable:
  61.         
  62.         try:
  63.             init_portable()
  64.         except Exception:
  65.             not reinit
  66.             not reinit
  67.             sys.is_portable = False
  68.         except:
  69.             not reinit
  70.  
  71.         sys.is_portable = True
  72.     
  73.  
  74.  
  75. def __res_dir():
  76.     import locale
  77.     if hasattr(sys, 'frozen') and sys.frozen == 'windows_exe':
  78.         prog_dir = path(sys.executable.decode(locale.getpreferredencoding())).abspath().dirname()
  79.     else:
  80.         import digsbypaths
  81.         prog_dir = path(digsbypaths.__file__).parent
  82.     return prog_dir / 'res'
  83.  
  84.  
  85. def init_portable():
  86.     import syck
  87.     
  88.     try:
  89.         f = _[1]
  90.         usb_info = syck.load(f)
  91.     finally:
  92.         pass
  93.  
  94.     for name in usb_info.keys():
  95.         usb_info[name] = path(usb_info[name]).abspath()
  96.     
  97.     _set_paths(**usb_info)
  98.  
  99.  
  100. def GetAppDir():
  101.     return path(sys.executable).parent
  102.  
  103.  
  104. def GetTempDir():
  105.     import os
  106.     for p in ('TMPDIR', 'TMP', 'TEMP'):
  107.         
  108.         try:
  109.             return os.environ[p]
  110.         continue
  111.         except KeyError:
  112.             continue
  113.         
  114.  
  115.     
  116.     return GetFolderLocation(CSIDL.LOCAL_APPDATA) + '\\Temp'
  117.  
  118.  
  119. def init_wx_old():
  120.     import wx
  121.     s = wx.StandardPaths.Get()
  122.     _set_paths(config = s.GetConfigDir(), data = s.GetDataDir(), documents = s.GetDocumentsDir(), executablepath = s.GetExecutablePath(), localdata = s.GetLocalDataDir(), userconfig = s.GetUserConfigDir(), userdata = s.GetUserDataDir(), userlocaldata = s.GetUserLocalDataDir(), temp = s.GetTempDir())
  123.     if sys.platform == 'win32':
  124.         _winpaths = [
  125.             ('GetUserStartupDir', CSIDL.STARTUP),
  126.             ('GetStartupDir', CSIDL.COMMON_STARTUP),
  127.             ('GetUserDesktopDir', CSIDL.DESKTOP),
  128.             ('GetDesktopDir', CSIDL.COMMON_DESKTOPDIRECTORY)]
  129.         for method_name, csidl in _winpaths:
  130.             setattr(wx.StandardPaths, method_name, (lambda p, id = csidl: p.GetFolderLocation(id)))
  131.         
  132.         _set_paths(userstartup = s.GetUserStartupDir(), startup = s.GetStartupDir(), userdesktop = s.GetUserDesktopDir(), desktop = s.GetDesktopDir())
  133.     
  134.  
  135.  
  136. def init_wx(appname = 'Digsby'):
  137.     if config.platform != 'win':
  138.         return init_wx_old()
  139.     paths = [
  140.         ('GetConfigDir', CSIDL.COMMON_APPDATA, True),
  141.         ('GetDataDir', GetAppDir),
  142.         ('GetDocumentsDir', CSIDL.PERSONAL, False),
  143.         ('GetExecutablePath', (lambda : sys.executable)),
  144.         ('GetLocalDataDir', GetAppDir),
  145.         ('GetUserConfigDir', CSIDL.APPDATA, False),
  146.         ('GetUserDataDir', CSIDL.APPDATA, True),
  147.         ('GetUserLocalDataDir', CSIDL.LOCAL_APPDATA, True),
  148.         ('GetUserLocalConfigDir', CSIDL.LOCAL_APPDATA, False),
  149.         ('GetTempDir', GetTempDir)]
  150.     Storage = Storage
  151.     import util.primitives.mapping
  152.     s = Storage()
  153.     for p in paths:
  154.         name = p[0]
  155.         if hasattr(p[1], '__call__'):
  156.             s[name] = p[1]
  157.             continue
  158.         config.platform != 'win'
  159.         csidl = p[1]
  160.         append_app_name = p[2]
  161.         if append_app_name:
  162.             
  163.             method = lambda id = (csidl,): GetFolderLocation(id) + '\\' + appname
  164.         else:
  165.             
  166.             method = lambda id = csidl: GetFolderLocation(id)
  167.         setattr(s, name, method)
  168.     
  169.     _set_paths(config = s.GetConfigDir(), data = s.GetDataDir(), documents = s.GetDocumentsDir(), executablepath = s.GetExecutablePath(), localdata = s.GetLocalDataDir(), userconfig = s.GetUserConfigDir(), userdata = s.GetUserDataDir(), userlocaldata = s.GetUserLocalDataDir(), userlocalconfig = s.GetUserLocalConfigDir(), temp = s.GetTempDir())
  170.     _winpaths = [
  171.         ('GetUserStartupDir', CSIDL.STARTUP),
  172.         ('GetStartupDir', CSIDL.COMMON_STARTUP),
  173.         ('GetUserDesktopDir', CSIDL.DESKTOP),
  174.         ('GetDesktopDir', CSIDL.COMMON_DESKTOPDIRECTORY)]
  175.     for method_name, csidl in _winpaths:
  176.         setattr(s, method_name, (lambda id = csidl: GetFolderLocation(id)))
  177.     
  178.     _set_paths(userstartup = s.GetUserStartupDir(), startup = s.GetStartupDir(), userdesktop = s.GetUserDesktopDir(), desktop = s.GetDesktopDir())
  179.  
  180. if sys.platform == 'win32':
  181.     
  182.     class CSIDL(object):
  183.         DESKTOP = 0
  184.         INTERNET = 1
  185.         PROGRAMS = 2
  186.         CONTROLS = 3
  187.         PRINTERS = 4
  188.         PERSONAL = 5
  189.         FAVORITES = 6
  190.         STARTUP = 7
  191.         RECENT = 8
  192.         SENDTO = 9
  193.         BITBUCKET = 10
  194.         STARTMENU = 11
  195.         MYDOCUMENTS = 12
  196.         MYMUSIC = 13
  197.         MYVIDEO = 14
  198.         DESKTOPDIRECTORY = 16
  199.         DRIVES = 17
  200.         NETWORK = 18
  201.         NETHOOD = 19
  202.         FONTS = 20
  203.         TEMPLATES = 21
  204.         COMMON_STARTMENU = 22
  205.         COMMON_PROGRAMS = 23
  206.         COMMON_STARTUP = 24
  207.         COMMON_DESKTOPDIRECTORY = 25
  208.         APPDATA = 26
  209.         PRINTHOOD = 27
  210.         LOCAL_APPDATA = 28
  211.         ALTSTARTUP = 29
  212.         COMMON_ALTSTARTUP = 30
  213.         COMMON_FAVORITES = 31
  214.         INTERNET_CACHE = 32
  215.         COOKIES = 33
  216.         HISTORY = 34
  217.         COMMON_APPDATA = 35
  218.         WINDOWS = 36
  219.         SYSTEM = 37
  220.         PROGRAM_FILES = 38
  221.         MYPICTURES = 39
  222.         PROFILE = 40
  223.         SYSTEMX86 = 41
  224.         PROGRAM_FILESX86 = 42
  225.         PROGRAM_FILES_COMMON = 43
  226.         PROGRAM_FILES_COMMONX86 = 44
  227.         COMMON_TEMPLATES = 45
  228.         COMMON_DOCUMENTS = 46
  229.         COMMON_ADMINTOOLS = 47
  230.         ADMINTOOLS = 48
  231.         CONNECTIONS = 49
  232.         COMMON_MUSIC = 53
  233.         COMMON_PICTURES = 54
  234.         COMMON_VIDEO = 55
  235.         RESOURCES = 56
  236.         RESOURCES_LOCALIZED = 57
  237.         COMMON_OEM_LINKS = 58
  238.         CDBURN_AREA = 59
  239.  
  240.  
  241.  
  242. def _set_paths(**d):
  243.     for k in d.keys():
  244.         v = path(d[k]).abspath()
  245.         globals()[k] = v
  246.         if v.isfile():
  247.             continue
  248.         
  249.         if not v.isdir():
  250.             
  251.             try:
  252.                 v.makedirs()
  253.             except Exception:
  254.                 import traceback
  255.                 traceback.print_exc()
  256.             except:
  257.                 None<EXCEPTION MATCH>Exception
  258.             
  259.  
  260.         None<EXCEPTION MATCH>Exception
  261.     
  262.  
  263.