From 6eaa4d3571e340598a2ddd03c8479d0bc993bde2 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Wed, 9 Feb 2005 13:40:02 -0500 Subject: [PATCH 1/4] fix indent (so emacs and vi aren't screwed up.) --HG-- extra : convert_revision : 589f37476fec14aa5e3c6e018631e291113d4e69 --- sim/pyconfig/m5config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sim/pyconfig/m5config.py b/sim/pyconfig/m5config.py index 4e3a4103c..c9bfdab54 100644 --- a/sim/pyconfig/m5config.py +++ b/sim/pyconfig/m5config.py @@ -28,9 +28,9 @@ from __future__ import generators import os, re, sys, types noDot = False try: - import pydot + import pydot except: - noDot = True + noDot = True env = {} env.update(os.environ) From 89ba024b9843719bf06a9c3efaaf1b137dee2a12 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Wed, 9 Feb 2005 13:41:53 -0500 Subject: [PATCH 2/4] Fix the panic message so that it looks more like M5's panic. Make it so the same path is not added to the system path twice. --HG-- extra : convert_revision : fe18db38cc4e335ad3525a364e9f8faf62b60e52 --- sim/pyconfig/m5config.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sim/pyconfig/m5config.py b/sim/pyconfig/m5config.py index c9bfdab54..bbd437b30 100644 --- a/sim/pyconfig/m5config.py +++ b/sim/pyconfig/m5config.py @@ -36,11 +36,12 @@ env = {} env.update(os.environ) def panic(*args, **kwargs): - sys.exit(*args, **kwargs) + print >>sys.stderr, 'panic:', string + sys.exit(1) def AddToPath(path): path = os.path.realpath(path) - if os.path.isdir(path): + if os.path.isdir(path) and path not in sys.path: sys.path.append(path) def Import(path): From 26ef1f56c8b62019e45f008f2abb2f8dcca6f24b Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Wed, 9 Feb 2005 13:46:23 -0500 Subject: [PATCH 3/4] Add the split_first and split_last functions on strings. base/str.cc: base/str.hh: Add a couple functions that allow you to split a string at the first or last instance of a delimiter. --HG-- extra : convert_revision : 2af22639e1b67ac61577c00475a555841a56f902 --- base/str.cc | 30 ++++++++++++++++++++++++++++++ base/str.hh | 14 ++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/base/str.cc b/base/str.cc index dd8d80043..5357ba79f 100644 --- a/base/str.cc +++ b/base/str.cc @@ -39,6 +39,36 @@ using namespace std; +bool +split_first(const string &s, string &lhs, string &rhs, char c) +{ + string::size_type offset = s.find(c); + if (offset == string::npos) { + lhs = s; + rhs = ""; + return false; + } + + lhs = s.substr(0, offset); + rhs = s.substr(offset + 1); + return true; +} + +bool +split_last(const string &s, string &lhs, string &rhs, char c) +{ + string::size_type offset = s.rfind(c); + if (offset == string::npos) { + lhs = s; + rhs = ""; + return false; + } + + lhs = s.substr(0, offset); + rhs = s.substr(offset + 1); + return true; +} + void tokenize(vector& v, const string &s, char token, bool ignore) { diff --git a/base/str.hh b/base/str.hh index 812f4d41a..41433f2bd 100644 --- a/base/str.hh +++ b/base/str.hh @@ -90,6 +90,20 @@ to_lower(const std::string &s) return lower; } +// Split the string s into lhs and rhs on the first occurence of the +// character c. +bool +split_first(const std::string &s, std::string &lhs, std::string &rhs, char c); + +// Split the string s into lhs and rhs on the last occurence of the +// character c. +bool +split_last(const std::string &s, std::string &lhs, std::string &rhs, char c); + +// Tokenize the string splitting on the character , and +// place the result in the string vector . If is true, +// then empty result strings (due to trailing tokens, or consecutive +// tokens) are skipped. void tokenize(std::vector &vector, const std::string &s, char token, bool ign = true); From 061f40df08f6992bf314eb6f23315ef415e58882 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Wed, 9 Feb 2005 16:20:53 -0500 Subject: [PATCH 4/4] Fixes to thes pbs send script util/pbs/send.py: - add a -d to set the job root directory allowing one to run send.py from anywhere. - specify full paths to files instead of relative paths to make -d work and to allow ssh qsub to work again. - make the Link directory only copy links that point to regular files. --HG-- extra : convert_revision : dd330cee08b97c5d72c3d58ef123f83ac7ccede7 --- util/pbs/send.py | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/util/pbs/send.py b/util/pbs/send.py index c0c56d98b..1f174b1f8 100755 --- a/util/pbs/send.py +++ b/util/pbs/send.py @@ -54,7 +54,7 @@ Usage: try: import getopt - opts, args = getopt.getopt(sys.argv[1:], '-cefhlq:v') + opts, args = getopt.getopt(sys.argv[1:], '-cd:efhlq:v') except getopt.GetoptError: sys.exit(usage) @@ -65,42 +65,48 @@ force = False listonly = False queue = '' verbose = False -for o,a in opts: - if o == '-c': +rootdir = re.sub(r'^/\.automount/', r'/n/', os.getcwd()) +for opt,arg in opts: + if opt == '-c': clean = True - if o == '-e': + if opt == '-d': + rootdir = arg + if opt == '-e': onlyecho = True - if o == '-f': + if opt == '-f': force = True - if o == '-h': + if opt == '-h': print usage sys.exit(0) - if o == '-l': + if opt == '-l': listonly = True - if o == '-q': - queue = a - if o == '-v': + if opt == '-q': + queue = arg + if opt == '-v': verbose = True +basedir = joinpath(rootdir, 'Base') +linkdir = joinpath(rootdir, 'Link') + for arg in args: exprs.append(re.compile(arg)) -if not listonly and not onlyecho and isdir('Link'): +if not listonly and not onlyecho and isdir(linkdir): print 'Checking for outdated files in Link directory' - entries = listdir('Link') + entries = listdir(linkdir) for entry in entries: - link = joinpath('Link', entry) - if not islink(link): + link = joinpath(linkdir, entry) + if not islink(link) or not isfile(link): continue - base = joinpath('Base', entry) + base = joinpath(basedir, entry) if not isfile(base) or not filecmp(link, base): - print '%s is different than source %s...copying' % (base, link) + print 'Base/%s is different than Link/%s: copying' % (entry, entry) copyfile(link, base) import job, jobfile, pbs -test = jobfile.JobFile(joinpath('Base', 'test.py')) +test = jobfile.JobFile(joinpath(basedir, 'test.py')) joblist = [] for jobname in test.jobs: @@ -143,7 +149,6 @@ if not onlyecho: jl.append(jobname) joblist = jl -rootdir = re.sub(r'^/\.automount/', r'/n/', os.getcwd()) for jobname in joblist: jobdir = joinpath(rootdir, jobname) @@ -165,5 +170,5 @@ for jobname in joblist: if len(queue): qsub.queue = queue - qsub.do(joinpath('Base', 'job.py')) + qsub.do(joinpath(basedir, 'job.py')) print >>sys.stderr, ''