Create empty .csv files with the right headers and place them in the
        Will place files as siblings of directory `channeldir`.
166509
def generate_templates(self, exercise_questions=False):
        
        self.generate_template(channeldir=self.channeldir,
                               filename=self.channelinfo,
                               header=CHANNEL_INFO_HEADER)
        self.generate_template(channeldir=self.channeldir,
                               filename=self.contentinfo,
                               header=CONTENT_INFO_HEADER)
        if exercise_questions:
            self.generate_template(channeldir=self.channeldir,
                                   filename=self.exercisesinfo,
                                   header=EXERCISE_INFO_HEADER)
            self.generate_template(channeldir=self.channeldir,
                                   filename=self.questionsinfo,
                                   header=EXERCISE_QUESTIONS_INFO_HEADER)
1317300
def create_dirs(fname, is_file=False):
    
    fname = os.path.abspath(fname)
    if is_file:
        fname = os.path.dirname(fname)

    if not os.path.exists(fname):
        os.makedirs(fname)
916441
def stack_files(files, hemi, source, target):
  
  import csv
  import os
  import numpy as np

  fname = "sdist_%s_%s_%s.csv" % (hemi, source, target)
  filename = os.path.join(os.getcwd(),fname)

  alldist = []

  for dfile in files:
    alldist.append(np.genfromtxt(dfile, delimiter=','))

  alldist = np.array(alldist)
  alldist.tofile(filename,",")

  return filename
1016218
private function _saveHeaders()
    {
        fwrite($this->SHPFile, pack('NNNNNN', self::MAGIC, 0, 0, 0, 0, 0));
        fwrite($this->SHPFile, pack('N', $this->fileLength));
        fwrite($this->SHPFile, pack('V', 1000));
        fwrite($this->SHPFile, pack('V', $this->shapeType));
        $this->_saveBBox($this->SHPFile);

        fwrite($this->SHXFile, pack('NNNNNN', self::MAGIC, 0, 0, 0, 0, 0));
        fwrite($this->SHXFile, pack('N', 50 + 4 * count($this->records)));
        fwrite($this->SHXFile, pack('V', 1000));
        fwrite($this->SHXFile, pack('V', $this->shapeType));
        $this->_saveBBox($this->SHXFile);
    }
9052
def _create(self):
    """"""
    from .tools import makedirs_safe

    # create directory for sql database
    makedirs_safe(os.path.dirname(self._database))

    # create all the tables
    Base.metadata.create_all(self._engine)
    logger.debug("Created new empty database '%s'" % self._database)
587717
def write_headers(self):
        
        h1 = []
        h2 = []
        for m in self.values():
            h2.append(m.render_subtitle())
            h1.append(m.render_title())

        stdout.write(" ".join(h1))
        stdout.write("\n\r")
        c = _ansi["gray"] + "|" + _ansi["reset"]
        stdout.write(c.join(h2))
        stdout.write("\n\r")
        stdout.flush()

        if self._csvfile:
            header_row = []
            for m in self.values():
                if isinstance(m, MultiMetric):
                    for subm in m.values():
                        header_row.append(
                            "{}_{}".format(m.title, subm.title)
                        )
                else:
                    if m.subtitle:
                        header_row.append(
                            "{}_{}".format(m.title, m.subtitle)
                        )
                    else:
                        header_row.append(m.title)
            self._write_csv_row(header_row, rewrite=True)
1151230
def _get_emptydirs(self, files):
        ''''''
        emptydirs = []
        for f in files:
            if self._is_dir(f):
                empty = True
                for ff in files:
                    if ff.startswith(f + '/'):
                        empty = False
                        break
                if empty:
                    emptydirs.append(f)
        return emptydirs
965860
def run(self):
        """"""
        # Try to create the directory
        if not os.path.exists(self.output):
            try:
                os.mkdir(self.output)
            except:
                print 'failed to create output directory %s' % self.output

        # Be sure it is a directory
        if not os.path.isdir(self.output):
            print 'invalid output directory %s' % self.output
            sys.exit(1)

        # Create the CSV handlers
        visitors = [
            _CompaniesCSV(self.output),
            _ActivitiesCSV(self.output),
            _ActivitiesSeenCSV(self.output),
            _QSACSV(self.output),
        ]

        # Run by each company populating the CSV files
        for path in glob.glob(os.path.join(self.input, '*.json')):
            with open(path, 'r') as f:
                try:
                    data = json.load(f, encoding='utf-8')
                except ValueError:
                    continue

                for visitor in visitors:
                    visitor.visit(data)
793836
def generate_contentinfo_from_folder(self, csvwriter, rel_path, filenames):
        
        LOGGER.debug('IN process_folder ' + str(rel_path) + '     ' + str(filenames))
        from ricecooker.utils.linecook import filter_filenames, filter_thumbnail_files, chan_path_from_rel_path

        # WRITE TOPIC ROW
        topicrow = self.channeldir_node_to_row( rel_path.split(os.path.sep) )
        csvwriter.writerow(topicrow)

        # WRITE CONTENT NODE ROWS
        chan_path = chan_path_from_rel_path(rel_path, self.channeldir)
        filenames_cleaned = filter_filenames(filenames)
        # filenames_cleaned2 = filter_thumbnail_files(chan_path, filenames_cleaned, self)
        for filename in filenames_cleaned:
            path_tuple = rel_path.split(os.path.sep)
            path_tuple.append(filename)
            filerow = self.channeldir_node_to_row(path_tuple)
            csvwriter.writerow(filerow)
