<commit_before>package main

import (
	"fmt"
	"os"
	"os/exec"
	"path/filepath"

	"github.com/gonuts/commander"
	"github.com/gonuts/flag"
	"github.com/gonuts/logger"
)

func lbpkr_make_cmd_self_upload_rpm() *commander.Command {
	cmd := &commander.Command{
		Run:       lbpkr_run_cmd_self_upload_rpm,
		UsageLine: "upload-rpm [options] <rpm-file>",
		Short:     "upload a RPM package of lbpkr",
		Long: `
upload-rpm uploads a previously created RPM package containing lbpkr.

ex:
 $ lbpkr self upload-rpm lbpkr-0.1.20140620-0.x86_64.rpm
`,
		Flag: *flag.NewFlagSet("lbpkr-self-upload-rpm", flag.ExitOnError),
	}
	cmd.Flag.Bool("v", false, "enable verbose mode")
	cmd.Flag.String("type", "lhcb", "config type (lhcb|atlas)")
	return cmd
}

func lbpkr_run_cmd_self_upload_rpm(cmd *commander.Command, args []string) error {
	var err error

	cfgtype := cmd.Flag.Lookup("type").Value.Get().(string)
	debug := cmd.Flag.Lookup("v").Value.Get().(bool)

	fname := ""
	switch len(args) {
	case 1:
		fname = args[0]
	default:
		cmd.Usage()
		return fmt.Errorf("lbpkr: invalid number of arguments. expected n=1. got=%d (%v)",
			len(args),
			args,
		)
	}

	//cfg := NewConfig(cfgtype)
	msg := logger.New("lbpkr")
	if debug {
		msg.SetLevel(logger.DEBUG)
	}

	msg.Infof("uploading [%s]...\n", fname)

	switch cfgtype {
	case "lhcb":
		rpmdir := "/afs/cern.ch/lhcb/distribution/rpm"
		dst := filepath.Join(rpmdir, "lhcb", fname)
		err = bincp(dst, fname)
		if err != nil {
			msg.Errorf("could not copy [%s] into [%s] (err=%v)\n", fname, dst, err)
			return err
		}

		msg.Debugf("update metadata...\n")
		updatecmd := filepath.Join(rpmdir, "update.sh")
		regen := exec.Command(updatecmd)
		regen.Dir = rpmdir
		regen.Stdout = os.Stdout
		regen.Stderr = os.Stderr
		regen.Stdin = os.Stdin
		err = regen.Run()
		if err != nil {
			msg.Errorf("could not regenerate metadata: %v\n", err)
			return err
		}
		msg.Debugf("update metadata... [ok]\n")

	default:
		return fmt.Errorf("lbpkr: config type [%s] not handled", cfgtype)
	}

	msg.Infof("uploading [%s]... [ok]\n", fname)
	return err
}<commit_msg>cmd-self-upload-rpm: cosmetics<commit_after>package main

import (
	"fmt"
	"os"
	"os/exec"
	"path/filepath"

	"github.com/gonuts/commander"
	"github.com/gonuts/flag"
	"github.com/gonuts/logger"
)

func lbpkr_make_cmd_self_upload_rpm() *commander.Command {
	cmd := &commander.Command{
		Run:       lbpkr_run_cmd_self_upload_rpm,
		UsageLine: "upload-rpm [options] <rpm-file>",
		Short:     "upload a RPM package of lbpkr",
		Long: `
upload-rpm uploads a previously created RPM package containing lbpkr.

ex:
 $ lbpkr self upload-rpm lbpkr-0.1.20140620-0.x86_64.rpm
`,
		Flag: *flag.NewFlagSet("lbpkr-self-upload-rpm", flag.ExitOnError),
	}
	cmd.Flag.Bool("v", false, "enable verbose mode")
	cmd.Flag.String("type", "lhcb", "config type (lhcb|atlas)")
	return cmd
}

func lbpkr_run_cmd_self_upload_rpm(cmd *commander.Command, args []string) error {
	var err error

	cfgtype := cmd.Flag.Lookup("type").Value.Get().(string)
	debug := cmd.Flag.Lookup("v").Value.Get().(bool)

	fname := ""
	switch len(args) {
	case 1:
		fname = args[0]
	default:
		cmd.Usage()
		return fmt.Errorf("lbpkr: invalid number of arguments. expected n=1. got=%d (%v)",
			len(args),
			args,
		)
	}

	//cfg := NewConfig(cfgtype)
	msg := logger.New("lbpkr")
	if debug {
		msg.SetLevel(logger.DEBUG)
	}

	msg.Infof("uploading [%s]...\n", fname)

	switch cfgtype {
	case "lhcb":
		rpmdir := "/afs/cern.ch/lhcb/distribution/rpm"
		dst := filepath.Join(rpmdir, "lhcb", fname)
		err = bincp(dst, fname)
		if err != nil {
			msg.Errorf("could not copy [%s] into [%s] (err=%v)\n", fname, dst, err)
			return err
		}

		msg.Debugf("updating metadata...\n")
		updatecmd := filepath.Join(rpmdir, "update.sh")
		regen := exec.Command(updatecmd)
		regen.Dir = rpmdir
		regen.Stdout = os.Stdout
		regen.Stderr = os.Stderr
		regen.Stdin = os.Stdin
		err = regen.Run()
		if err != nil {
			msg.Errorf("could not regenerate metadata: %v\n", err)
			return err
		}
		msg.Debugf("updating metadata... [ok]\n")

	default:
		return fmt.Errorf("lbpkr: config type [%s] not handled", cfgtype)
	}

	msg.Infof("uploading [%s]... [ok]\n", fname)
	return err
}
{'fraction_non_alphanumeric': 0.1710054931932171, 'fraction_numerical': 0.008598041557200859, 'mean_word_length': 3.742921857304643, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3476680', 'n_tokens_mistral': 1830, 'n_tokens_neox': 1674, 'n_words': 353}