recover from an existing export run. We do this by
        finding the last time change between events, truncate the file
        and restart from there
12656
def recover(options):
    

    event_format = options.kwargs['omode']

    buffer_size = 64*1024
    fpd = open(options.kwargs['output'], "r+")
    fpd.seek(0, 2) # seek to end
    fptr = max(fpd.tell() - buffer_size, 0)
    fptr_eof = 0

    while (fptr > 0):
        fpd.seek(fptr)
        event_buffer = fpd.read(buffer_size)
        (event_start, next_event_start, last_time) = \
            get_event_start(event_buffer, event_format)
        if (event_start != -1):
            fptr_eof = event_start + fptr
            break
        fptr = fptr - buffer_size

    if fptr < 0:
        # didn't find a valid event, so start over
        fptr_eof = 0
        last_time = 0 

    # truncate file here
    fpd.truncate(fptr_eof)
    fpd.seek(fptr_eof)
    fpd.write("\n")
    fpd.close()

    return last_time
1223582
private LocatedBlock recoverBlock(int namespaceId, Block block, boolean keepLength,
      DatanodeID[] datanodeids, boolean closeFile, long deadline) throws IOException {
    InjectionHandler.processEvent(InjectionEvent.DATANODE_BEFORE_RECOVERBLOCK,
        this);

    // If the block is already being recovered, then skip recovering it.
    // This can happen if the namenode and client start recovering the same
    // file at the same time.
    synchronized (ongoingRecovery) {
      Block tmp = new Block();
      tmp.set(block.getBlockId(), block.getNumBytes(), GenerationStamp.WILDCARD_STAMP);
      if (ongoingRecovery.get(tmp) != null) {
        String msg = "Block " + block + " is already being recovered, " +
                     " ignoring this request to recover it.";
        LOG.info(msg);
        throw new IOException(msg);
      }
      ongoingRecovery.put(block, block);
    }
    try {
      BlockRecoveryCoordinator brc = new BlockRecoveryCoordinator(LOG,
          getConf(), socketTimeout, this, namespaceManager.get(namespaceId),
          getDNRegistrationForNS(namespaceId));
      
      return brc.recoverBlock(namespaceId, block, keepLength, datanodeids, closeFile,
          deadline);
    } finally {
      synchronized (ongoingRecovery) {
        ongoingRecovery.remove(block);
      }
    }
  }
372729
def delete_run():
    
    assert request.method == "POST", "POST request expected received {}".format(request.method)
    if request.method == "POST":
        try:
            selections = json.loads(request.form["selections"])
            utils.drop_run(selections["project"], selections["run"])
            return jsonify({"response": "deleted {}".format(selections["run"])})
        except Exception as e:
            logging.error(e)
    return jsonify({"0": "__EMPTY"})
1336728
function restore() {
    if (isOriginal) return;
    else isOriginal = true;
    ['log', 'debug', 'info', 'warn', 'error'].forEach((item) => {
        console[item] = originalConsoleFunctions[item];
    });
}
408949
void rollOver() throws IOException {

		// If compression is enabled we start a separated thread
		if (getCompressBackups().equalsIgnoreCase("YES")
				|| getCompressBackups().equalsIgnoreCase("TRUE")) {
			File file = new File(fileName);
			Thread fileCompressor = new Thread(new CompressFile(file));
			fileCompressor.start();
		}

		/* Compute filename, but only if datePattern is specified */
		if (datePattern == null) {
			errorHandler.error("Missing DatePattern option in rollOver().");
			return;
		}

		String datedFilename = baseFileName + sdf.format(now);
		// It is too early to roll over because we are still within the
		// bounds of the current interval. Rollover will occur once the
		// next interval is reached.
		if (scheduledFilename.equals(datedFilename)) {
			return;
		}

		activateOptions();
	}
1178710
def execute_run(event)
      phase! Run
      @world.logger.debug format('%13s %s:%2d got event %s',
                                 'Step', execution_plan_id, @step.id, event) if event
      @input = OutputReference.dereference @input, world.persistence

      case
      when state == :running
        raise NotImplementedError, 'recovery after restart is not implemented'

      when [:pending, :error, :skipping, :suspended].include?(state)
        if event && state != :suspended
          raise 'event can be processed only when in suspended state'
        end

        self.state = :running unless self.state == :skipping
        save_state
        with_error_handling do
          event = Skip if state == :skipping

          # we run the Skip event only when the run accepts events
          if event != Skip || run_accepts_events?
            result = catch(SUSPEND) do
              world.middleware.execute(:run, self, *[event].compact) do |*args|
                run(*args)
              end
            end

            self.state = :suspended if result == SUSPEND
          end

          check_serializable :output
        end
      else
        raise "wrong state #{state} when event:#{event}"
      end
    end
1217930
def on_deleted(self, event):
        
        logger.debug("File deleted: %s", event.src_path)
        if not event.is_directory:
            self.update_file(event.src_path)
