Exemple #1
0
func main() {

	ini := "./conf.base"
	inf, _ := config.Read(ini, config.ALTERNATIVE_COMMENT, config.ALTERNATIVE_SEPARATOR, false, true)
	// create new options
	base_data_dir, _ := inf.String("BASE", "tmp_data")
	base_target, _ := inf.String("BASE", "target")
	base_source, _ := inf.String("BASE", "source")
	base_weight, _ := inf.String("BASE", "weight")
	default_weight, _ := inf.String("IN", "weight")
	base_feature, _ := inf.String("BASE", "feature_base")
	tasks := ReadTasks("task.list")
	for idx, task := range tasks {
		task_inf := config.New(config.ALTERNATIVE_COMMENT, config.ALTERNATIVE_SEPARATOR, false, true)
		task_inf.Merge(inf)
		task_inf.AddOption("IN", "tag", task.tag)
		task_inf.AddOption("IN", "feature_dir", filepath.Join(base_feature, task.feature))
		task_inf.AddOption("IN", "env", task.env)
		task_inf.AddOption("IN", "weight", base_weight+default_weight)
		task_inf.AddOption("IN", "data_dir", filepath.Join(base_data_dir, task.env, task.tag))
		task_inf.AddOption("IN", "list", filepath.Join(base_source+task.list))
		task_inf.AddOption("OUT", "dae_dir", filepath.Join(base_target, task.env, task.tag))
		task_inf.WriteFile(fmt.Sprintf("./conf.ini.%d", idx), 0666, "")
	}
}
Exemple #2
0
// readTrashInfo reads in a info file and returns the original path of the file and date it was deleted.
func readTrashInfo(info string) (origPath, date string, err error) {
	c, err := config.Read(info, config.DEFAULT_COMMENT, config.DEFAULT_SEPARATOR, false, false)
	if err != nil {
		return
	}

	if !c.HasSection("Trash Info") {
		err = errors.New("not a valid trash info file")
		return
	}

	origPath, err = c.String("Trash Info", "Path")
	if err != nil {
		return
	}

	date, err = c.String("Trash Info", "DeletionDate")
	if err != nil {
		return
	}

	return
}
Exemple #3
0
func parser(s string) {
	var now = time.Now()
	var parses time.Time
	var parsee time.Time
	var ups time.Time
	var upe time.Time
	defer func() {
		naw := time.Now().Sub(now)
		nzw := parsee.Sub(parses)
		nkw := upe.Sub(ups)
		lg.Log(lg.TRACE, "Total:"+naw.String())
		lg.Log(lg.TRACE, "Parse:"+nzw.String())
		lg.Log(lg.TRACE, "Post:"+nkw.String())
	}()

	parses = time.Now()
	tmp, err := ioutil.ReadFile(s)
	if err != nil {
		lg.Log(lg.ERROR, err.Error())
		return
	}

	if *dbgmode {
		regfhd, err := ioutil.TempFile(os.TempDir(), "regp-raw-")
		if err != nil {
			lg.Log(lg.ERROR, "Failed to create debug raw file")
			lg.Log(lg.DEBUG, err.Error())
			return
		}
		lg.Log(lg.DEBUG, "Raw Dump File: "+regfhd.Name())
		lg.Log(lg.DEBUG, "Dumping body into raw file")
		fmt.Fprint(regfhd, tmp)
	}

	regfh, err := ioutil.TempFile(os.TempDir(), "regp-")
	if err != nil {
		lg.Log(lg.ERROR, "Failed to create temporary file")
		lg.Log(lg.DEBUG, err.Error())
		return
	}
	lg.Log(lg.DEBUG, "Temporary File: "+regfh.Name())
	defer func() {
		if regfh != nil && !*dbgmode {
			lg.Log(lg.DEBUG, "RMing temp file "+regfh.Name())
			os.Remove(regfh.Name())
			regfh = nil
		}
	}()

	/*tmpa, err := url.QueryUnescape(string(tmp))
	if err != nil {
		lg.Log(lg.DEBUG,err.Error())
		return
	}*/

	tmpb := strings.Replace(string(tmp), "\r", "", -1)

	if *dbgmode {
		regfhd, err := ioutil.TempFile(os.TempDir(), "regp-post-")
		if err != nil {
			lg.Log(lg.ERROR, "Failed to create debug post-processing dump file")
			lg.Log(lg.DEBUG, err.Error())
			return
		}
		lg.Log(lg.DEBUG, "Processed Dump File: "+regfhd.Name())
		lg.Log(lg.DEBUG, "Dumping tmpb into raw file")
		fmt.Fprint(regfhd, tmpb)
	}

	if strings.HasPrefix(string(tmpb), "REGEDIT4") {
		lg.Log(lg.DEBUG, "Found Windows Registry Editor string")
		fmt.Fprint(regfh, strings.Join(strings.Split(string(tmpb), "\n")[1:], "\n"))
	} else {
		lg.Log(lg.INFO, "Invalid .reg")
		lg.Log(lg.INFO, "Not a valid .reg file.")
		return
	}

	registry, err := config.Read(regfh.Name(), config.ALTERNATIVE_COMMENT, config.ALTERNATIVE_SEPARATOR, false, false)

	if err != nil {
		lg.Log(lg.DEBUG, "Not a valid .reg file.")
		lg.Log(lg.DEBUG, err.Error())
		return
	}

	lg.Log(lg.TRACE, "Entering print")
	n := 0
	if len(registry.Sections()) != 0 {
		n = 1
	}
	var aok bool = true
	var aok2 bool = true
	var buff = make(map[string]string)
	lg.Log(lg.TRACE, fmt.Sprint("n = ", n))
	for _, vv := range registry.Sections() {
		if vv == "DEFAULT" {
			continue
		}

		if strings.HasPrefix(vv, "-") { // Lol an actual .reg file
			lg.Log(lg.DEBUG, "- found")
			aok = false
			break
		} else if strings.Count(vv, "\"") > 2 {
			aok = false
			break
		}

		lg.Log(lg.DEBUG, vv)

		r, err := registry.Options(vv)
		if err != nil {
			lg.Log(lg.DEBUG, err.Error())
		}

		for _, vvv := range r {
			rr, err := registry.RawString(vv, vvv)
			if rr == "-" {
				lg.Log(lg.TRACE, "- found")
				aok = false // ya blew it
				// ya could'a had it all
				// but 'cha blew it
			}

			if err != nil {
				lg.Log(lg.DEBUG, err.Error())
			}

			lg.Log(lg.DEBUG, fmt.Sprintf("%v=%v\n", vvv, rr))
		}

		rs, _ := registry.RawString(vv, "@")
		var swiggy = swiki{Key: vv, Default: rs}
		for _, vvv := range r {
			rr, _ := registry.RawString(vv, vvv)
			var i = ParseType(rr)
			lg.Log(lg.DEBUG, i)
			swiggy.Values = append(swiggy.Values, swiki{Key: vvv, Type: GetName(i)})
		}
		buff[vv] = Render(swiggy)
	}

	if !aok {
		lg.Log(lg.DEBUG, "Not aok, terminating")
		return
	} else {
		lg.Log(lg.DEBUG, "aok = true, continuing")
	}
	parsee = time.Now()

	ups = time.Now()
	hkeywiki := url.URL{
		Scheme: "http",
		Host:   "hkey.n0v4.com",
		Path:   "/w/api.php",
	}
	api := mwapi.NewMWApi(hkeywiki)
	api.Login(USER, PASSWD)

	delete(buff, "DEFAULT")
	for k, v := range buff {
		lg.Log(lg.DEBUG, k)
		if aok2 {
			api.Login(USER, PASSWD)
			t := api.GetToken("edit")
			lg.Log(lg.TRACE, t.Tokens.Edittoken)
			params := url.Values{
				"action":     {"edit"},
				"title":      {k},
				"createonly": {"1"},
				"bot":        {"1"},
				"text":       {fmt.Sprintf("#REDIRECT [[%v]]", strings.Replace(k, "\\", "/", -1))},
				"token":      {t.Tokens.Edittoken},
			}
			resp := api.PostForm(params)
			if resp.StatusCode != 200 {
				rbody, _ := ioutil.ReadAll(resp.Body)
				lg.Log(lg.DEBUG, string(rbody))
			}
		}
		api.Login(USER, PASSWD)
		t := api.GetToken("edit")
		lg.Log(lg.TRACE, t.Tokens.Edittoken)

		params := url.Values{
			"action":     {"edit"},
			"title":      {strings.Replace(k, "\\", "/", -1)},
			"createonly": {"1"},
			"bot":        {"1"},
			"text":       {v},
			"token":      {t.Tokens.Edittoken},
		}