Add a newly created file to a Recipe
333889
def file_add(backend, kitchen, recipe, message, filepath):
    
    err_str, use_kitchen = Backend.get_kitchen_from_user(kitchen)
    if use_kitchen is None:
        raise click.ClickException(err_str)
    if recipe is None:
        recipe = DKRecipeDisk.find_recipe_name()
        if recipe is None:
            raise click.ClickException('You must be in a recipe folder, or provide a recipe name.')

    click.secho('%s - Adding File (%s) to Recipe (%s) in kitchen(%s) with message (%s)' %
                (get_datetime(), filepath, recipe, use_kitchen, message), fg='green')
    check_and_print(DKCloudCommandRunner.add_file(backend.dki, use_kitchen, recipe, message, filepath))
354659
def add(self, filename, change=None):
        
        try:
            if not self.canAdd(filename):
                raise errors.RevisionError('File is not under client path')

            if change is None:
                self.run(['add', filename])
            else:
                self.run(['add', '-c', str(change.change), filename])

            data = self.run(['fstat', filename])[0]
        except errors.CommandError as err:
            LOGGER.debug(err)
            raise errors.RevisionError('File is not under client path')

        rev = Revision(data, self)

        if isinstance(change, Changelist):
            change.append(rev)

        return rev
996582
def create_new_file(self, current_path, title, filters, create_func):
        """"""
        if current_path is None:
            current_path = ''
        if osp.isfile(current_path):
            current_path = osp.dirname(current_path)
        self.redirect_stdio.emit(False)
        fname, _selfilter = getsavefilename(self, title, current_path, filters)
        self.redirect_stdio.emit(True)
        if fname:
            try:
                create_func(fname)
                return fname
            except EnvironmentError as error:
                QMessageBox.critical(self, _("New file"),
                                     _("<b>Unable to create file <i>%s</i>"
                                       "</b><br><br>Error message:<br>%s"
                                       ) % (fname, to_text_string(error)))
222723
def create(self, columns=None, type_map=None, overwrite=False):
        """"""
        # Check already exists #
        if self.count_bytes > 0:
            if overwrite: self.remove()
            else: raise Exception("File exists already at '%s'" % self)
        # If we want it empty #
        if columns is None:
            self.touch()
        # Make the table #
        else:
            self.add_table(self.main_table, columns=columns, type_map=type_map)
266368
function handleRecipeFile(recipePath) {
    var contents = null;
    try {
        contents = fs.readFileSync(recipePath);
    } catch (err) {
        // Not finding a recipe is OK
        return;
    }

    var config = null;
    try {
        config = JSON.parse(contents.toString());
    } catch (err) {
        // Finding a recipe that cannot be parsed is a disaster
        console.log('Error in parsing JSON for ' + recipePath);
        process.exit(-1);
    }

    // Determine the glob patterns
    var filesGlob = ['**/*.ts'];
    if (typeof config.filesGlob === 'string') {
        filesGlob = [config.filesGlob];
    } else if (Array.isArray(config.filesGlob)) {
        filesGlob = config.filesGlob;
    }

    var resultConfig = {};
    for (var prop in config) {
        resultConfig[prop] = config[prop];
    }
    resultConfig.files = findFiles(recipePath, filesGlob);

    var resultTxt = JSON.stringify(resultConfig, null, '  ');
    var resultPath = path.join(path.dirname(recipePath), 'tsconfig.json');
    fs.writeFileSync(resultPath, resultTxt);
    console.log('Updated ' + resultPath);
}
335841
def content_from_cookbook_file(chef_run, cookbook_file)
      cookbook_name = cookbook_file.cookbook || cookbook_file.cookbook_name
      cookbook = cookbook_collection(chef_run.node)[cookbook_name]
      File.read(cookbook.preferred_filename_on_disk_location(chef_run.node, :files, cookbook_file.source))
    end
560327
def setup_recent_files_menu(self):
        
        self.recent_files_manager = widgets.RecentFilesManager(
            'pyQode', 'notepad')
        self.menu_recents = widgets.MenuRecentFiles(
            self.menuFile, title='Recents',
            recent_files_manager=self.recent_files_manager)
        self.menu_recents.open_requested.connect(self.open_file)
        self.menuFile.insertMenu(self.actionSave, self.menu_recents)
        self.menuFile.insertSeparator(self.actionSave)
410501
def build_knife_config
      FileUtils.mkdir_p(chef_config_path)
      File.binwrite(knife_config_path, ERB.new(knife_config_template).result(binding))
    end
