How to pass all Visual Studio 2008 "Macros" to Python script? - python

[NOTE: This questions is similar to but not the same as this one.]
Visual Studio defines several dozen "Macros" which are sort of simulated environment variables (completely unrelated to C++ macros) which contain information about the build in progress. Examples:
ConfigurationName Release
TargetPath D:\work\foo\win\Release\foo.exe
VCInstallDir C:\ProgramFiles\Microsoft Visual Studio 9.0\VC\
Here is the complete set of 43 built-in Macros that I see (yours may differ depending on which version of VS you use and which tools you have enabled):
ConfigurationName IntDir RootNamespace TargetFileName
DevEnvDir OutDir SafeInputName TargetFramework
FrameworkDir ParentName SafeParentName TargetName
FrameworkSDKDir PlatformName SafeRootNamespace TargetPath
FrameworkVersion ProjectDir SolutionDir VCInstallDir
FxCopDir ProjectExt SolutionExt VSInstallDir
InputDir ProjectFileName SolutionFileName WebDeployPath
InputExt ProjectName SolutionName WebDeployRoot
InputFileName ProjectPath SolutionPath WindowsSdkDir
InputName References TargetDir WindowsSdkDirIA64
InputPath RemoteMachine TargetExt
Of these, only four (FrameworkDir, FrameworkSDKDir, VCInstallDir and VSInstallDir) are set in the environment used for build-events.
As Brian mentions, user-defined Macros can be defined such as to be set in the environment in which build tasks execute. My problem is with the built-in Macros.
I use a Visual Studio Post-Build Event to run a python script as part of my build process. I'd like to pass the entire set of Macros (built-in and user-defined) to my script in the environment but I don't know how. Within my script I can access regular environment variables (e.g., Path, SystemRoot) but NOT these "Macros". All I can do now is pass them on-by-one as named options which I then process within my script. For example, this is what my Post-Build Event command line looks like:
postbuild.py --t="$(TargetPath)" --c="$(ConfigurationName)"
Besides being a pain in the neck, there is a limit on the size of Post-Build Event command line so I can't pass dozens Macros using this method even if I wanted to because the command line is truncated.
Does anyone know if there is a way to pass the entire set of Macro names and values to a command that does NOT require switching to MSBuild (which I believe is not available for native VC++) or some other make-like build tool?

You might want to look into PropertySheets. These are files containing Visual C++ settings, including user macros. The sheets can inherit from other sheets and are attached to VC++ projects using the PropertyManager View in Visual Studio. When you create one of these sheets, there is an interface for creating user macros. When you add a macro using this mechanism, there is a checkbox for setting the user macro as an environment variable. We use this type of mechanism in our build system to rapidly set up projects to perform out-of-place builds. Our various build directories are all defined as user macros. I have not actually verified that the environment variables are set in an external script called from post-build. I tend to use these macros as command line arguments to my post-build scripts - but I would expect accessing them as environment variables should work for you.

This is a bit hacky, but it could work.
Why not call multiple .py scripts in a row?
Each scripts can pass in a small subset of the parameters, and the values to a temp text file. The final script will read and work off of the temp text file.
I agree that this method is filled with danger and WTF's, but sometimes you have to just hack stuff together.

As far as I can tell, the method described in the question is the only way to pass build variables to a Python script.
Perhaps Visual Studio 2010 has something better?

Related

When building python from source how to get rid of abs_srcdir & abs_builddir string in output files

I'm trying to build python from source and using the prefix option to control the target directory where it gets installed.
After successful installation, in some files in the target directory I see the entries of the working directory from where I actually built.
Example files which has entry for abs_srcdir & abs_builddir
lib/python3.9/_sysconfigdata__linux_x86_64-linux-gnu.py
lib/python3.9/config-3.9-x86_64-linux-gnu/Makefile
How can I avoid this?
I am a bit unfamiliar with the process in Python but I can tell that these are part of the Preset Output Variables
From docs:
Some output variables are preset by the Autoconf macros. Some of the Autoconf macros set additional output variables, which are mentioned in the descriptions for those macros. See Output Variable Index, for a complete list of output variables. See Installation Directory Variables, for the list of the preset ones related to installation directories. Below are listed the other preset ones, many of which are precious variables (see Setting Output Variables, AC_ARG_VAR).
You can see the variables you mentioned here - B.2 Output Variable Index. Since these are preset variables, I don't see how you can exclude them post-installation. Manually removing or creating some sort of a script seems like the only way you can solve this.
If this was done in GNU Make then you can use the filter-out text function

