From 3b80de869af3ac92fad2eafbc81020974cf262e2 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Wed, 28 Dec 2011 14:51:33 -0500 Subject: [PATCH 1/5] Replaced objcmin with objp-based proxy. --HG-- branch : objp --- .hgignore | 1 + build.py | 18 ++++++++++++++++-- cocoa/inter/app.py | 14 ++++++-------- cocoa/inter/app_pe.py | 13 +++++-------- cocoa/inter/app_se.py | 9 ++++----- 5 files changed, 32 insertions(+), 23 deletions(-) diff --git a/.hgignore b/.hgignore index d3dba846..1569a994 100644 --- a/.hgignore +++ b/.hgignore @@ -6,6 +6,7 @@ run.py *.so *.mo *.pyd +.tm_* *.xcodeproj/xcuserdata *.xcodeproj/project.xcworkspace/xcuserdata conf.json diff --git a/build.py b/build.py index 11457162..85b5b4df 100644 --- a/build.py +++ b/build.py @@ -12,8 +12,7 @@ from optparse import OptionParser import shutil import json -from setuptools import setup -from distutils.extension import Extension +from setuptools import setup, Extension from hscommon import sphinxgen from hscommon.build import (add_to_pythonpath, print_and_do, copy_packages, filereplace, @@ -38,6 +37,7 @@ def parse_args(): def build_cocoa(edition, dev): from pluginbuilder import build_plugin + build_cocoa_proxy_module() print("Building dg_cocoa.plugin") if dev: tocopy = ['cocoa/inter'] @@ -162,6 +162,20 @@ def build_mergepot(): loc.merge_pots_into_pos('locale') loc.merge_pots_into_pos(op.join('hscommon', 'locale')) +def build_cocoa_proxy_module(): + print("Building Cocoa Proxy") + import objp.p2o + objp.p2o.generate_python_proxy_code('hscommon/cocoa/Cocoa.h', 'build/CocoaProxy.m') + exts = [ + Extension("CocoaProxy", ['hscommon/cocoa/Cocoa.m', 'build/CocoaProxy.m', 'build/ObjP.m'], + extra_link_args=["-framework", "CoreFoundation", "-framework", "Foundation", "-framework", "AppKit"]), + ] + setup( + script_args = ['build_ext', '--inplace'], + ext_modules = exts, + ) + move_all('CocoaProxy*', 'hscommon/cocoa') + def build_pe_modules(ui): print("Building PE Modules") exts = [ diff --git a/cocoa/inter/app.py b/cocoa/inter/app.py index 90add3ff..b5e598c5 100644 --- a/cocoa/inter/app.py +++ b/cocoa/inter/app.py @@ -2,10 +2,8 @@ import logging from jobprogress import job from hscommon import cocoa -from hscommon.cocoa import install_exception_hook +from hscommon.cocoa import install_exception_hook, proxy from hscommon.cocoa.inter import signature, subproxy, PyFairware -from hscommon.cocoa.objcmin import (NSNotificationCenter, NSSearchPathForDirectoriesInDomains, - NSApplicationSupportDirectory, NSUserDomainMask, NSWorkspace) from hscommon.trans import trget from core.app import JobType @@ -25,7 +23,7 @@ class PyDupeGuruBase(PyFairware): def _init(self, modelclass): logging.basicConfig(level=logging.WARNING, format='%(levelname)s %(message)s') install_exception_hook() - appdata = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, True)[0] + appdata = proxy.getAppdataPath() self.py = modelclass(self, appdata) self.progress = cocoa.ThreadedJobPerformer() @@ -166,10 +164,10 @@ class PyDupeGuruBase(PyFairware): #--- model --> view def open_path(self, path): - NSWorkspace.sharedWorkspace().openFile_(str(path)) + proxy.openPath_(str(path)) def reveal_path(self, path): - NSWorkspace.sharedWorkspace().selectFile_inFileViewerRootedAtPath_(str(path), '') + proxy.revealPath_(str(path)) def start_job(self, jobid, func, args=()): try: @@ -177,10 +175,10 @@ class PyDupeGuruBase(PyFairware): args = tuple([j] + list(args)) self.progress.run_threaded(func, args=args) except job.JobInProgressError: - NSNotificationCenter.defaultCenter().postNotificationName_object_('JobInProgress', self) + proxy.postNotification_userInfo_('JobInProgress', None) else: ud = {'desc': JOBID2TITLE[jobid], 'jobid':jobid} - NSNotificationCenter.defaultCenter().postNotificationName_object_userInfo_('JobStarted', self, ud) + proxy.postNotification_userInfo_('JobStarted', ud) def show_extra_fairware_reminder(self): self.cocoa.showExtraFairwareReminder() diff --git a/cocoa/inter/app_pe.py b/cocoa/inter/app_pe.py index 58671556..08098a1c 100644 --- a/cocoa/inter/app_pe.py +++ b/cocoa/inter/app_pe.py @@ -16,7 +16,7 @@ from appscript import app, its, CommandError, ApplicationNotFoundError from hscommon import io from hscommon.util import remove_invalid_xml from hscommon.path import Path -from hscommon.cocoa.objcmin import NSUserDefaults, NSURL +from hscommon.cocoa import proxy from hscommon.trans import tr from core import directories @@ -49,14 +49,11 @@ class IPhoto(Photo): return IPHOTO_PATH def get_iphoto_database_path(): - ud = NSUserDefaults.standardUserDefaults() - prefs = ud.persistentDomainForName_('com.apple.iApps') - if prefs is None: + plisturls = proxy.prefValue_inDomain_('iPhotoRecentDatabases', 'com.apple.iApps') + if not plisturls: raise directories.InvalidPathError() - if 'iPhotoRecentDatabases' not in prefs: - raise directories.InvalidPathError() - plisturl = NSURL.URLWithString_(prefs['iPhotoRecentDatabases'][0]) - return Path(plisturl.path()) + plistpath = proxy.url2path_(plisturls[0]) + return Path(plistpath) def get_iphoto_pictures(plistpath): if not io.exists(plistpath): diff --git a/cocoa/inter/app_se.py b/cocoa/inter/app_se.py index a7e8e568..4f0b6a72 100644 --- a/cocoa/inter/app_se.py +++ b/cocoa/inter/app_se.py @@ -11,18 +11,17 @@ import os.path as op from hscommon import io from hscommon.path import Path -from hscommon.cocoa.objcmin import NSWorkspace +from hscommon.cocoa import proxy from core import fs from core.directories import Directories as DirectoriesBase, DirectoryState from core_se.app import DupeGuru as DupeGuruBase def is_bundle(str_path): - sw = NSWorkspace.sharedWorkspace() - uti, error = sw.typeOfFile_error_(str_path, None) - if error is not None: + uti = proxy.getUTI_(str_path) + if uti is None: logging.warning('There was an error trying to detect the UTI of %s', str_path) - return sw.type_conformsToType_(uti, 'com.apple.bundle') or sw.type_conformsToType_(uti, 'com.apple.package') + return proxy.type_conformsToType_(uti, 'com.apple.bundle') or proxy.type_conformsToType_(uti, 'com.apple.package') class Bundle(fs.Folder): @classmethod From ceaf2ee4baa969a1cd65d8c85db04b6f73410f02 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Wed, 28 Dec 2011 15:04:42 -0500 Subject: [PATCH 2/5] Fixed bogus imports. --HG-- branch : objp --- cocoa/me/dg_cocoa.py | 2 +- cocoa/se/dg_cocoa.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cocoa/me/dg_cocoa.py b/cocoa/me/dg_cocoa.py index 079b7493..c8c6324e 100644 --- a/cocoa/me/dg_cocoa.py +++ b/cocoa/me/dg_cocoa.py @@ -7,7 +7,7 @@ from hscommon.trans import install_gettext_trans_under_cocoa install_gettext_trans_under_cocoa() -from hscommon.cocoa import signature +from hscommon.cocoa.inter import signature from core.scanner import ScanType diff --git a/cocoa/se/dg_cocoa.py b/cocoa/se/dg_cocoa.py index 0150a7a2..01a6efac 100644 --- a/cocoa/se/dg_cocoa.py +++ b/cocoa/se/dg_cocoa.py @@ -7,7 +7,7 @@ from hscommon.trans import install_gettext_trans_under_cocoa install_gettext_trans_under_cocoa() -from hscommon.cocoa import signature +from hscommon.cocoa.inter import signature from core.scanner import ScanType From 7ce72b1998e63d5a66b74c99f6394e650204d5e5 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Thu, 5 Jan 2012 14:12:52 -0500 Subject: [PATCH 3/5] Adapted build script to changes in hscommon's CocoaProxy and objp. --HG-- branch : objp --- build.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.py b/build.py index 85b5b4df..17295f12 100644 --- a/build.py +++ b/build.py @@ -165,9 +165,9 @@ def build_mergepot(): def build_cocoa_proxy_module(): print("Building Cocoa Proxy") import objp.p2o - objp.p2o.generate_python_proxy_code('hscommon/cocoa/Cocoa.h', 'build/CocoaProxy.m') + objp.p2o.generate_python_proxy_code('hscommon/cocoa/CocoaProxy.h', 'build/CocoaProxy.m') exts = [ - Extension("CocoaProxy", ['hscommon/cocoa/Cocoa.m', 'build/CocoaProxy.m', 'build/ObjP.m'], + Extension("CocoaProxy", ['hscommon/cocoa/CocoaProxy.m', 'build/CocoaProxy.m', 'build/ObjP.m'], extra_link_args=["-framework", "CoreFoundation", "-framework", "Foundation", "-framework", "AppKit"]), ] setup( From 01f1e5e46ea61b2aa8943083b9083bae14af8b50 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Thu, 5 Jan 2012 16:57:31 -0500 Subject: [PATCH 4/5] Moved hscommon.cocoa to cocoalib. --HG-- branch : objp --- build.py | 10 +++++----- cocoa/inter/app.py | 6 +++--- cocoa/inter/app_me.py | 2 +- cocoa/inter/app_pe.py | 2 +- cocoa/inter/app_se.py | 2 +- cocoa/inter/details_panel.py | 2 +- cocoa/inter/directory_outline.py | 2 +- cocoa/inter/extra_fairware_reminder.py | 2 +- cocoa/inter/prioritize_dialog.py | 2 +- cocoa/inter/prioritize_list.py | 2 +- cocoa/inter/problem_dialog.py | 2 +- cocoa/inter/problem_table.py | 2 +- cocoa/inter/result_table.py | 2 +- cocoa/inter/stats_label.py | 2 +- cocoa/me/dg_cocoa.py | 2 +- cocoa/se/dg_cocoa.py | 2 +- requirements-osx.txt | 3 ++- 17 files changed, 24 insertions(+), 23 deletions(-) diff --git a/build.py b/build.py index 17295f12..38eff9ff 100644 --- a/build.py +++ b/build.py @@ -40,14 +40,14 @@ def build_cocoa(edition, dev): build_cocoa_proxy_module() print("Building dg_cocoa.plugin") if dev: - tocopy = ['cocoa/inter'] + tocopy = ['cocoa/inter', 'cocoalib/cocoa'] else: specific_packages = { 'se': ['core_se'], 'me': ['core_me'], 'pe': ['core_pe'], }[edition] - tocopy = ['core', 'hscommon', 'cocoa/inter'] + specific_packages + tocopy = ['core', 'hscommon', 'cocoa/inter', 'cocoalib/cocoa'] + specific_packages copy_packages(tocopy, 'build') cocoa_project_path = 'cocoa/{0}'.format(edition) shutil.copy(op.join(cocoa_project_path, 'dg_cocoa.py'), 'build') @@ -165,16 +165,16 @@ def build_mergepot(): def build_cocoa_proxy_module(): print("Building Cocoa Proxy") import objp.p2o - objp.p2o.generate_python_proxy_code('hscommon/cocoa/CocoaProxy.h', 'build/CocoaProxy.m') + objp.p2o.generate_python_proxy_code('cocoalib/cocoa/CocoaProxy.h', 'build/CocoaProxy.m') exts = [ - Extension("CocoaProxy", ['hscommon/cocoa/CocoaProxy.m', 'build/CocoaProxy.m', 'build/ObjP.m'], + Extension("CocoaProxy", ['cocoalib/cocoa/CocoaProxy.m', 'build/CocoaProxy.m', 'build/ObjP.m'], extra_link_args=["-framework", "CoreFoundation", "-framework", "Foundation", "-framework", "AppKit"]), ] setup( script_args = ['build_ext', '--inplace'], ext_modules = exts, ) - move_all('CocoaProxy*', 'hscommon/cocoa') + move_all('CocoaProxy*', 'cocoalib/cocoa') def build_pe_modules(ui): print("Building PE Modules") diff --git a/cocoa/inter/app.py b/cocoa/inter/app.py index b5e598c5..f7472bc6 100644 --- a/cocoa/inter/app.py +++ b/cocoa/inter/app.py @@ -1,9 +1,9 @@ import logging from jobprogress import job -from hscommon import cocoa -from hscommon.cocoa import install_exception_hook, proxy -from hscommon.cocoa.inter import signature, subproxy, PyFairware +import cocoa +from cocoa import install_exception_hook, proxy +from cocoa.inter import signature, subproxy, PyFairware from hscommon.trans import trget from core.app import JobType diff --git a/cocoa/inter/app_me.py b/cocoa/inter/app_me.py index 3e73ee61..f22affb7 100644 --- a/cocoa/inter/app_me.py +++ b/cocoa/inter/app_me.py @@ -11,7 +11,7 @@ from appscript import app, k, CommandError import time import os.path as op -from hscommon.cocoa import as_fetch +from cocoa import as_fetch from hscommon.trans import tr from core.app import JobType diff --git a/cocoa/inter/app_pe.py b/cocoa/inter/app_pe.py index 08098a1c..51ce2c58 100644 --- a/cocoa/inter/app_pe.py +++ b/cocoa/inter/app_pe.py @@ -16,8 +16,8 @@ from appscript import app, its, CommandError, ApplicationNotFoundError from hscommon import io from hscommon.util import remove_invalid_xml from hscommon.path import Path -from hscommon.cocoa import proxy from hscommon.trans import tr +from cocoa import proxy from core import directories from core_pe import _block_osx diff --git a/cocoa/inter/app_se.py b/cocoa/inter/app_se.py index 4f0b6a72..c5779c2c 100644 --- a/cocoa/inter/app_se.py +++ b/cocoa/inter/app_se.py @@ -11,7 +11,7 @@ import os.path as op from hscommon import io from hscommon.path import Path -from hscommon.cocoa import proxy +from cocoa import proxy from core import fs from core.directories import Directories as DirectoriesBase, DirectoryState diff --git a/cocoa/inter/details_panel.py b/cocoa/inter/details_panel.py index e3cfbdb8..1afe4f92 100644 --- a/cocoa/inter/details_panel.py +++ b/cocoa/inter/details_panel.py @@ -1,4 +1,4 @@ -from hscommon.cocoa.inter import signature, PyGUIObject +from cocoa.inter import signature, PyGUIObject from core.gui.details_panel import DetailsPanel diff --git a/cocoa/inter/directory_outline.py b/cocoa/inter/directory_outline.py index 72d4921c..bdac6a5a 100644 --- a/cocoa/inter/directory_outline.py +++ b/cocoa/inter/directory_outline.py @@ -1,4 +1,4 @@ -from hscommon.cocoa.inter import PyOutline +from cocoa.inter import PyOutline from core.gui.directory_tree import DirectoryTree diff --git a/cocoa/inter/extra_fairware_reminder.py b/cocoa/inter/extra_fairware_reminder.py index e93533c7..97904b1d 100644 --- a/cocoa/inter/extra_fairware_reminder.py +++ b/cocoa/inter/extra_fairware_reminder.py @@ -1,4 +1,4 @@ -from hscommon.cocoa.inter import PyGUIObject +from cocoa.inter import PyGUIObject from core.gui.extra_fairware_reminder import ExtraFairwareReminder diff --git a/cocoa/inter/prioritize_dialog.py b/cocoa/inter/prioritize_dialog.py index 0d9852ac..76d140a5 100644 --- a/cocoa/inter/prioritize_dialog.py +++ b/cocoa/inter/prioritize_dialog.py @@ -1,4 +1,4 @@ -from hscommon.cocoa.inter import PyGUIObject, PySelectableList +from cocoa.inter import PyGUIObject, PySelectableList from core.gui.prioritize_dialog import PrioritizeDialog from .prioritize_list import PyPrioritizeList diff --git a/cocoa/inter/prioritize_list.py b/cocoa/inter/prioritize_list.py index d3d23d84..fd728ad0 100644 --- a/cocoa/inter/prioritize_list.py +++ b/cocoa/inter/prioritize_list.py @@ -1,4 +1,4 @@ -from hscommon.cocoa.inter import signature, PySelectableList +from cocoa.inter import signature, PySelectableList class PyPrioritizeList(PySelectableList): @signature('v@:@i') diff --git a/cocoa/inter/problem_dialog.py b/cocoa/inter/problem_dialog.py index e96992c5..5eb62364 100644 --- a/cocoa/inter/problem_dialog.py +++ b/cocoa/inter/problem_dialog.py @@ -1,4 +1,4 @@ -from hscommon.cocoa.inter import PyGUIObject +from cocoa.inter import PyGUIObject from core.gui.problem_dialog import ProblemDialog diff --git a/cocoa/inter/problem_table.py b/cocoa/inter/problem_table.py index ebff3c28..965e1a75 100644 --- a/cocoa/inter/problem_table.py +++ b/cocoa/inter/problem_table.py @@ -1,4 +1,4 @@ -from hscommon.cocoa.inter import PyTable +from cocoa.inter import PyTable from core.gui.problem_table import ProblemTable diff --git a/cocoa/inter/result_table.py b/cocoa/inter/result_table.py index 620b25e9..ece69101 100644 --- a/cocoa/inter/result_table.py +++ b/cocoa/inter/result_table.py @@ -1,4 +1,4 @@ -from hscommon.cocoa.inter import signature, PyTable +from cocoa.inter import signature, PyTable class PyResultTable(PyTable): @signature('c@:') diff --git a/cocoa/inter/stats_label.py b/cocoa/inter/stats_label.py index f1976e73..e9fc6905 100644 --- a/cocoa/inter/stats_label.py +++ b/cocoa/inter/stats_label.py @@ -1,4 +1,4 @@ -from hscommon.cocoa.inter import PyGUIObject +from cocoa.inter import PyGUIObject from core.gui.stats_label import StatsLabel diff --git a/cocoa/me/dg_cocoa.py b/cocoa/me/dg_cocoa.py index c8c6324e..200d5312 100644 --- a/cocoa/me/dg_cocoa.py +++ b/cocoa/me/dg_cocoa.py @@ -7,7 +7,7 @@ from hscommon.trans import install_gettext_trans_under_cocoa install_gettext_trans_under_cocoa() -from hscommon.cocoa.inter import signature +from cocoa.inter import signature from core.scanner import ScanType diff --git a/cocoa/se/dg_cocoa.py b/cocoa/se/dg_cocoa.py index 01a6efac..3f71c71a 100644 --- a/cocoa/se/dg_cocoa.py +++ b/cocoa/se/dg_cocoa.py @@ -7,7 +7,7 @@ from hscommon.trans import install_gettext_trans_under_cocoa install_gettext_trans_under_cocoa() -from hscommon.cocoa.inter import signature +from cocoa.inter import signature from core.scanner import ScanType diff --git a/requirements-osx.txt b/requirements-osx.txt index d6e23720..8e84104c 100644 --- a/requirements-osx.txt +++ b/requirements-osx.txt @@ -1,4 +1,5 @@ -r requirements.txt pyobjc-core>=2.3 pluginbuilder>=1.0.0 -appscript>=1.0.0 \ No newline at end of file +appscript>=1.0.0 +objp>=0.1.0 \ No newline at end of file From f636333938112e1cdfe102e71f0a54e289e217ca Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Thu, 5 Jan 2012 17:08:56 -0500 Subject: [PATCH 5/5] Simplified the dev cocoa build process. --HG-- branch : objp --- build.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/build.py b/build.py index 38eff9ff..908bd2fa 100644 --- a/build.py +++ b/build.py @@ -39,16 +39,13 @@ def build_cocoa(edition, dev): from pluginbuilder import build_plugin build_cocoa_proxy_module() print("Building dg_cocoa.plugin") - if dev: - tocopy = ['cocoa/inter', 'cocoalib/cocoa'] - else: - specific_packages = { - 'se': ['core_se'], - 'me': ['core_me'], - 'pe': ['core_pe'], - }[edition] - tocopy = ['core', 'hscommon', 'cocoa/inter', 'cocoalib/cocoa'] + specific_packages - copy_packages(tocopy, 'build') + specific_packages = { + 'se': ['core_se'], + 'me': ['core_me'], + 'pe': ['core_pe'], + }[edition] + tocopy = ['core', 'hscommon', 'cocoa/inter', 'cocoalib/cocoa'] + specific_packages + copy_packages(tocopy, 'build', create_links=dev) cocoa_project_path = 'cocoa/{0}'.format(edition) shutil.copy(op.join(cocoa_project_path, 'dg_cocoa.py'), 'build') os.chdir('build') @@ -59,11 +56,6 @@ def build_cocoa(edition, dev): if op.exists(pluginpath): shutil.rmtree(pluginpath) shutil.move('build/dist/dg_cocoa.plugin', pluginpath) - if dev: - # In alias mode, the tweakings we do to the pythonpath aren't counted in. We have to - # manually put a .pth in the plugin - pthpath = op.join(pluginpath, 'Contents/Resources/dev.pth') - open(pthpath, 'w').write(op.abspath('.')) os.chdir(cocoa_project_path) print('Generating Info.plist') app_version = get_module_version('core_{}'.format(edition))