home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1431 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  8.2 KB  |  229 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __VERSION__ = '0.2'
  5. import os
  6. from win32com import storagecon
  7. from win32com.shell import shell, shellcon
  8. import pythoncom
  9.  
  10. class x_winshell(Exception):
  11.     pass
  12.  
  13.  
  14. def get_path(folder_id):
  15.     return shell.SHGetPathFromIDList(shell.SHGetSpecialFolderLocation(0, folder_id))
  16.  
  17.  
  18. def desktop(common = 0):
  19.     return get_path((shellcon.CSIDL_DESKTOP, shellcon.CSIDL_COMMON_DESKTOPDIRECTORY)[common])
  20.  
  21.  
  22. def common_desktop():
  23.     return desktop(common = 1)
  24.  
  25.  
  26. def application_data(common = 0):
  27.     return get_path((shellcon.CSIDL_APPDATA, shellcon.CSIDL_COMMON_APPDATA)[common])
  28.  
  29.  
  30. def favourites(common = 0):
  31.     return get_path((shellcon.CSIDL_FAVORITES, shellcon.CSIDL_COMMON_FAVORITES)[common])
  32.  
  33. bookmarks = favourites
  34.  
  35. def start_menu(common = 0):
  36.     return get_path((shellcon.CSIDL_STARTMENU, shellcon.CSIDL_COMMON_STARTMENU)[common])
  37.  
  38.  
  39. def programs(common = 0):
  40.     return get_path((shellcon.CSIDL_PROGRAMS, shellcon.CSIDL_COMMON_PROGRAMS)[common])
  41.  
  42.  
  43. def startup(common = 0):
  44.     return get_path((shellcon.CSIDL_STARTUP, shellcon.CSIDL_COMMON_STARTUP)[common])
  45.  
  46.  
  47. def personal_folder():
  48.     return get_path(shellcon.CSIDL_PERSONAL)
  49.  
  50. my_documents = personal_folder
  51.  
  52. def recent():
  53.     return get_path(shellcon.CSIDL_RECENT)
  54.  
  55.  
  56. def sendto():
  57.     return get_path(shellcon.CSIDL_SENDTO)
  58.  
  59.  
  60. def _file_operation(operation, source_path, target_path = None, allow_undo = True, no_confirm = False, rename_on_collision = True, silent = False, hWnd = None):
  61.     if not source_path:
  62.         pass
  63.     source_path = ''
  64.     if not target_path:
  65.         pass
  66.     target_path = ''
  67.     flags = 0
  68.     if allow_undo:
  69.         flags |= shellcon.FOF_ALLOWUNDO
  70.     
  71.     if no_confirm:
  72.         flags |= shellcon.FOF_NOCONFIRMATION
  73.     
  74.     if rename_on_collision:
  75.         flags |= shellcon.FOF_RENAMEONCOLLISION
  76.     
  77.     if silent:
  78.         flags |= shellcon.FOF_SILENT
  79.     
  80.     if not hWnd:
  81.         pass
  82.     (result, n_aborted) = shell.SHFileOperation((0, operation, source_path, target_path, flags, None, None))
  83.     if result != 0:
  84.         raise x_winshell, result
  85.     result != 0
  86.     if n_aborted:
  87.         raise x_winshell, '%d operations were aborted by the user' % n_aborted
  88.     n_aborted
  89.  
  90.  
  91. def copy_file(source_path, target_path, allow_undo = True, no_confirm = False, rename_on_collision = True, silent = False, hWnd = None):
  92.     _file_operation(shellcon.FO_COPY, source_path, target_path, allow_undo, no_confirm, rename_on_collision, silent, hWnd)
  93.  
  94.  
  95. def move_file(source_path, target_path, allow_undo = True, no_confirm = False, rename_on_collision = True, silent = False, hWnd = None):
  96.     _file_operation(shellcon.FO_MOVE, source_path, target_path, allow_undo, no_confirm, rename_on_collision, silent, hWnd)
  97.  
  98.  
  99. def rename_file(source_path, target_path, allow_undo = True, no_confirm = False, rename_on_collision = True, silent = False, hWnd = None):
  100.     _file_operation(shellcon.FO_RENAME, source_path, target_path, allow_undo, no_confirm, rename_on_collision, silent, hWnd)
  101.  
  102.  
  103. def delete_file(source_path, allow_undo = True, no_confirm = False, rename_on_collision = True, silent = False, hWnd = None):
  104.     _file_operation(shellcon.FO_DELETE, source_path, None, allow_undo, no_confirm, rename_on_collision, silent, hWnd)
  105.  
  106.  
  107. def CreateShortcut(Path, Target, Arguments = '', StartIn = '', Icon = ('', 0), Description = ''):
  108.     sh = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
  109.     sh.SetPath(Target)
  110.     sh.SetDescription(Description)
  111.     sh.SetArguments(Arguments)
  112.     sh.SetWorkingDirectory(StartIn)
  113.     sh.SetIconLocation(Icon[0], Icon[1])
  114.     persist = sh.QueryInterface(pythoncom.IID_IPersistFile)
  115.     persist.Save(Path, 1)
  116.  
  117. FMTID_USER_DEFINED_PROPERTIES = '{F29F85E0-4FF9-1068-AB91-08002B27B3D9}'
  118. FMTID_CUSTOM_DEFINED_PROPERTIES = '{D5CDD505-2E9C-101B-9397-08002B2CF9AE}'
  119. PIDSI_TITLE = 2
  120. PIDSI_SUBJECT = 3
  121. PIDSI_AUTHOR = 4
  122. PIDSI_CREATE_DTM = 12
  123. PIDSI_KEYWORDS = 5
  124. PIDSI_COMMENTS = 6
  125. PIDSI_TEMPLATE = 7
  126. PIDSI_LASTAUTHOR = 8
  127. PIDSI_REVNUMBER = 9
  128. PIDSI_EDITTIME = 10
  129. PIDSI_LASTPRINTED = 11
  130. PIDSI_LASTSAVE_DTM = 13
  131. PIDSI_PAGECOUNT = 14
  132. PIDSI_WORDCOUNT = 15
  133. PIDSI_CHARCOUNT = 16
  134. PIDSI_THUMBNAIL = 17
  135. PIDSI_APPNAME = 18
  136. PROPERTIES = (PIDSI_TITLE, PIDSI_SUBJECT, PIDSI_AUTHOR, PIDSI_CREATE_DTM, PIDSI_KEYWORDS, PIDSI_COMMENTS, PIDSI_TEMPLATE, PIDSI_LASTAUTHOR, PIDSI_EDITTIME, PIDSI_LASTPRINTED, PIDSI_LASTSAVE_DTM, PIDSI_PAGECOUNT, PIDSI_WORDCOUNT, PIDSI_CHARCOUNT, PIDSI_APPNAME)
  137.  
  138. def structured_storage(filename):
  139.     if not pythoncom.StgIsStorageFile(filename):
  140.         return { }
  141.     flags = storagecon.STGM_READ | storagecon.STGM_SHARE_EXCLUSIVE
  142.     storage = pythoncom.StgOpenStorage(filename, None, flags)
  143.     
  144.     try:
  145.         properties_storage = storage.QueryInterface(pythoncom.IID_IPropertySetStorage)
  146.     except pythoncom.com_error:
  147.         pythoncom.StgIsStorageFile(filename)
  148.         pythoncom.StgIsStorageFile(filename)
  149.         return { }
  150.  
  151.     property_sheet = properties_storage.Open(FMTID_USER_DEFINED_PROPERTIES)
  152.     
  153.     try:
  154.         data = property_sheet.ReadMultiple(PROPERTIES)
  155.     finally:
  156.         property_sheet = None
  157.  
  158.     (title, subject, author, created_on, keywords, comments, template_used, updated_by, edited_on, printed_on, saved_on, n_pages, n_words, n_characters, application) = data
  159.     result = { }
  160.     if title:
  161.         result['title'] = title
  162.     
  163.     if subject:
  164.         result['subject'] = subject
  165.     
  166.     if author:
  167.         result['author'] = author
  168.     
  169.     if created_on:
  170.         result['created_on'] = created_on
  171.     
  172.     if keywords:
  173.         result['keywords'] = keywords
  174.     
  175.     if comments:
  176.         result['comments'] = comments
  177.     
  178.     if template_used:
  179.         result['template_used'] = template_used
  180.     
  181.     if updated_by:
  182.         result['updated_by'] = updated_by
  183.     
  184.     if edited_on:
  185.         result['edited_on'] = edited_on
  186.     
  187.     if printed_on:
  188.         result['printed_on'] = printed_on
  189.     
  190.     if saved_on:
  191.         result['saved_on'] = saved_on
  192.     
  193.     if n_pages:
  194.         result['n_pages'] = n_pages
  195.     
  196.     if n_words:
  197.         result['n_words'] = n_words
  198.     
  199.     if n_characters:
  200.         result['n_characters'] = n_characters
  201.     
  202.     if application:
  203.         result['application'] = application
  204.     
  205.     return result
  206.  
  207. if __name__ == '__main__':
  208.     
  209.     try:
  210.         print 'Desktop =>', desktop()
  211.         print 'Common Desktop =>', desktop(1)
  212.         print 'Application Data =>', application_data()
  213.         print 'Common Application Data =>', application_data(1)
  214.         print 'Bookmarks =>', bookmarks()
  215.         print 'Common Bookmarks =>', bookmarks(1)
  216.         print 'Start Menu =>', start_menu()
  217.         print 'Common Start Menu =>', start_menu(1)
  218.         print 'Programs =>', programs()
  219.         print 'Common Programs =>', programs(1)
  220.         print 'Startup =>', startup()
  221.         print 'Common Startup =>', startup(1)
  222.         print 'My Documents =>', my_documents()
  223.         print 'Recent =>', recent()
  224.         print 'SendTo =>', sendto()
  225.     finally:
  226.         raw_input('Press enter...')
  227.  
  228.  
  229.