Execute GameFbxExporter Maya with Python

I need to export thousand of files with the GameFbXExporter Plugin from Maya, and I was wondering if there was any way to script those exports, knowing that the parameters are fine in every files. All I need to do is fill the path section and the name of the exported file in FBX, then launching the export itself with the plugin.
I'm kind of lost and doesn't know how to do this. Could someone help me understand how to reach that please?
Thank you
The game exporter is written in MEL, so you can interact with it from Python using the maya.mel module. This will open the dialog, for example:
import maya.mel as mel
mel.eval("gameFbxExporter();")
Unfortunately a quick look at the actual game exporter scripts (which are in your maya install directory in the scripts/others directory -- they all start with the prefix "gameFBX") make it look like the UI is hopelessly entangled with the actual act of exporting; it doesn't seem to expose anything which actually just exports the current file in a batch friendly way.
The operative procedure is called gameExp_FBXExport, defined in "gameFbxExporter.mel." It appears like the actual business of exporting is actually delegated to the regular FBX plugin -- all the other stuff in the game exporter is just managing fbx presets, selecting parts of the scene to export (if you have the scenes set that way) and then calling the fbx plugin. So, you may be able to batch the process using Python by looping over your files and calling FBXExport() from Python. This will export file to FBX:
import maya.cmds as cmds
cmds.FBXExport('-file', 'path/to/file.fbx')
It will just use whatever FBX settings are currently active, so you will need to be confident that the files are correctly set up. You'll be tempted to write it as cmds.FBXExport(f='path/to/file') but that won't work -- the FBX plugin commands don't use regular python syntax.
If your current settings rely on the export-selected functionality you'll need to figure out how to cache the correct selections -- if you're using the "export selections set" functionality you should be able to have your exporter find the set by name and the select it before exporting.
cmds.select("name_of_selection_set")
cmds.FBXExport('-file', 'path/to/file.fbx')
You can use the other FBX plugin commands -- documented here to inspect and manipulate the settings in your files as you go along.
Most professional users don't use the GameExport pipeline precisely because it's very opaque and not batch friendly. In the long run you'll probably want to write a simple system that provides standard settings for different file types and exports the FBXes directly without the GameExporter - while it's a not-trivial project it's going to be easier to maintain and expand than hacking your way around the edges of Autodesk's version which is, frankly, pretty lame.
If you're not already familiar with it http://tech-artists.org/ is a great place to look for pipeline help and advice.

Vim plugins don't always load?

