// Downloader returns instance of current downloader func (context *AptlyContext) Downloader() aptly.Downloader { if context.downloader == nil { context.downloader = http.NewDownloader(context.Config().DownloadConcurrency, context.Progress()) } return context.downloader }
// Downloader returns instance of current downloader func (context *AptlyContext) Downloader() aptly.Downloader { if context.downloader == nil { var downloadLimit int64 limitFlag := context.flags.Lookup("download-limit") if limitFlag != nil { downloadLimit = limitFlag.Value.Get().(int64) } if downloadLimit == 0 { downloadLimit = context.Config().DownloadLimit } context.downloader = http.NewDownloader(context.Config().DownloadConcurrency, downloadLimit*1024, context.Progress()) } return context.downloader }
// InitContext initializes context with default settings func InitContext(cmd *commander.Command) error { var err error context.dependencyOptions = 0 if utils.Config.DepFollowSuggests || cmd.Flag.Lookup("dep-follow-suggests").Value.Get().(bool) { context.dependencyOptions |= debian.DepFollowSuggests } if utils.Config.DepFollowRecommends || cmd.Flag.Lookup("dep-follow-recommends").Value.Get().(bool) { context.dependencyOptions |= debian.DepFollowRecommends } if utils.Config.DepFollowAllVariants || cmd.Flag.Lookup("dep-follow-all-variants").Value.Get().(bool) { context.dependencyOptions |= debian.DepFollowAllVariants } if utils.Config.DepFollowSource || cmd.Flag.Lookup("dep-follow-source").Value.Get().(bool) { context.dependencyOptions |= debian.DepFollowSource } context.architecturesList = utils.Config.Architectures optionArchitectures := cmd.Flag.Lookup("architectures").Value.String() if optionArchitectures != "" { context.architecturesList = strings.Split(optionArchitectures, ",") } context.progress = console.NewProgress() context.progress.Start() context.downloader = http.NewDownloader(utils.Config.DownloadConcurrency, context.progress) context.database, err = database.OpenDB(filepath.Join(utils.Config.RootDir, "db")) if err != nil { return fmt.Errorf("can't open database: %s", err) } context.packagePool = files.NewPackagePool(utils.Config.RootDir) context.publishedStorage = files.NewPublishedStorage(utils.Config.RootDir) return nil }
// InitContext initializes context with default settings func InitContext(cmd *commander.Command) error { var err error context.dependencyOptions = 0 if utils.Config.DepFollowSuggests || cmd.Flag.Lookup("dep-follow-suggests").Value.Get().(bool) { context.dependencyOptions |= debian.DepFollowSuggests } if utils.Config.DepFollowRecommends || cmd.Flag.Lookup("dep-follow-recommends").Value.Get().(bool) { context.dependencyOptions |= debian.DepFollowRecommends } if utils.Config.DepFollowAllVariants || cmd.Flag.Lookup("dep-follow-all-variants").Value.Get().(bool) { context.dependencyOptions |= debian.DepFollowAllVariants } if utils.Config.DepFollowSource || cmd.Flag.Lookup("dep-follow-source").Value.Get().(bool) { context.dependencyOptions |= debian.DepFollowSource } context.architecturesList = utils.Config.Architectures optionArchitectures := cmd.Flag.Lookup("architectures").Value.String() if optionArchitectures != "" { context.architecturesList = strings.Split(optionArchitectures, ",") } context.progress = console.NewProgress() context.progress.Start() context.downloader = http.NewDownloader(utils.Config.DownloadConcurrency, context.progress) context.database, err = database.OpenDB(filepath.Join(utils.Config.RootDir, "db")) if err != nil { return fmt.Errorf("can't open database: %s", err) } context.packagePool = files.NewPackagePool(utils.Config.RootDir) context.publishedStorage = files.NewPublishedStorage(utils.Config.RootDir) if aptly.EnableDebug { cpuprofile := cmd.Flag.Lookup("cpuprofile").Value.String() if cpuprofile != "" { context.fileCPUProfile, err = os.Create(cpuprofile) if err != nil { return err } pprof.StartCPUProfile(context.fileCPUProfile) } memprofile := cmd.Flag.Lookup("memprofile").Value.String() if memprofile != "" { context.fileMemProfile, err = os.Create(memprofile) if err != nil { return err } } memstats := cmd.Flag.Lookup("memstats").Value.String() if memstats != "" { interval := cmd.Flag.Lookup("meminterval").Value.Get().(time.Duration) context.fileMemStats, err = os.Create(memstats) if err != nil { return err } context.fileMemStats.WriteString("# Time\tHeapSys\tHeapAlloc\tHeapIdle\tHeapReleased\n") go func() { var stats runtime.MemStats start := time.Now().UnixNano() for { runtime.ReadMemStats(&stats) if context.fileMemStats != nil { context.fileMemStats.WriteString(fmt.Sprintf("%d\t%d\t%d\t%d\t%d\n", (time.Now().UnixNano()-start)/1000000, stats.HeapSys, stats.HeapAlloc, stats.HeapIdle, stats.HeapReleased)) time.Sleep(interval) } else { break } } }() } } return nil }