+ ### handle filename
+ # build the filename string
+ # check for permissions and concurrency
+ # returns the filename
+ def handle_filename (self, filename, nodename, suffix, arch):
+ # allow to set filename to None or any other empty value
+ if not filename: filename=''
+ filename = filename.replace ("%d",self.WORKDIR)
+ filename = filename.replace ("%n",nodename)
+ filename = filename.replace ("%s",suffix)
+ filename = filename.replace ("%p",self.api.config.PLC_NAME)
+ # let's be cautious
+ try: filename = filename.replace ("%f", self.nodefamily)
+ except: pass
+ try: filename = filename.replace ("%a", arch)
+ except: pass
+ try: filename = filename.replace ("%v",self.bootcd_version())
+ except: pass
+
+ ### Check filename location
+ if filename != '':
+ if 'admin' not in self.caller['roles']:
+ if ( filename.index(self.WORKDIR) != 0):
+ raise PLCInvalidArgument, "File %s not under %s"%(filename,self.WORKDIR)
+
+ ### output should not exist (concurrent runs ..)
+ if os.path.exists(filename):
+ raise PLCInvalidArgument, "Resulting file %s already exists"%filename
+
+ ### we can now safely create the file,
+ ### either we are admin or under a controlled location
+ filedir=os.path.dirname(filename)
+ # dirname does not return "." for a local filename like its shell counterpart
+ if filedir:
+ if not os.path.exists(filedir):
+ try:
+ os.makedirs (filedir,0777)
+ except:
+ raise PLCPermissionDenied, "Could not create dir %s"%filedir
+
+ return filename
+
+ # Build the command line to be executed
+ # according the node type
+ def build_command(self, node_type, build_sh_spec, node_image, type, floppy_file, log_file):
+
+ command = ""
+
+ # regular node, make build's arguments
+ # and build the full command line to be called
+ if node_type == 'regular':
+
+ build_sh_options=""
+ if "cramfs" in build_sh_spec:
+ type += "_cramfs"
+ if "serial" in build_sh_spec:
+ build_sh_options += " -s %s"%build_sh_spec['serial']
+ if "variant" in build_sh_spec:
+ build_sh_options += " -V %s"%build_sh_spec['variant']
+
+ for karg in build_sh_spec['kargs']:
+ build_sh_options += ' -k "%s"'%karg
+
+ log_file="%s.log"%node_image
+
+ command = '%s -f "%s" -o "%s" -t "%s" %s &> %s' % (self.BOOTCDBUILD,
+ floppy_file,
+ node_image,
+ type,
+ build_sh_options,
+ log_file)
+ # dummynet node
+ elif node_type == 'dummynet':
+ # the build script expect the following parameters:
+ # the package base directory
+ # the working directory
+ # the full path of the configuration file
+ # the name of the resulting image file
+ # the type of the generated image
+ # the name of the log file
+ command = "%s -b %s -w %s -f %s -o %s -t %s -l %s" \
+ % (self.BOOTCDBUILD, self.BOOTCDDIR, self.WORKDIR,
+ floppy_file, node_image, type, log_file)
+ command = "touch %s %s; echo 'dummynet build script not yet supported'" \
+ % (log_file, node_image)
+
+ if self.DEBUG:
+ print "The build command line is %s" % command
+
+ return command
+