I was trying to install autoclose.vim to Vim. I noticed I didn't have a ~/.vim/plugin folder, so I accidentally made a ~/.vim/plugins folder (notice the extra 's' in plugins). I then added au FileType python set rtp += ~/.vim/plugins to my .vimrc, because from what I've read, that will allow me to automatically source the scripts in that folder.
The plugin didn't load for me until I realized my mistake and took out the extra 's' from 'plugins'. I'm confused because this new path isn't even defined in my runtime path. I'm basically wondering why the plugin loaded when I had it in ~/.vim/plugin but not in ~/.vim/plugins?
:help load-plugins outlines how plugins are loaded.
Adding a folder to your rtp alone does not suffice; it must have a plugin subdirectory. For example, given :set rtp+=/tmp/foo, a file /tmp/foo/plugin/bar.vim would be detected and loaded, but neither /tmp/foo/plugins/bar.vim nor /tmp/foo/bar.vim would be.
You are on the right track with set rtp+=... but there's a bit more to it (rtp is non-recursive, help indexing, many corner cases) than what meets the eye so it is not a very good idea to do it by yourself. Unless you are ready for a months-long drop in productivity.
If you want to store all your plugins in a special directory you should use a proper runtimepath/plugin-management solution. I suggest Pathogen (rtp-manager) or Vundle (plugin-manager) but there are many others.
In addition to #Nikita Kouevda answer: modifying rtp on FileType event may be too late for vim to load any plugins from the modified runtimepath: if this event was launched after vimrc was sourced it is not guaranteed plugins from new addition will be loaded; if this event was launched after VimEnter event it is guaranteed plugins from new addition will not be sourced automatically.
If you want to source autoclose only when you edit python files you should use :au FileType python :source ~/.vim/macros/autoclose.vim (note: macros or any other subdirectory except plugin and directories found in $VIMRUNTIME or even any directory not found in runtimepath at all).
If you want to use autoclose only when you edit python files you should check out plugin source and documentation, there must be support on the plugin side for it to work.
// Or, if autoclose does not support this, use :au FileType command from above paragraph, but prepend source with something that records vim state (commands, mappings and autocommands), append same after source, find out differences in the state and delete the differences on each :au BufEnter if filetype is not python and restore them otherwise: hacky and may introduce strange bugs. The example of state-recording and diff-determining code may be found here.
All folders in the rtp (runtimepath) option need to have the same folder structure as your $VIMRUNTIME ($VIMRUNTIME is usually /usr/share/vim/vim{version}). So it should have the same subdirectory names e.g. autoload, doc, plugin (whichever you need, but having the same names is key). The plugins should be in their corresponding subdirectory.
Let's say you have /path/to/dir (in your case it's ~/.vim) is in your rtp, vim will
look for global plugins in /path/to/dir/plugin
look for file-type plugins in /path/to/dir/ftplugin
look for syntax files in /path/to/dir/syntax
look for help files in /path/to/dir/doc
and so on...
vim only looks for a couple of recognized subdirectories† in /path/to/dir. If you have some unrecognized subdirectory name in there (like /path/to/dir/plugins), vim won't see it.
† "recognized" here means that a subdirectory of the same name can be found in /usr/share/vim/vim{version} or wherever you have vim installed.

Trying to automate the fpga build process in Xilinx using python scripts

I want to automate the entire process of creating ngs,bit and mcs files in xilinx and have these files be automatically be associated with certain folders in the svn repository. What I need to know is that is there a log file that gets created in the back end of the Xilinx gui which records all the commands I run e.g open project,load file,synthesize etc.
Also the other part that I have not been able to find is a log file that records the entire process of synthesis, map,place and route and generate programming file. Specially record any errors that the tool encountered during these processes.
If any of you can point me to such files if they exist it would be great. I haven't gotten much out of my search but maybe I didn't look enough.
Thanks!
Well, it is definitely a nice project idea but a good amount of work. There's always a reason why an IDE was built – a simple search yields the "Command Line Tools User Guide" for various versions of Xilinx ISE, like for 14.3, 380 pages about
Overview and list of features
Input and output files
Command line syntax and options
Report and message information
ISE is a GUI for various command line executables, most of them are located in the subfolder 14.5/ISE_DS/ISE/bin/lin/ (in this case: Linux executables for version 14.5) of your ISE installation root. You can review your current parameters for each action by right clicking the item in the process tree and selecting "Process properties".
On the Python side, consider using the subprocess module:
The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes.
Is this the entry point you were looking for?
As phineas said, what you are trying to do is quite an undertaking.
I've been there done that, and there are countless challenges along the way. For example, if you want to move generated files to specific folders, how do you classify these files in order to figure out which files are which? I've created a project called X-MimeTypes that attempts to classify the files, but you then need a tool to parse the EDA mime type database and use that to determine which files are which.
However there is hope, so to answer the two main questions you've pointed out:
To be able to automatically move generated files to predetermined paths. From what you are saying it seems like you want to do this to make the versioning process easier? There is already a tool that does this for you based on "design structures" that you create and that can be shared within a team. The tool is called Scineric Workspace so check it out. It also have built in Git and SVN support which ignores things according to the design structure and in most cases it filters all generated things by vendor tools without you having to worry about it.
You are looking for a log file that shows all commands that were run. As phineas said, you can check out the Command Line Tools User guides for ISE, but be aware that the commands to run have changed again in Vivado. The log file of each process also usually states the exact command with its parameters that have been called. This should be close to the top of the report. If you look for one log file that contains everything, that does not exist. Again, Scineric Workspace supports evoking flows from major vendors (ISE, Vivado, Quartus) and it produces one log file for all processes together while still allowing each process to also create its own log file. Errors, warning etc. are also marked properly in this big report. Scineric has a tcl shell mode as well, so your python tool can run it in the background and parse the complete log file it creates.
If you have more questions on the above, I will be happy to help.
Hope this helps,
Jaco

