Create a file with our PID.
167254
def write_pid_file(fn):
    
    if not fn:
        return None
    if fn == '' or fn == "''":
        # work around argument passings in init-scripts
        return None
    f = open(fn, "w")
    f.write("%s\n" % (os.getpid()))
    f.close()
930700
def GenerateFile(self, input_filename=None, output_filename=None):
    """"""
    if input_filename is None:
      input_filename = output_filename + ".in"
    if output_filename[-3:] == ".in":
      output_filename = output_filename[:-3]
    logging.debug("Generating file %s from %s", output_filename, input_filename)

    with io.open(input_filename, "r") as fd:
      data = fd.read()

    with io.open(output_filename, "w") as fd:
      fd.write(config.CONFIG.InterpolateValue(data, context=self.context))
1335519
def main():
    """"""
    args = parse_arguments()
    print(args)
    print("action" + args.action)
    print("pid" + args.pid)
    print("directory" + args.directory)
    print("fileprefix" + args.fileprefix)
1293424
def __writepid(self, pid):
        
        import tempfile
        d = tempfile.gettempdir()
        name = os.path.join(d, "hoverpy.%i.%i"%(self._proxyPort, self._adminPort))
        with open(name, 'w') as f:
            f.write(str(pid))
            logging.debug("writing to %s"%name)
1306022
def open_sciobj_file_by_pid(pid, write=False):
    """"""
    abs_path = get_abs_sciobj_file_path_by_pid(pid)
    if write:
        d1_common.utils.filesystem.create_missing_directories_for_file(abs_path)
    return open_sciobj_file_by_path(abs_path, write)
661076
protected void createLockFile(String pid, String label) throws IOException {
        if (!AccessHelper.isDirectory(repositoryLocation)) {
            AccessHelper.makeDirectories(repositoryLocation);
        }

        // Remove stale lock files if any.
        for (File lock : listFiles(LOCKFILE_FILTER)) {
            AccessHelper.deleteFile(lock);
        }

        // Create a new lock file.
        StringBuilder sb = new StringBuilder();
        sb.append(getLogDirectoryName(System.currentTimeMillis(), pid, label)).append(LOCK_EXT);
        AccessHelper.createFileOutputStream(new File(repositoryLocation, sb.toString()), false).close();
    }
895079
def make(self):
        
        eval = self.command.eval()
        with open(self.filename, 'w') as f:
            f.write(eval)
471932
def cmd_as_file(cmd, *args, **kwargs):
    """"""
    kwargs['stdout'] = subprocess.PIPE
    stdin = kwargs.pop('stdin', None)
    if isinstance(stdin, basestring):
        with tempfile.TemporaryFile() as stdin_file:
            stdin_file.write(stdin)
            stdin_file.seek(0)
            kwargs['stdin'] = stdin_file
            p = subprocess.Popen(cmd, *args, **kwargs)
    else:
        p = subprocess.Popen(cmd, *args, **kwargs)
    try:
        yield p.stdout
    finally:
        p.stdout.close()
        if p.wait():
            raise subprocess.CalledProcessError(p.returncode, cmd)
237019
def create_lockfile(self):
        
        process = subprocess.Popen(
            self.pin_command,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )
        stdout, stderr = process.communicate()
        if process.returncode == 0:
            self.fix_lockfile()
        else:
            logger.critical("ERROR executing %s", ' '.join(self.pin_command))
            logger.critical("Exit code: %s", process.returncode)
            logger.critical(stdout.decode('utf-8'))
            logger.critical(stderr.decode('utf-8'))
            raise RuntimeError("Failed to pip-compile {0}".format(self.infile))
1100030
def write_pidfile(rundir, process_type=PROCESS_TYPE,
                  name=None, file=None): #@ReservedAssignment
    
    from feat.common.run import get_pidpath
    # don't shadow builtin file
    pid_file = file
    if pid_file is None:
        _ensure_dir(rundir, "rundir")
        filename = get_pidpath(rundir, process_type, name)
        pid_file = open(filename, 'w')
    else:
        filename = pid_file.name
    pid_file.write("%d\n" % (os.getpid(), ))
    pid_file.close()
    os.chmod(filename, 0644)
    return filename
441776
def write_pid(self, pid=None):
    """"""
    pid = pid or os.getpid()
    self.write_metadata_by_name(self._name, 'pid', str(pid))
417512
def __open_pidfile(self, write=False):
        
        # if problem on opening or creating file it'll be raised to the caller:
        try:
            self.pre_log.append(("DEBUG",
                                 "Opening %s pid file: %s" % ('existing' if
                                                              os.path.exists(self.pid_filename)
                                                              else 'missing', self.pid_filename)))
            # Windows do not manage the rw+ mode,
            # so we must open in read mode first, then reopen it write mode...
            if not write and os.path.exists(self.pid_filename):
                self.fpid = open(self.pid_filename, 'r+')
            else:
                # If it doesn't exist too, we create it as void
                self.fpid = open(self.pid_filename, 'w+')
        except Exception as exp:  # pylint: disable=broad-except
            self.exit_on_error("Error opening pid file: %s. Error: %s. "
                               "Check the %s:%s account permissions to write this file."
                               % (self.pid_filename, str(exp), self.user, self.group), exit_code=3)
1369430
def create(self):
        
        fdint = os.open(self.path, (os.O_EXCL |
                                    os.O_CREAT |
                                    os.O_RDWR))

        # XXX TODO: 'name' attribute of returned files is not mutable or
        # settable via fdopen, so this file is slighly less functional than the
        # one returned from 'open' by default.  send a patch to Python...

        return os.fdopen(fdint, 'w+b')
40500
def create_sample_file(ip, op, num_lines): 
    
    with open(ip, "rb") as f:
        with open(op, "wb") as fout:
            for _ in range(num_lines):
                fout.write(f.readline() )
539880
def write_pid(self, pid):
        
        self.fpid.seek(0)
        self.fpid.truncate()
        self.fpid.write("%d" % pid)
        self.fpid.close()
        del self.fpid
187895
protected static function saveMasterPid()
    {
        if (static::$_OS !== OS_TYPE_LINUX) {
            return;
        }

        static::$_masterPid = posix_getpid();
        if (false === file_put_contents(static::$pidFile, static::$_masterPid)) {
            throw new Exception('can not save pid to ' . static::$pidFile);
        }
    }
377472
def create(self, name):
        """"""
        if not os.path.exists(self.directory):
            os.makedirs(self.directory)

        filename = self.get_new_filename(name)
        with open(os.path.join(self.directory, filename), 'w') as fp:
            fp.write("def up(db): pass\n\n\n")
            fp.write("def down(db): pass\n")
            logger.info(filename)