114039
def run
      # do plugins that need to happen before capture
      execute_plugins_for(:pre_capture)

      # do main capture to snapshot_loc
      run_capture

      # check capture succeded, file must exist
      if File.exist?(snapshot_loc)
        ## resize snapshot first
        resize_snapshot!

        # execute post_capture plugins, use to alter the capture
        execute_plugins_for(:post_capture)

        # execute capture_ready plugins, capture is ready for export/sharing
        execute_plugins_for(:capture_ready)

        # clean away any tmp files
        cleanup!
      else
        debug 'Runner: failed to capture a snapshot'
        exit 1
      end
    end
929385
protected void doRestore() throws Throwable
   {
      PlainChangesLog changes = read();

      TransactionChangesLog tLog = new TransactionChangesLog(changes);
      tLog.setSystemId(Constants.JCR_CORE_RESTORE_WORKSPACE_INITIALIZER_SYSTEM_ID); // mark changes

      dataManager.save(tLog);
   }
65610
def cleanup(self):
        
        if self.sock is not None:
            self.sock.close()
        if self.outfile is not None:
            self.outfile.close()
        if self.bar is not None:
            self.update_progress(complete=True)
923534
def reset
      output.each do |file, format|
        if File.exist?(file)
          utime(0,0,file)
          report "Marked #{file} as out-of-date."
        end
      end
    end
754456
def after_def
      previous = pop_scope
      current  = current_scope

      reset_docstring_tags

      EXPORT_VARIABLES.each do |type|
        current.copy(previous, type)
      end
    end
566709
protected void removeOldExport(String exportPath) {

        File output = new File(exportPath);
        if (output.exists()) {
            // the output already exists
            if (output.isDirectory()) {
                // purge the complete directory
                CmsFileUtil.purgeDirectory(output);
            } else {
                // remove the existing file
                if (m_isExportAsFiles) {
                    // in case we write to a file we can just overwrite,
                    // but for a folder we must remove an existing file
                    output.delete();
                }
            }
        }
    }
102032
def reload_exports():
    '''
    
    '''
    ret = {}

    command = 'exportfs -r'

    output = __salt__['cmd.run_all'](command)
    ret['stdout'] = output['stdout']
    ret['stderr'] = output['stderr']
    # exportfs always returns 0, so retcode is useless
    # We will consider it an error if stderr is nonempty
    ret['result'] = output['stderr'] == ''

    return ret