Python MMTK "There is no program associated with ..pdb files, please install a suitable viewer"

I'm new to programming and computer world. I'm trying to study biomolecular simulations with MMTK.
I run it in Windows 7 and I have already installed this software:
python-2.5.4
numpy-1.6.2-win32-superpack-python2.5
netCDF4-0.8.2.win32-py2.5
ScientificPython-2.9.0.win32-py2.5
MMTK-2.6.0.win32-py2.5
pywin32-217.win32-py2.7
When I run this protein.py mmtk sample, all seems to be OK. It show the numbers of 1000 process steps.
But when I run a script with the view method, like this:
from MMTK import *
molecule = Molecule('water')
molecule.view()
Then I get this message:
There is no program associated with ..pdb files, please install a suitable viewer
After searching for some answers on the internet I got this information: "A viewer for PDB files can be defined by the environment variable PDBVIEWER. For showing a PDB file, MMTK will execute a command consisting of the value of this variable followed by a space and the name of the PDB file." And my doubt is: how define a viewer for PDB files by the environment variable PDBVIEWER? What would be the variable value?
This issue of the environment variables seems to me so simple as the mystery of life's emergence on Mars. I know how to change it, but I don't know what to change or when change it. Reading the Wikipedia articles on the subject didn't help me too much.
So what I'd like to know is: how exactly to modify the system variable in this case? I must add a new variable (PDBVIEWER) or just one more path to an existing variable? What is the value path to PDBVIEWER (should not it be C:\Windows\System32)?
This is my current variable value:
Variable's name:
Path
Variables's value:
C:\Program Files (x86)\PC Connectivity Solution\;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;%PYTHON_HOME%;%PYTHON_HOME%\Scripts;C:\Program Files (x86);C:\Python27\; C:\Python27\Scripts;C:\Python25\DLLs
I also have this Python variable: PYTHON_HOME with this variable's value: C:\Python27 (though I'm using Python25 with MMTK).
This question may seem trivial to an experienced programmer. But the answer to it can be very useful to others. There is a large number of biologists, biochemists and pharmacists interested in using computational methods to their problems. These professionals do not always have a computer scientist in the vicinity (especially if they are in an underdeveloped country).
Overcoming this initial frustrating phase of bugs and installation problems can be crucial in the scientific career of many people. And the answer to this question will help them.
Thanks in advance.
If this forum is not appropriate for questions of this level, please give me a feedback.
Install VMD, which is recommended by MMTK for visualization, and run
import os
os.environ['PDBVIEWER'] = 'C:/Program Files (x86)/University of Illinois/VMD/vmd.exe'
from MMTK import *
molecule = Molecule('water')
molecule.view()
Google says http://spdbv.vital-it.ch/ is a PDB viewer.
You need to install that or something else you find that can view PDB files. Assuming the installer for that doesn't just go set that environment variable for you (which it may), you'd then need to set the variable PDBVIEWER to be the path to an executable that can view PDBs presumably. So, say, C:\SwissPDBViewer\view.exe hypothetically speaking.

Categories