From 14ba868df4ca9b62bb99499532271109c2e4c998 Mon Sep 17 00:00:00 2001 From: Andy Kittner Date: Mon, 27 Aug 2012 20:24:41 +0200 Subject: [PATCH 1/5] Treat openslides the same way as other packages OpenSlides will now be copied from (and to) site-packages in the same way as it's dependencies --- extras/win32-portable/prepare_portable.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/extras/win32-portable/prepare_portable.py b/extras/win32-portable/prepare_portable.py index 574a4cfba..04c1e0cc7 100644 --- a/extras/win32-portable/prepare_portable.py +++ b/extras/win32-portable/prepare_portable.py @@ -45,10 +45,6 @@ LIBEXCLUDE = [ r"^unittest/", ] -OPENSLIDES_EXCLUDE = [ - r"^openslides/settings.py" -] - SITE_PACKAGES = { "django": { @@ -84,7 +80,10 @@ SITE_PACKAGES = { "pil": { # NOTE: PIL is a special case, see copy_pil "copy": [], - } + }, + "openslides": { + "copy" : ["openslides"], + }, } PY_DLLS = [ @@ -302,9 +301,6 @@ def main(): collect_lib(libdir, odir) collect_site_packages(sitedir, os.path.join(odir, "site-packages")) - exclude = get_pkg_exclude("openslides", OPENSLIDES_EXCLUDE) - copy_dir_exclude(exclude, ".", "openslides", odir) - if not compile_openslides_launcher(): sys.stdout.write("Using prebuild openslides.exe\n") From cc20ec345618fae0a195e11a4017b434e4315e8f Mon Sep 17 00:00:00 2001 From: Andy Kittner Date: Mon, 27 Aug 2012 21:48:46 +0200 Subject: [PATCH 2/5] Add special handling to determine default settings for portable version The portable version will prefer to create it's settings in it's own directory and only fallback to a user-specific path ($LOCAL_APPDATA/openslides) if this directory is not writable --- extras/win32-portable/openslides.c | 2 +- openslides/main.py | 46 +++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/extras/win32-portable/openslides.c b/extras/win32-portable/openslides.c index 997baf123..6df2f8e7f 100644 --- a/extras/win32-portable/openslides.c +++ b/extras/win32-portable/openslides.c @@ -23,7 +23,7 @@ static const char *site_code = static const char *run_openslides_code = "import openslides.main;" - "openslides.main.main()"; + "openslides.main.win32_portable_main()"; /* determine the path to the executable * NOTE: Py_GetFullProgramPath() can't be used because diff --git a/openslides/main.py b/openslides/main.py index 6764ea859..dde97b165 100644 --- a/openslides/main.py +++ b/openslides/main.py @@ -72,7 +72,7 @@ def _fs2unicode(s): return s.decode(_fs_encoding) -def main(argv=None): +def main(argv=None, opt_defaults = None): if argv is None: argv = sys.argv[1:] @@ -90,6 +90,9 @@ def main(argv=None): parser.add_option( "--no-reload", action="store_true", help="Do not reload the development server") + if not opt_defaults is None: + parser.set_defaults(**opt_defaults) + opts, args = parser.parse_args(argv) if args: sys.stderr.write("This command does not take arguments!\n\n") @@ -249,6 +252,47 @@ def start_browser(url): t = threading.Thread(target=f) t.start() +def win32_portable_main(argv=None): + """special entry point for the win32 portable version""" + import tempfile + + # NOTE: sys.executable will be the path to openslides.exe + # since it is essentially a small wrapper that embeds the + # python interpreter + portable_dir = os.path.dirname(os.path.abspath(sys.executable)) + try: + fd, test_file = tempfile.mkstemp(dir = portable_dir) + except OSError: + portable_dir_writeable = False + else: + portable_dir_writeable = True + os.close(fd) + os.unlink(test_file) + + if portable_dir_writeable: + default_settings = os.path.join(portable_dir, "openslides", + "openslides_personal_settings.py") + else: + import ctypes + + shell32 = ctypes.WinDLL("shell32.dll") + SHGetFolderPath = shell32.SHGetFolderPathW + SHGetFolderPath.argtypes = (ctypes.c_void_p, ctypes.c_int, + ctypes.c_void_p, ctypes.c_uint32, ctypes.c_wchar_p) + SHGetFolderPath.restype = ctypes.c_uint32 + + CSIDL_LOCAL_APPDATA = 0x001c + MAX_PATH = 260 + + buf = ctypes.create_unicode_buffer(MAX_PATH) + res = SHGetFolderPath(0, CSIDL_LOCAL_APPDATA, 0, 0, buf) + if res != 0: + raise Exception("Could not deterime APPDATA path") + default_settings = os.path.join(buf.value, "openslides", + "openslides_personal_settings.py") + + main(argv, opt_defaults = { "settings": default_settings }) + if __name__ == "__main__": main() From 7f6f7a934033028852b2a3e6b32e15bb47b2f2ee Mon Sep 17 00:00:00 2001 From: Andy Kittner Date: Mon, 27 Aug 2012 21:49:05 +0200 Subject: [PATCH 3/5] Rebuild openslides.exe --- extras/win32-portable/openslides.exe | Bin 7168 -> 7168 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/extras/win32-portable/openslides.exe b/extras/win32-portable/openslides.exe index 55a24e895183383f158097748d77212bdbc8976e..3e86e8909b2b4399cd9b6e4236a3c85da42a412a 100644 GIT binary patch delta 763 zcmW+zUuaTM96m?y)$6~4*cDfpB1Oe?*wzKbSw19;C~z2+P_0D^XKO_$J?vqE37JN= z1F;7mcDV(6*n{8(5%{0tP8HC^do_x`rakF^*J1F3kK0?KN z>PgH?N=L;NP|ffF2B};oF8!k@Yoy{l4RTo06@hDkjYyb(3KOYSXEVB zRq|~nka7rp-3Uggy9WP|3BDw4{V;w({^-+qKo*5jv%0C33wNm0C!2!jh?+>X*?SBr z{Yp=`gmHm*joW~KjZ=WvOqT(dO)gv{o2FZa0v!3fm6M9ZYIZ@zZys6tItHdJI}F7w zhV}+Ssm?H11AJHzyDC}sRkBxA;x|+}T~^7n4pe%>w}J9ur0lB9DSN=L!-CRbI@=yl z+T@)OWB6n!`k)nDHTf+-1BdEOeg`7B2qZJRx$GXy$VD~WhY(&BZcMR}6BZ}7RVFMo zY+$o&=_Glp3E)B{c=Vm#`h0F-d~EvZlV{19`}4EYk7wo<&YnY+Z&nAc2)4fVKaD>P AvH$=8 delta 751 zcmW+zOK1~O6n!t5NhUun(kWJrDM9hmq{PoaLK@AYfg*}20X3kYpc3O}m4MJd10i6V zik~OaMHU&RLKa;V(n63dvIs^*&_xLavzSE|BkiIKMbYB(-eKUJd+xiR^WGH0#c-Vp zMs4vb6X<2@X*Xpl`qT15XkM~}EL3On!UcMSy%&532BA2~k~!Wlb)|AAXV1*AZDBFA zdL~YK!m%0GUik?QuWM2ZH00L6<5#~SJ0R-{g3lf*R9n-M7(d<7u$&d#^=6)0?yl$T)u5? zLN9q6mzP2H5_{0d)jIRrAEvO7%a0(R~dw zy@`To1GJx{gcuFDLn-!@>GpA&V}I;Ly2IwBDYrSPUr7wPVz3Pc=xA?GK+zs@Q|H^8*}^NB;uZ2=$r*po;IS~LiDa9 zDr<a lLuc75OOzIxvHfrDw#RoKJUMx)`F+esS)GnFrGvk%{{i?t2V(#L From ce87353cd43c6fa8b69e0a0308f75f6138c120eb Mon Sep 17 00:00:00 2001 From: Andy Kittner Date: Mon, 27 Aug 2012 21:54:12 +0200 Subject: [PATCH 4/5] Update instructions for building the portable --- extras/win32-portable/create_portable.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/extras/win32-portable/create_portable.txt b/extras/win32-portable/create_portable.txt index 9818f6ec9..6770efd3f 100644 --- a/extras/win32-portable/create_portable.txt +++ b/extras/win32-portable/create_portable.txt @@ -6,11 +6,15 @@ How to create a new portable Windows distribution of OpenSlides: easy_install -Z django django-mptt reportlab pil -2.) In the main directory of the OpenSlides checkout execute: +2.) Install OpenSlides by running python setup.py install in the top directory + of OpenSlides. + NOTE: This step must be repeated whenever you make changes to OpenSlides + +3.) In the main directory of the OpenSlides checkout execute: python extras/win32-portable/prepare_portable.py -3.) The portable OpenSlides distribution is now ready as a zip in the +4.) The portable OpenSlides distribution is now ready as a zip in the 'dist/' directory Note: Creating the portable Windows distribution of OpenSlides is not possible, From 1b650442237be023d620426ab80ed0d10c6c3ab1 Mon Sep 17 00:00:00 2001 From: Andy Kittner Date: Tue, 28 Aug 2012 19:07:40 +0200 Subject: [PATCH 5/5] Remove a few spaces for pep8 conformance --- openslides/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openslides/main.py b/openslides/main.py index dde97b165..17d682eb8 100644 --- a/openslides/main.py +++ b/openslides/main.py @@ -72,7 +72,7 @@ def _fs2unicode(s): return s.decode(_fs_encoding) -def main(argv=None, opt_defaults = None): +def main(argv=None, opt_defaults=None): if argv is None: argv = sys.argv[1:] @@ -261,7 +261,7 @@ def win32_portable_main(argv=None): # python interpreter portable_dir = os.path.dirname(os.path.abspath(sys.executable)) try: - fd, test_file = tempfile.mkstemp(dir = portable_dir) + fd, test_file = tempfile.mkstemp(dir=portable_dir) except OSError: portable_dir_writeable = False else: @@ -291,7 +291,7 @@ def win32_portable_main(argv=None): default_settings = os.path.join(buf.value, "openslides", "openslides_personal_settings.py") - main(argv, opt_defaults = { "settings": default_settings }) + main(argv, opt_defaults={ "settings": default_settings }) if __name__ == "__main__":