362203
def create_empty_directories
      %w{config/initializers lib spec}.each do |dir|
        empty_directory File.join(@app_path, dir)
      end

      empty_directory File.join(@app_path, 'db/migrate') unless @database.empty?

      create_file File.join(@app_path, "lib", ".gitkeep")
    end
1120027
private void setupFile() {
        if (!new File(directory).exists() && !new File(directory).mkdirs()) {
            try {
                throw new IOException("Unable to create output directory");
            } catch (IOException e) {
                log.info(e);
            }
        }
        if (!file.exists()) {
            try {
                if (!file.createNewFile()) {
                    throw new IOException("Unable to create output file");
                }
            } catch (IOException e) {
                log.error(e);
            }
        }
    }
1232710
def createBlendedFolders():
    """"""
    # Create the templates folder
    create_folder(os.path.join(cwd, "templates"))

    # Create the templates/assets folder
    create_folder(os.path.join(cwd, "templates", "assets"))

    # Create the templates/assets/css folder
    create_folder(os.path.join(cwd, "templates", "assets", "css"))

    # Create the templates/assets/js folder
    create_folder(os.path.join(cwd, "templates", "assets", "js"))

    # Create the templates/assets/img folder
    create_folder(os.path.join(cwd, "templates", "assets", "img"))

    # Create the content folder
    create_folder(os.path.join(cwd, "content"))
1025703
def build(self, sources=None, headers=None):
        ''' 
        '''
        tempdir = None
        strings, files = separate_sources(sources)
        if len(strings) or headers:
            # TODO: remove tempdir
            tempdir = tmpdir()

        temp_list = [tmpfile(x, tempdir, '.c') for x in strings]

        if headers:
            for n, s in headers.items():
                (Path(tempdir) / n).write_text(s)

        cmd = self.command_list(files + temp_list)
        if tempdir:
            cmd += ['-I' + tempdir]
        self.proc = Proc(cmd).call()
#        for x in temp_list:
#            os.remove(x)

        if not self.ok:
            raise AvrGccCompileError(cmd, sources, self.error_text)
599600
public static void writeCSVRows(XYSeries series, String path2Dir) {

    File newFile = new File(path2Dir + series.getName() + ".csv");
    Writer out = null;
    try {

      out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(newFile), "UTF8"));
      String csv = join(series.getXData(), ",") + System.getProperty("line.separator");
      out.write(csv);
      csv = join(series.getYData(), ",") + System.getProperty("line.separator");
      out.write(csv);
      if (series.getExtraValues() != null) {
        csv = join(series.getExtraValues(), ",") + System.getProperty("line.separator");
        out.write(csv);
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (out != null) {
        try {
          out.flush();
          out.close();
        } catch (IOException e) {
          // NOP
        }
      }
    }
  }
26350
void initFromDir() {
    for (File file : this.logDir.listFiles()) {
      if (!file.isDirectory() &&
          file.getName().matches("transaction\\.\\d+_\\d+")) {
        // Appends the file with valid name to log file list.
        this.logFiles.add(file);
      }
    }
    if (!this.logFiles.isEmpty()) {
      // Sorts the file by the zxid order.
      Collections.sort(this.logFiles);
    }
  }
1281453
def exporter(directory, method, datasets):
    """"""
    if method.lower() == 'json':
        # Convert json_dict to a JSON styled string
        json_string = json.dumps(datasets, indent=4)
        savefile = open('{}/exported.json'.format(directory), 'w+')
        savefile.write(json_string)
        savefile.close()

    if method.lower() == 'csv':
        with open('{}/exported.csv'.format(directory), 'w+') as csvfile:
            csv_writer = csv.writer(
                csvfile, delimiter=',', quoting=csv.QUOTE_MINIMAL)
            for key, values in datasets.items():
                if values is None:
                    csv_writer.writerow([key])
                else:
                    csv_writer.writerow([key] + values)
        csvfile.close()
456185
def createFile(dataArray=None, outfile=None, header=None):
    
    # Insure that at least a data-array has been provided to create the file
    assert(dataArray is not None), "Please supply a data array for createFiles"

    try:
        # Create the output file
        fitsobj = fits.HDUList()
        if header is not None:
            try:
                del(header['NAXIS1'])
                del(header['NAXIS2'])
                if 'XTENSION' in header:
                    del(header['XTENSION'])
                if 'EXTNAME' in header:
                    del(header['EXTNAME'])
                if 'EXTVER' in header:
                    del(header['EXTVER'])
            except KeyError:
                pass

            if 'NEXTEND' in header:
                header['NEXTEND'] = 0

            hdu = fits.PrimaryHDU(data=dataArray, header=header)
            try:
                del hdu.header['PCOUNT']
                del hdu.header['GCOUNT']
            except KeyError:
                pass

        else:
            hdu = fits.PrimaryHDU(data=dataArray)

        fitsobj.append(hdu)
        if outfile is not None:
            fitsobj.writeto(outfile)
    finally:
        # CLOSE THE IMAGE FILES
        fitsobj.close()

        if outfile is not None:
            del fitsobj
            fitsobj = None
    return fitsobj