home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / stdpaths.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-11-24  |  8.3 KB  |  262 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.         ('GetTempDir', GetTempDir)]
  149.     Storage = Storage
  150.     import util.primitives.mapping
  151.     s = Storage()
  152.     for p in paths:
  153.         name = p[0]
  154.         if hasattr(p[1], '__call__'):
  155.             s[name] = p[1]
  156.             continue
  157.         config.platform != 'win'
  158.         csidl = p[1]
  159.         append_app_name = p[2]
  160.         if append_app_name:
  161.             
  162.             method = lambda id = (csidl,): GetFolderLocation(id) + '\\' + appname
  163.         else:
  164.             
  165.             method = lambda id = csidl: GetFolderLocation(id)
  166.         setattr(s, name, method)
  167.     
  168.     _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())
  169.     _winpaths = [
  170.         ('GetUserStartupDir', CSIDL.STARTUP),
  171.         ('GetStartupDir', CSIDL.COMMON_STARTUP),
  172.         ('GetUserDesktopDir', CSIDL.DESKTOP),
  173.         ('GetDesktopDir', CSIDL.COMMON_DESKTOPDIRECTORY)]
  174.     for method_name, csidl in _winpaths:
  175.         setattr(s, method_name, (lambda id = csidl: GetFolderLocation(id)))
  176.     
  177.     _set_paths(userstartup = s.GetUserStartupDir(), startup = s.GetStartupDir(), userdesktop = s.GetUserDesktopDir(), desktop = s.GetDesktopDir())
  178.  
  179. if sys.platform == 'win32':
  180.     
  181.     class CSIDL(object):
  182.         DESKTOP = 0
  183.         INTERNET = 1
  184.         PROGRAMS = 2
  185.         CONTROLS = 3
  186.         PRINTERS = 4
  187.         PERSONAL = 5
  188.         FAVORITES = 6
  189.         STARTUP = 7
  190.         RECENT = 8
  191.         SENDTO = 9
  192.         BITBUCKET = 10
  193.         STARTMENU = 11
  194.         MYDOCUMENTS = 12
  195.         MYMUSIC = 13
  196.         MYVIDEO = 14
  197.         DESKTOPDIRECTORY = 16
  198.         DRIVES = 17
  199.         NETWORK = 18
  200.         NETHOOD = 19
  201.         FONTS = 20
  202.         TEMPLATES = 21
  203.         COMMON_STARTMENU = 22
  204.         COMMON_PROGRAMS = 23
  205.         COMMON_STARTUP = 24
  206.         COMMON_DESKTOPDIRECTORY = 25
  207.         APPDATA = 26
  208.         PRINTHOOD = 27
  209.         LOCAL_APPDATA = 28
  210.         ALTSTARTUP = 29
  211.         COMMON_ALTSTARTUP = 30
  212.         COMMON_FAVORITES = 31
  213.         INTERNET_CACHE = 32
  214.         COOKIES = 33
  215.         HISTORY = 34
  216.         COMMON_APPDATA = 35
  217.         WINDOWS = 36
  218.         SYSTEM = 37
  219.         PROGRAM_FILES = 38
  220.         MYPICTURES = 39
  221.         PROFILE = 40
  222.         SYSTEMX86 = 41
  223.         PROGRAM_FILESX86 = 42
  224.         PROGRAM_FILES_COMMON = 43
  225.         PROGRAM_FILES_COMMONX86 = 44
  226.         COMMON_TEMPLATES = 45
  227.         COMMON_DOCUMENTS = 46
  228.         COMMON_ADMINTOOLS = 47
  229.         ADMINTOOLS = 48
  230.         CONNECTIONS = 49
  231.         COMMON_MUSIC = 53
  232.         COMMON_PICTURES = 54
  233.         COMMON_VIDEO = 55
  234.         RESOURCES = 56
  235.         RESOURCES_LOCALIZED = 57
  236.         COMMON_OEM_LINKS = 58
  237.         CDBURN_AREA = 59
  238.  
  239.  
  240.  
  241. def _set_paths(**d):
  242.     for k in d.keys():
  243.         v = path(d[k]).abspath()
  244.         globals()[k] = v
  245.         if v.isfile():
  246.             continue
  247.         
  248.         if not v.isdir():
  249.             
  250.             try:
  251.                 v.makedirs()
  252.             except Exception:
  253.                 import traceback
  254.                 traceback.print_exc()
  255.             except:
  256.                 None<EXCEPTION MATCH>Exception
  257.             
  258.  
  259.         None<EXCEPTION MATCH>Exception
  260.     
  261.  
  262.