Can I create a single exe with custom modules files and other files? - python-2.7

Now I'm developing a medium proj with python.
It has many modules and some of them are customize modules. And some of them are non-python files(may be config files), are need to use such as copy/paste (e.g when the client run this app and plug some the hw device, the app will config the hw device and copy the some file of app to hw device (may be ROM))
first my question is : can I create 1 single exe with all of my code, modules and non-python files?
if it is yes, how can I?

you could try changing your approach and putting all the files in the module as text.
then you could use the py2exe to create executable and it would contain all the data you need. this approach makes sense only if you have some small files.
if you want to embed more and bigger files take a look at that solution:
Py2exe: Embed static files in exe file itself and access them

open CMD
Change path to PyInstaller directory.(ex-C:\PyInstaller-2.1)
use this command
pyinstaller.py my.py --noconsole --onefile --icon=icon.ico
change my.py to your script name.
--noconsole option remove the python console while executing your program. If you need console to get an output,just remove --noconsole
--onefile option makes all the modules and files in to one executable file.
--icon=icon.ico gives your exe an icon.Remember to put your icon file in Pyinstaller directory

Related

How to write a file in to an OS X app Resources folder?

I have an xcode project, the used language is C++. while my program is running writes a txt file in to
My App.app/Contents/Resources/
folder using fstream. After a month pause don't work anymore. Nothing is modified on the project but the OS X is updated. The file path is ok, i can read the file. What is wrong?
You should not write into your app bundle, and instead use one of the following folders to store files, which can be obtained using NSSearchPathForDirectoriesInDomains:
Document folder (NSDocumentDirectory).
Application Support folder (NSApplicationSupportDirectory).
Caches folder (NSCachesDirectory).
If you write to your app bundle you will cause issues with the code signing of the app and might not even have write access, if it's installed in the default location (/Applications).

Run a jar Rhapsody app file

I have created some Java applications to extend Rhapsody using Java API and I have deployed them successfully to the Rhapsody environment (Right click on the project -> Apps).
I can see the exported .jar files under the directory RhapsodyApps/apps.
My question is, How can I run them from the command line (Under windows 7)???
Thank you in advance
What I managed to do is to create a .bat file, using "Generate Apps Execution Batch File". As I mentioned in my last post it did not exist in the "Apps" menu of rhapsody. Besides, it existed in the "...\share\RhapsodyApps\apps" directory with the name "SynchronousScriptInvocation.jar". I hardcoded the RhapsodyApps.hep file, by adding the following:
#REM: This app generates a script which will invoke each app synchronously one after another. ...
name7=Apps\Generate Apps Execution Batch File
isPluginCommand7=1
command7=Apps
applicableTo7=Project,SysML,AUTOSAR_40,AUTOSAR_31,AUTOSAR_32,DDS,UPDM1_DoDAF20,UPDM2_DoDAF
isVisible7=1
I got the name (Generate Apps Execution Batch File) from the AppInfos.xml file.
Then, the plugin is displayed in the Apps menu in Rhapsody IDE, and I can generate the .bat file. Problems did not stop here. The batch file was not displaying my plugin and the reason was something with my JAVA_PATH configuration. Finally I modified the .bat file as following:
#rem This is auto generated script. Be careful on changing it manually.
#rem Build Order
set APP0=0df8829923eb43f4aab9d33ada1ddbf1
#set APPS= %APP0%
set JAVA_PATH=%JAVA_PATH%\bin\java
set JAVA_API=C:/work/User/Build.TRUNK/ProjectName/RhapsodyShare8/JavaAPI
set RhapsodyApps=C:/work/User/Build.TRUNK/ProjectName/RhapsodyShare8/RhapsodyApps
set CLASS_PATH="%RhapsodyApps%"/apps/RhapsodyAppLauncher.jar;"%RhapsodyApps%"/RhapsodyApps.jar;"%RhapsodyApps%"/apps.jar;"%JAVA_API%"/rhapsody.jar
"C:\Program Files (x86)\IBM\Rational\Rhapsody\8.0.5\jre\bin\java" -cp %CLASS_PATH% -Djava.library.path="%JAVA_API%" apps.RhapsodyLauncherApp %APPS%
Finally it works. I hope that this post will help somebody in the future.