623159
function (filename) {
    if (!fs.existsSync(filename)) {
        logger.error({
            method: "edit_add_cookbook_ids",
            filename: filename
        }, "file does not exist");
        return;
    }

    var encoding = 'utf8';
    var changed = false;
    var contents = fs.readFileSync(filename, encoding);
    var _replacer = function (full, cookbook_name) {
        changed = true;
        return util.format('homestar.cookbook(%s, "%s");', cookbook_name, uuid.v4());
    };

    contents = contents.replace(/^\s*homestar\s*.\s*cookbook\s*[(]\s*("[^"]*")\s*[)](\s*;)?/mg, _replacer);
    contents = contents.replace(/^\s*homestar\s*.\s*cookbook\s*[(]\s*('[^"]*')\s*[)](\s*;)?/mg, _replacer);

    if (changed) {
        fs.writeFileSync(filename, contents, {
            encoding: encoding
        });
        logger.info({
            method: "edit_add_cookbook_ids",
            filename: filename
        }, "updated recipe");
    }
}
394953
def add_file(name, content)
      full_path = File.join(@path, name)
      file      = MirrorFile.new(full_path)

      file.write(content)

      file
    end
735624
def on_created(self, event):
        
        if os.path.isdir(event.src_path):
            return

        logger.debug("File created: %s", event.src_path)

        name = self.file_name(event)

        try:
            result = self.target_class.from_config(
                name, yaml.load(open(event.src_path))
            )
        except Exception as e:
            logger.exception(
                "Error when loading new config file %s: %s",
                event.src_path, str(e)
            )
            return

        if not result:
            return

        self.on_add(self.target_class, name, result)
521718
def add_ingredients(self):
        
        for ingredient in self.recipe._cauldron.values():
            if hasattr(ingredient.meta, 'anonymizer'):
                anonymizer = ingredient.meta.anonymizer

                # Build a FakerAnonymizer if we have a string
                if isinstance(anonymizer, basestring):

                    # Check for extra parameters
                    kwargs = {}
                    anonymizer_locale = getattr(
                        ingredient.meta, 'anonymizer_locale', None
                    )
                    anonymizer_postprocessor = getattr(
                        ingredient.meta, 'anonymizer_postprocessor', None
                    )
                    if anonymizer_postprocessor is not None:
                        kwargs['postprocessor'] = anonymizer_postprocessor
                    if anonymizer_locale is not None:
                        kwargs['locale'] = anonymizer_locale

                    anonymizer = FakerAnonymizer(anonymizer, **kwargs)

                # Strip out all FakerAnonymizers
                ingredient.formatters = [
                    f for f in ingredient.formatters
                    if not isinstance(f, FakerAnonymizer)
                ]
                if self._anonymize:
                    if ingredient.meta.anonymizer not in ingredient.formatters:
                        ingredient.formatters.append(anonymizer)
                else:
                    if ingredient.meta.anonymizer in ingredient.formatters:
                        ingredient.formatters.remove(anonymizer)
245598
protected function createMenuFile()
    {
        $file = $this->directory.'/menu.php';

        $contents = $this->getStub('menu');
        $this->laravel['files']->put($file, $contents);
        $this->line('<info>Menu file was created:</info> '.str_replace(base_path(), '', $file));
    }
866819
def register(self, name, path, plugin, description=None, final_words=None):
        
        if name in self.recipes.keys():
            raise RecipeExistsException("Recipe %s was already registered by %s" %
                                        (name, self.recipes["name"].plugin.name))

        self.recipes[name] = Recipe(name, path, plugin, description, final_words)
        self.__log.debug("Recipe %s registered by %s" % (name, plugin.name))
        return self.recipes[name]
773914
private function insertNewFileFunctions(iterable $new): void
    {
        // early return when there is nothing to be added
        if (0 === \count($new)) {
            return;
        }
        $table = $this->getTable();
        $db    = $this->getDb();

        foreach ($new as $file_function => $data) {
            $query      = $db->prepare(
                "INSERT INTO $table (function, added_at, changed_at) VALUES (:file_function, NOW(), :changed_at)"
            );
            $changed_at = $data->getChangedAt();
            $query->bindParam(":file_function", $file_function);
            $query->bindParam(":changed_at", $changed_at);
            $query->execute();
        }
    }
914170
def recipe(package, repository=None, depends_on=None, release=False,
           output_path=None, auto=False, overwrite=False, name=None):
    """"""
    upgrader = InvenioUpgrader()
    logger = upgrader.get_logger()

    try:
        path, found_repository = _upgrade_recipe_find_path(package)

        if output_path:
            path = output_path

        if not repository:
            repository = found_repository

        if not os.path.exists(path):
            raise RuntimeError("Path does not exists: %s" % path)
        if not os.path.isdir(path):
            raise RuntimeError("Path is not a directory: %s" % path)

        # Generate upgrade filename
        if release:
            filename = "%s_release_x_y_z.py" % repository
        else:
            filename = "%s_%s_%s.py" % (repository,
                                        date.today().strftime("%Y_%m_%d"),
                                        name or 'rename_me')

        # Check if generated repository name can be parsed
        test_repository = upgrader._parse_plugin_id(filename[:-3])
        if repository != test_repository:
            raise RuntimeError(
                "Generated repository name cannot be parsed. "
                "Please override it with --repository option."
            )

        upgrade_file = os.path.join(path, filename)

        if os.path.exists(upgrade_file) and not overwrite:
                raise RuntimeError(
                    "Could not generate upgrade - %s already exists."
                    % upgrade_file
                )

        # Determine latest installed upgrade
        if depends_on is None:
            depends_on = ["CHANGE_ME"]

            u = upgrader.latest_applied_upgrade(repository=repository)
            if u:
                depends_on = [u]

        # Write upgrade template file
        _write_template(
            upgrade_file, name or 'rename_me',
            depends_on, repository, auto=auto)

        logger.info("Created new upgrade %s" % upgrade_file)
    except RuntimeError as e:
        for msg in e.args:
            logger.error(unicode(msg))
        raise
1076418
def addFile(self, path, msg=""):
        """"""
        item = Item.from_path(repo=self.repo, path=path)
        self.addItem(item)