1319615
def onImport(self, event):
        
        if self.grid.changes:
            print("-W- Your changes will be overwritten...")
            wind = pw.ChooseOne(self, "Import file anyway", "Save grid first",
                                "-W- Your grid has unsaved changes which will be overwritten if you import a file now...")
            wind.Centre()
            res = wind.ShowModal()
            # save grid first:
            if res == wx.ID_NO:
                self.onSave(None, alert=True, destroy=False)
                # reset self.changes
                self.grid.changes = set()

        openFileDialog = wx.FileDialog(self, "Open MagIC-format file", self.WD, "",
                                       "MagIC file|*.*", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
        result = openFileDialog.ShowModal()
        if result == wx.ID_OK:
            # get filename
            filename = openFileDialog.GetPath()
            # make sure the dtype is correct
            f = open(filename)
            line = f.readline()
            if line.startswith("tab"):
                delim, dtype = line.split("\t")
            else:
                delim, dtype = line.split("")
            f.close()
            dtype = dtype.strip()
            if (dtype != self.grid_type) and (dtype + "s" != self.grid_type):
                text = "You are currently editing the {} grid, but you are trying to import a {} file.\nPlease open the {} grid and then re-try this import.".format(self.grid_type, dtype, dtype)
                pw.simple_warning(text)
                return
            # grab old data for concatenation
            if self.grid_type in self.contribution.tables:
                old_df_container = self.contribution.tables[self.grid_type]
            else:
                old_df_container = None
            old_col_names = self.grid.col_labels
            # read in new file and update contribution
            df_container = cb.MagicDataFrame(filename, dmodel=self.dm,
                                             columns=old_col_names)
            # concatenate if possible
            if not isinstance(old_df_container, type(None)):
                df_container.df = pd.concat([old_df_container.df, df_container.df],
                                            axis=0, sort=True)
            self.contribution.tables[df_container.dtype] = df_container
            self.grid_builder = GridBuilder(self.contribution, self.grid_type,
                                            self.panel, parent_type=self.parent_type,
                                            reqd_headers=self.reqd_headers)
            # delete old grid
            self.grid_box.Hide(0)
            self.grid_box.Remove(0)
            # create new, updated grid
            self.grid = self.grid_builder.make_grid()
            self.grid.InitUI()
            # add data to new grid
            self.grid_builder.add_data_to_grid(self.grid, self.grid_type)
            # add new grid to sizer and fit everything
            self.grid_box.Add(self.grid, flag=wx.ALL, border=5)
            self.main_sizer.Fit(self)
            self.Centre()
            # add any needed drop-down-menus
            self.drop_down_menu = drop_down_menus.Menus(self.grid_type,
                                                        self.contribution,
                                                        self.grid)
            # done!
        return
362750
def reset(self):
        

        if self.ffmpeg_process is not None:
            # Close the previous stream
            try:
                self.ffmpeg_process.send_signal(signal.SIGINT)
            except OSError:
                pass

        command = []
        command.extend([
            self.ffmpeg_binary,
            '-loglevel', 'verbose',
            '-y',       # overwrite previous file/stream
            # '-re',    # native frame-rate
            '-analyzeduration', '1',
            '-f', 'rawvideo',
            '-r', '%d' % self.fps,  # set a fixed frame rate
            '-vcodec', 'rawvideo',
            # size of one frame
            '-s', '%dx%d' % (self.width, self.height),
            '-pix_fmt', 'rgb24',  # The input are raw bytes
            '-thread_queue_size', '1024',
            '-i', '/tmp/videopipe',  # The input comes from a pipe

            # Twitch needs to receive sound in their streams!
            # '-an',            # Tells FFMPEG not to expect any audio
        ])
        if self.audio_enabled:
            command.extend([
                '-ar', '%d' % AUDIORATE,
                '-ac', '2',
                '-f', 's16le',
                '-thread_queue_size', '1024',
                '-i', '/tmp/audiopipe'
            ])
        else:
            command.extend([
                '-ar', '8000',
                '-ac', '1',
                '-f', 's16le',
                '-i', '/dev/zero',  # silence alternative, works forever
                # '-i','http://stream1.radiostyle.ru:8001/tunguska',
                # '-filter_complex',
                # '[0:1][1:0]amix=inputs=2:duration=first[all_audio]'
            ])
        command.extend([
            # VIDEO CODEC PARAMETERS
            '-vcodec', 'libx264',
            '-r', '%d' % self.fps,
            '-b:v', '3000k',
            '-s', '%dx%d' % (self.width, self.height),
            '-preset', 'faster', '-tune', 'zerolatency',
            '-crf', '23',
            '-pix_fmt', 'yuv420p',
            # '-force_key_frames', r'expr:gte(t,n_forced*2)',
            '-minrate', '3000k', '-maxrate', '3000k',
            '-bufsize', '12000k',
            '-g', '60',     # key frame distance
            '-keyint_min', '1',
            # '-filter:v "setpts=0.25*PTS"'
            # '-vsync','passthrough',

            # AUDIO CODEC PARAMETERS
            '-acodec', 'libmp3lame', '-ar', '44100', '-b:a', '160k',
            # '-bufsize', '8192k',
            '-ac', '1',
            # '-acodec', 'aac', '-strict', 'experimental',
            # '-ab', '128k', '-ar', '44100', '-ac', '1',
            # '-async','44100',
            # '-filter_complex', 'asplit', #for audio sync?

            # STORE THE VIDEO PARAMETERS
            # '-vcodec', 'libx264', '-s', '%dx%d'%(width, height),
            # '-preset', 'libx264-fast',
            # 'my_output_videofile2.avi'

            # MAP THE STREAMS
            # use only video from first input and only audio from second
            '-map', '0:v', '-map', '1:a',

            # NUMBER OF THREADS
            '-threads', '2',

            # STREAM TO TWITCH
            '-f', 'flv', 'rtmp://live-ams.twitch.tv/app/%s' %
            self.twitch_stream_key
            ])

        devnullpipe = open("/dev/null", "w")     # Throw away stream
        if self.verbose:
            devnullpipe = None
        self.ffmpeg_process = subprocess.Popen(
            command,
            stdin=subprocess.PIPE,
            stderr=devnullpipe,
            stdout=devnullpipe)
220561
def _FlushExportBuffer(self, output_module, deduplicate_events=True):
    
    last_macb_group_identifier = None
    last_content_identifier = None
    macb_group = []

    generator = self._export_event_heap.PopEvents()

    for macb_group_identifier, content_identifier, event in generator:
      if deduplicate_events and last_content_identifier == content_identifier:
        self._events_status.number_of_duplicate_events += 1
        continue

      if macb_group_identifier is None:
        if macb_group:
          output_module.WriteEventMACBGroup(macb_group)
          macb_group = []

        output_module.WriteEvent(event)

      else:
        if (last_macb_group_identifier == macb_group_identifier or
            not macb_group):
          macb_group.append(event)

        else:
          output_module.WriteEventMACBGroup(macb_group)
          macb_group = [event]

        self._events_status.number_of_macb_grouped_events += 1

      last_macb_group_identifier = macb_group_identifier
      last_content_identifier = content_identifier

    if macb_group:
      output_module.WriteEventMACBGroup(macb_group)