Executing a file of some other directory from the PWD
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
If the executable is python and the script is scons.py and it resides in the scons directory, then what you are doing is correct. But if the script resides in the python scons directory, then you need to say:
Code:
../../python\ scons/scons.py
That way bash knows that python scons is the directory where the script lives.
If the executable is python and the script is scons.py and it resides in the scons directory, then what you are doing is correct. But if the script resides in the python scons directory, then you need to say
scons is a directory and it contains scons.py, as seen below:
Code:
anisha@linux:~/downloads/mapnik-0.6.1/scons> ls
sconsign.py scons-LICENSE scons-local-1.2.0 scons.py scons-README scons-time.py
Now see the following results:
Code:
anisha@linux:~/downloads/mapnik-0.6.1> python scons/scons.py
scons: Reading SConscript files ...
Welcome to Mapnik...
Using previous successful configuration...
Re-configure by running "python scons/scons.py configure".
Now I navigate to 2 directories ahead as follows and tried to execute the script in following 2 ways, and see it results in errors
Code:
anisha@linux:~/downloads/mapnik-0.6.1> cd demo/c++/
anisha@linux:~/downloads/mapnik-0.6.1/demo/c++> python ../../scons/scons.py
scons: *** No SConstruct file found.
File "/home/anisha/downloads/mapnik-0.6.1/scons/scons-local-1.2.0/SCons/Script/Main.py", line 826, in _main
Code:
anisha@linux:~/downloads/mapnik-0.6.1/demo/c++> ../../python scons/scons.py
bash: ../../python: No such file or directory
Last edited by Aquarius_Girl; 01-14-2010 at 10:26 PM.
As I noted before, the "python" command always needs to come first. Thus, the last example in post #6 does not make sense. (It tries to go up 2 levels and run a file named "python")
In the other example it appears that the program runs but cannot find the file named in the error message. That one is stumping me--it would seem that a program would look for files in the same place--regardless of how it was called.
I suggest you post the portion of the code that is trying to access "SConstruct".
Language:
Many of us do not like to see the texting shorthand---to me, it simply comes across as sloppy and lazy. In the extreme, if every few words is in shorthand, we tend to treat it as a rules violation.
From another perspective, if you are learning any new language, I think you have a responsibility to learn it correctly. I am appalled at anyone who thinks they know English as soon as they are able (with their thumbs) type: "C u l8tr".
I suggest you post the portion of the code that is trying to access "SConstruct".
Thanks for guiding !
As from the error output it is clear that Main.py residing in the following directory /home/anisha/downloads/mapnik-0.6.1/scons/scons-local-1.2.0/SCons/Script is using SConstruct file.
I don't know how to attach the Main.py file here. Its code is too lengthy to be posted here !
Last edited by Aquarius_Girl; 01-15-2010 at 11:33 PM.
I have posted this function from Main.py !
I hope you can make some sense out of it :
Code:
def _main(parser):
global exit_status
global this_build_status
options = parser.values
# Here's where everything really happens.
# First order of business: set up default warnings and then
# handle the user's warning options, so that we can issue (or
# suppress) appropriate warnings about anything that might happen,
# as configured by the user.
default_warnings = [ SCons.Warnings.CorruptSConsignWarning,
SCons.Warnings.DeprecatedWarning,
SCons.Warnings.DuplicateEnvironmentWarning,
SCons.Warnings.FutureReservedVariableWarning,
SCons.Warnings.LinkWarning,
SCons.Warnings.MissingSConscriptWarning,
SCons.Warnings.NoMD5ModuleWarning,
SCons.Warnings.NoMetaclassSupportWarning,
SCons.Warnings.NoObjectCountWarning,
SCons.Warnings.NoParallelSupportWarning,
SCons.Warnings.MisleadingKeywordsWarning,
SCons.Warnings.ReservedVariableWarning,
SCons.Warnings.StackSizeWarning,
]
for warning in default_warnings:
SCons.Warnings.enableWarningClass(warning)
SCons.Warnings._warningOut = _scons_internal_warning
SCons.Warnings.process_warn_strings(options.warn)
# Now that we have the warnings configuration set up, we can actually
# issue (or suppress) any warnings about warning-worthy things that
# occurred while the command-line options were getting parsed.
try:
dw = options.delayed_warnings
except AttributeError:
pass
else:
delayed_warnings.extend(dw)
for warning_type, message in delayed_warnings:
SCons.Warnings.warn(warning_type, message)
if options.diskcheck:
SCons.Node.FS.set_diskcheck(options.diskcheck)
# Next, we want to create the FS object that represents the outside
# world's file system, as that's central to a lot of initialization.
# To do this, however, we need to be in the directory from which we
# want to start everything, which means first handling any relevant
# options that might cause us to chdir somewhere (-C, -D, -U, -u).
if options.directory:
cdir = _create_path(options.directory)
try:
os.chdir(cdir)
except OSError:
sys.stderr.write("Could not change directory to %s\n" % cdir)
target_top = None
if options.climb_up:
target_top = '.' # directory to prepend to targets
script_dir = os.getcwd() # location of script
while script_dir and not _SConstruct_exists(script_dir,
options.repository,
options.file):
script_dir, last_part = os.path.split(script_dir)
if last_part:
target_top = os.path.join(last_part, target_top)
else:
script_dir = ''
if script_dir and script_dir != os.getcwd():
display("scons: Entering directory `%s'" % script_dir)
os.chdir(script_dir)
# Now that we're in the top-level SConstruct directory, go ahead
# and initialize the FS object that represents the file system,
# and make it the build engine default.
fs = SCons.Node.FS.get_default_fs()
for rep in options.repository:
fs.Repository(rep)
# Now that we have the FS object, the next order of business is to
# check for an SConstruct file (or other specified config file).
# If there isn't one, we can bail before doing any more work.
scripts = []
if options.file:
scripts.extend(options.file)
if not scripts:
sfile = _SConstruct_exists(repositories=options.repository,
filelist=options.file)
if sfile:
scripts.append(sfile)
if not scripts:
if options.help:
# There's no SConstruct, but they specified -h.
# Give them the options usage now, before we fail
# trying to read a non-existent SConstruct file.
raise SConsPrintHelpException
raise SCons.Errors.UserError, "No SConstruct file found."
if scripts[0] == "-":
d = fs.getcwd()
else:
d = fs.File(scripts[0]).dir
fs.set_SConstruct_dir(d)
_set_debug_values(options)
SCons.Node.implicit_cache = options.implicit_cache
SCons.Node.implicit_deps_changed = options.implicit_deps_changed
SCons.Node.implicit_deps_unchanged = options.implicit_deps_unchanged
if options.no_exec:
SCons.SConf.dryrun = 1
SCons.Action.execute_actions = None
if options.question:
SCons.SConf.dryrun = 1
if options.clean:
SCons.SConf.SetBuildType('clean')
if options.help:
SCons.SConf.SetBuildType('help')
SCons.SConf.SetCacheMode(options.config)
SCons.SConf.SetProgressDisplay(progress_display)
if options.no_progress or options.silent:
progress_display.set_mode(0)
if options.site_dir:
_load_site_scons_dir(d, options.site_dir)
elif not options.no_site_dir:
_load_site_scons_dir(d)
if options.include_dir:
sys.path = options.include_dir + sys.path
# That should cover (most of) the options. Next, set up the variables
# that hold command-line arguments, so the SConscript files that we
# read and execute have access to them.
targets = []
xmit_args = []
for a in parser.largs:
if a[0] == '-':
continue
if '=' in a:
xmit_args.append(a)
else:
targets.append(a)
SCons.Script._Add_Targets(targets + parser.rargs)
SCons.Script._Add_Arguments(xmit_args)
# If stdout is not a tty, replace it with a wrapper object to call flush
# after every write.
#
# Tty devices automatically flush after every newline, so the replacement
# isn't necessary. Furthermore, if we replace sys.stdout, the readline
# module will no longer work. This affects the behavior during
# --interactive mode. --interactive should only be used when stdin and
# stdout refer to a tty.
if not sys.stdout.isatty():
sys.stdout = SCons.Util.Unbuffered(sys.stdout)
if not sys.stderr.isatty():
sys.stderr = SCons.Util.Unbuffered(sys.stderr)
memory_stats.append('before reading SConscript files:')
count_stats.append(('pre-', 'read'))
# And here's where we (finally) read the SConscript files.
progress_display("scons: Reading SConscript files ...")
start_time = time.time()
try:
for script in scripts:
SCons.Script._SConscript._SConscript(fs, script)
except SCons.Errors.StopError, e:
# We had problems reading an SConscript file, such as it
# couldn't be copied in to the VariantDir. Since we're just
# reading SConscript files and haven't started building
# things yet, stop regardless of whether they used -i or -k
# or anything else.
sys.stderr.write("scons: *** %s Stop.\n" % e)
exit_status = 2
sys.exit(exit_status)
global sconscript_time
sconscript_time = time.time() - start_time
progress_display("scons: done reading SConscript files.")
memory_stats.append('after reading SConscript files:')
count_stats.append(('post-', 'read'))
# Re-{enable,disable} warnings in case they disabled some in
# the SConscript file.
#
# We delay enabling the PythonVersionWarning class until here so that,
# if they explicity disabled it in either in the command line or in
# $SCONSFLAGS, or in the SConscript file, then the search through
# the list of deprecated warning classes will find that disabling
# first and not issue the warning.
SCons.Warnings.enableWarningClass(SCons.Warnings.PythonVersionWarning)
SCons.Warnings.process_warn_strings(options.warn)
# Now that we've read the SConscript files, we can check for the
# warning about deprecated Python versions--delayed until here
# in case they disabled the warning in the SConscript files.
if python_version_deprecated():
msg = "Support for pre-2.2 Python (%s) is deprecated.\n" + \
" If this will cause hardship, contact dev@scons.tigris.org."
SCons.Warnings.warn(SCons.Warnings.PythonVersionWarning,
msg % python_version_string())
if not options.help:
SCons.SConf.CreateConfigHBuilder(SCons.Defaults.DefaultEnvironment())
# Now re-parse the command-line options (any to the left of a '--'
# argument, that is) with any user-defined command-line options that
# the SConscript files may have added to the parser object. This will
# emit the appropriate error message and exit if any unknown option
# was specified on the command line.
parser.preserve_unknown_options = False
parser.parse_args(parser.largs, options)
if options.help:
help_text = SCons.Script.help_text
if help_text is None:
# They specified -h, but there was no Help() inside the
# SConscript files. Give them the options usage.
raise SConsPrintHelpException
else:
print help_text
print "Use scons -H for help about command-line options."
exit_status = 0
return
# Change directory to the top-level SConstruct directory, then tell
# the Node.FS subsystem that we're all done reading the SConscript
# files and calling Repository() and VariantDir() and changing
# directories and the like, so it can go ahead and start memoizing
# the string values of file system nodes.
fs.chdir(fs.Top)
SCons.Node.FS.save_strings(1)
# Now that we've read the SConscripts we can set the options
# that are SConscript settable:
SCons.Node.implicit_cache = options.implicit_cache
SCons.Node.FS.set_duplicate(options.duplicate)
fs.set_max_drift(options.max_drift)
SCons.Job.explicit_stack_size = options.stack_size
if options.md5_chunksize:
SCons.Node.FS.File.md5_chunksize = options.md5_chunksize
platform = SCons.Platform.platform_module()
if options.interactive:
SCons.Script.Interactive.interact(fs, OptionsParser, options,
targets, target_top)
else:
# Build the targets
nodes = _build_targets(fs, options, targets, target_top)
if not nodes:
exit_status = 2
Last edited by Aquarius_Girl; 01-16-2010 at 05:37 AM.
Well---it's pretty easy to see where it's calling "SConstruct". I'm not experienced enough with Python to analyze the code.
One other idea (grabbing at straws maybe...): Have you tried making a soft link to the file that you are executing? Go to the directory where you were trying to run the command and do this:
ln -s <path>/scons.py scons.py
Then, in that directory, you should be able to do:
python scons.py
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.