Try building the attached code on Windows (I use 10 but you will
probably get same error on other versions), the purpose of the code is
to find the path to the users AppData folder in a cross-platform
manner. I get the following error: ImportError: No module named
'pythoncom'
I have tried everything I can think of to include the module in the
project but it's having none of it.

-- 
Thanks, Richie Ward
https://uk.linkedin.com/in/richie-ward-07ab0495
# Copyright (c) 2005 ActiveState Corp.
# License: MIT
# Author:  Trent Mick (TrentM at ActiveState.com)
# Contains xdg modiforcations by Richie Ward
# (Under same licence)
"""Cross-platform application utilities:

Utility Functions:
    user_data_dir(...)      path to user-specific app data dir
    site_data_dir(...)      path to all users shared app data dir
"""
#TODO:
# - Add cross-platform versions of other abstracted dir locations, like
#   a cache dir, prefs dir, something like bundle/Contents/SharedSupport
#   on OS X, etc.
#       
http://developer.apple.com/documentation/MacOSX/Conceptual/BPRuntimeConfig/Concepts/UserPreferences.html
#       
http://developer.apple.com/documentation/MacOSX/Conceptual/BPFileSystem/index.html
#       
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/enums/csidl.asp
#
from win32com.shell import shellcon, shell
import sys
import os

class Error(Exception):
    pass
        
def user_data_dir(appname, owner=None, version=None):
    """Return full path to the user-specific data dir for this application.
    
        "appname" is the name of application.
        "owner" (only required and used on Windows) is the name of the
            owner or distributing body for this application. Typically
            it is the owning company name.
        "version" is an optional version path element to append to the
            path. You might want to use this if you want multiple versions
            of your app to be able to run independently. If used, this
            would typically be "<major>.<minor>".
    
    Typical user data directories are:
        Windows:    C:/Documents and Settings/USER/Application 
Data/<owner>/<appname>
        Mac OS X:   ~/Library/Application Support/<appname>
        Unix:       ~/.config/<lowercased-appname>
    """
    if sys.platform.startswith("win"):
        # Try to make this a unicode path because SHGetFolderPath does
        # not return unicode strings when there is unicode data in the
        # path.
        if owner is None:
            raise Error("must specify 'owner' on Windows")
        path = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
        path = os.path.join(path, owner, appname)
    elif sys.platform == 'darwin':
        from Carbon import Folder, Folders
        path = Folder.FSFindFolder(Folders.kUserDomain,
                                   Folders.kApplicationSupportFolderType,
                                   Folders.kDontCreateFolder)
        path = os.path.join(path.FSRefMakePath(), appname)
    else:
        pass
    if version:
        path = os.path.join(path, version)
    return path


def site_data_dir(appname, owner=None, version=None):
    """Return full path to the user-shared data dir for this application.
    
        "appname" is the name of application.
        "owner" (only required and used on Windows) is the name of the
            owner or distributing body for this application. Typically
            it is the owning company name.
        "version" is an optional version path element to append to the
            path. You might want to use this if you want multiple versions
            of your app to be able to run independently. If used, this
            would typically be "<major>.<minor>".
    
    Typical user data directories are:
        Windows:    C:\Documents and Settings\All Users\Application 
Data\<owner>\<appname>
        Mac OS X:   /Library/Application Support/<appname>
        Unix:       /etc/<lowercased-appname>
    """
    if sys.platform.startswith("win"):
        # Try to make this a unicode path because SHGetFolderPath does
        # not return unicode strings when there is unicode data in the
        # path.
        if owner is None:
            raise Error("must specify 'owner' on Windows")
        from win32com.shell import shellcon, shell
        shellcon.CSIDL_COMMON_APPDATA = 0x23 # missing from shellcon
        path = shell.SHGetFolderPath(0, shellcon.CSIDL_COMMON_APPDATA, 0, 0)
        path = os.path.join(path, owner, appname)
    elif sys.platform == 'darwin':
        from Carbon import Folder, Folders
        path = Folder.FSFindFolder(Folders.kLocalDomain,
                                   Folders.kApplicationSupportFolderType,
                                   Folders.kDontCreateFolder)
        path = os.path.join(path.FSRefMakePath(), appname)
    else:
        path = "/etc/"+appname.lower()
    if version:
        path = os.path.join(path, version)
    return path


if __name__ == "__main__":
    print(("applib: user data dir:", user_data_dir("Komodo", "ActiveState")))
    print(("applib: site data dir:", site_data_dir("Komodo", "ActiveState")))

import sys
import glob
from cx_Freeze import setup, Executable
from os import sep
from os.path import join
base = None
if sys.platform == "win32":
    base = "Win32GUI"

include_files = []
includes = ["pythoncom", "win32com", "win32com.shell"]
excludes = []
packages = ["win32com.shell", "win32com"]

setup(name = "Hypernucleus", 
      version = "1.0", 
      description = "Hypernucleus Client - A Python Game Database", 
      author_email='rich...@gmail.com',
      url='http://hypernucleus.pynguins.com',
      executables = [Executable("test_win32com.py", base = base)],
      options = {'build_exe': {'excludes': excludes, 'packages': packages, 
                               'include_files': include_files,
                               'includes': includes}})
from find_path import user_data_dir
PROJNAME = "test_find_path"
datadir = user_data_dir(PROJNAME, owner=PROJNAME)
print(datadir)
input()
------------------------------------------------------------------------------
_______________________________________________
cx-freeze-users mailing list
cx-freeze-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cx-freeze-users

Reply via email to