Where to start for writing a shell script for copying elements into main app xcode4

I am looking for some documentation or tutorial for copying files from a given directory into the app created by xcode at build time, before it is run.
At first I have tried to copy files into the derived directory, hoping that everything resides in there would be automatically added to the app, but I was wrong.
So I am looking for a script because the original dir may change its name, second the script could be customized by another xcode 4 user with its src dir path etc.
The things is I don't know how to start, which language etc. I am quite confident with shell script, but maybe there's a better option.
Second, I am trying to figure out which command could add a file in the already built app.
thanks
That answer didn't really help - the BUILT_PRODUCT_DIR isn't where most stuff goes.
Ultimately, I found you just need to do:
Add the following to the very end of your script (or get your script to write directly to the output location):
cp ${DERIVED_FILE_DIR}/[YOUR OUTPUT FILES] ${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}
...but there's a lot of other things I tried. More thoughts and ideas here: http://red-glasses.com/index.php/tutorials/xcode4-a-script-that-creates-adds-files-to-your-project/
You want a Run Script or Copy Files build phase. Select your main project in the navigator, then select the app's target. Click the Build Phases tab. Click the Add Build Phase button at the bottom of the window and choose the appropriate phase.
By "appropriate" I mean if you really want to run a script, you'll use a Run Script build phase and use Xcode-provided environment variables like $BUILT_PRODUCT_DIR (see the documentation or hit build and examine the full output of an empty script in the build log) to figure out your target folder. If all you want to do is copy files (no real processing), the Copy Files build phase already knows how to locate the app bundle's proper folders depending on what you're copying (Resources, Frameworks, etc.).

Embedding Lua: how to programatically save a script to a folder, how to compile a script?

I am embedding Lua in a C++ application, and I am using luaL_dofile to load a script
However, I cannot seem to find documentation on the functions to use to:
Compile a script (and save byte stream to a specified folder)
Save a script to a specified folder
last but not the least, when I use luaL_dofile to load a script into the Lua engine, if the loaded script has a line that loads a module for example:
require 'strict'
which directory would the script.lua (or its compiled version) be loaded from?
Look up luaL_loadfile and lua_dump. See also test/luac.lua.
For the question about where Lua looks for modules require'd: It depends on package.path and package.cpath variables, which can be influenced by the environment variables LUA_PATH and LUA_CPATH.

Relative path problem for a deployed win32 application

I have written a c++ program and deployed it in say c:\my_app, and my executable's path is c:\my_app\my_app.exe. Say, my_app needs many files such as the_file.txt, which is located in c:\my_app\the_file.txt.
In my executable, I open the txt file as, xx.open("the_file.txt");
Moreover, I have associated my program with let's say .myp extension.
When I'm on Desktop, and want to open a file named example.myp, my program can not see the_file.txt. Because, it (somehow) assumes that it's currently working on Desktop.
Is there any easy way to handle this problem by changing shell command for open in HKEY_CLASSES_ROOT? The naive solution would be to change all file open operations with something like %my_app_location/the_file.txt". I don't want to do that.
Always use a full path name to open a file. In other words, don't open "foo.txt", open "c:\bar\foo.txt". To find the install directory of your EXE use GetModuleFileName(), passing NULL for the module handle.
These days you shouldn't add files to c:\my_app....
Instead use the ProgramData Folder and full paths.
Use SHGetSpecialFolderPathA with CSIDL_COMMON_APPDATA to get the ProgramData folder and the create your program directory and add your files.
You should set current directory for your app's folder with SetCurrentDirectory function. After that you can open file by name without full path