Best Venom code snippet using readfile.Run
main_test.go
Source:main_test.go
...10 "path/filepath"11 "runtime"12 "testing"13)14func RunInTmpDir(run func()) {15 dir, err := ioutil.TempDir("", "")16 if err != nil {17 log.Fatal(err)18 }19 current, err := os.Getwd()20 if err != nil {21 panic(err)22 }23 err = os.Chdir(dir)24 if err != nil {25 panic(err)26 }27 run()28 defer func() {29 os.RemoveAll(dir) // clean up30 os.Chdir(current)31 }()32}33func RunInTmpRepo(run func()) {34 commands := []string{35 "git init",36 "git config --local user.email \"you@example.com\"",37 "git config --local user.name \"Your Name\"",38 }39 RunInTmpDir(func() {40 for _, command := range commands {41 err := exec.Command("sh", "-c", command).Run()42 if err != nil {43 panic(err)44 }45 }46 run()47 })48}49func CommitFile(name string, content string) {50 err := os.MkdirAll(filepath.Dir(name), os.ModePerm)51 if err != nil {52 panic(err)53 }54 err = ioutil.WriteFile(name, []byte(content), os.ModePerm)55 if err != nil {56 panic(err)57 }58 err = exec.Command("git", "add", ".").Run()59 if err != nil {60 panic(err)61 }62 err = exec.Command("git", "commit", "-m", fmt.Sprintf("\"Add\" %s", name)).Run()63 if err != nil {64 panic(err)65 }66}67func GitGsubPath() string {68 _, filename, _, _ := runtime.Caller(0)69 return filepath.Clean(fmt.Sprintf("%s/../bin/git-gsub", filename))70}71func RunGitGsub(args ...string) ([]byte, error) {72 var out []byte73 var err error74 _, e2e := os.LookupEnv("E2E")75 if e2e {76 out, err = exec.Command(GitGsubPath(), args...).Output()77 } else {78 outStream, errStream := new(bytes.Buffer), new(bytes.Buffer)79 cli := &CLI{outStream: outStream, errStream: errStream}80 exitcode := cli.Run(args)81 if exitcode != 0 {82 err = errors.New(errStream.String())83 }84 out = outStream.Bytes()85 }86 return out, err87}88func TestVersion(t *testing.T) {89 out, err := RunGitGsub("--version")90 if err != nil {91 t.Errorf("Command failed: %s", err)92 }93 if string(out) != "v0.1.1\n" {94 t.Errorf("Failed: %s", string(out))95 }96}97func TestSimpleSubstitution(t *testing.T) {98 RunInTmpRepo(func() {99 CommitFile("README.md", "Git Subversion Bzr")100 _, err := RunGitGsub("Bzr", "Mercurial")101 if err != nil {102 t.Errorf("Command failed: %s", err)103 }104 dat, _ := ioutil.ReadFile("./README.md")105 if string(dat) != "Git Subversion Mercurial" {106 t.Errorf("Failed: %s", string(dat))107 }108 })109}110func TestSimpleSubstitutionManyFiles(t *testing.T) {111 RunInTmpRepo(func() {112 CommitFile("README_1.md", "Git Subversion Bzr")113 CommitFile("README_2.md", "Git Subversion Bzr")114 CommitFile("README_3.md", "Git Subversion Bzr")115 CommitFile("README_4.md", "Git Subversion Bzr")116 CommitFile("README_5.md", "Git Subversion Bzr")117 CommitFile("README_6.md", "Git Subversion Bzr")118 _, err := RunGitGsub("Bzr", "Mercurial")119 if err != nil {120 t.Errorf("Command failed: %s", err)121 }122 dat, _ := ioutil.ReadFile("./README_1.md")123 if string(dat) != "Git Subversion Mercurial" {124 t.Errorf("Failed: %s", string(dat))125 }126 })127}128func TestSubstitutionWithPath(t *testing.T) {129 RunInTmpRepo(func() {130 CommitFile("README.md", "Git Subversion Bzr")131 CommitFile("foo/git", "Git Subversion Bzr")132 CommitFile("bar/git", "Git Subversion Bzr")133 _, err := RunGitGsub("Git", "Svn", "foo")134 if err != nil {135 t.Errorf("Command failed: %s", err)136 }137 dat, _ := ioutil.ReadFile("./README.md")138 if string(dat) != "Git Subversion Bzr" {139 t.Errorf("Failed: %s", string(dat))140 }141 dat, _ = ioutil.ReadFile("./foo/git")142 if string(dat) != "Svn Subversion Bzr" {143 t.Errorf("Failed: %s", string(dat))144 }145 })146}147func TestSubstitutionWithCaseConversion(t *testing.T) {148 RunInTmpRepo(func() {149 CommitFile("README.md", "GitGsub git_gsub git-gsub")150 _, err := RunGitGsub("--camel", "--kebab", "--snake", "git-gsub", "svn-gsub")151 if err != nil {152 t.Errorf("Command failed: %s", err)153 }154 dat, _ := ioutil.ReadFile("./README.md")155 if string(dat) != "SvnGsub svn_gsub svn-gsub" {156 t.Errorf("Failed: %s", string(dat))157 }158 })159}160func TestSubstitutionOfAllUnderscoredPhraseWithCaseConversion(t *testing.T) {161 RunInTmpRepo(func() {162 CommitFile("README.md", "activerecord")163 _, err := RunGitGsub("activerecord", "inactiverecord", "--kebab", "--snake", "--camel")164 if err != nil {165 t.Errorf("Command failed: %s", err)166 }167 dat, _ := ioutil.ReadFile("./README.md")168 if string(dat) != "inactiverecord" {169 t.Errorf("Failed: %s", string(dat))170 }171 })172}173func TestOptionsCanBePutAfterArguments(t *testing.T) {174 RunInTmpRepo(func() {175 CommitFile("README.md", "GitGsub git_gsub git-gsub")176 _, err := RunGitGsub("git-gsub", "svn-gsub", "--camel", "--kebab", "--snake")177 if err != nil {178 t.Errorf("Command failed: %s", err)179 }180 dat, _ := ioutil.ReadFile("./README.md")181 if string(dat) != "SvnGsub svn_gsub svn-gsub" {182 t.Errorf("Failed: %s", string(dat))183 }184 })185}186func TestSubstitutionWithFixedStringOption(t *testing.T) {187 RunInTmpRepo(func() {188 CommitFile("hello.rb", "puts('hello')")189 _, err := RunGitGsub("--fgrep", "(", " ")190 if err != nil {191 t.Errorf("Command failed: %s", err)192 }193 _, err = RunGitGsub("-F", ")", "")194 if err != nil {195 t.Errorf("Command failed: %s", err)196 }197 dat, _ := ioutil.ReadFile("./hello.rb")198 if string(dat) != "puts 'hello'" {199 t.Errorf("Failed: %s", string(dat))200 }201 })202}203func TestEscape(t *testing.T) {204 RunInTmpRepo(func() {205 CommitFile("README.md", `<h1 class="foo">`)206 _, err := RunGitGsub(`<h1 class="foo">`, `<h1 class="bar">`)207 if err != nil {208 t.Errorf("Command failed: %s", err)209 }210 dat, _ := ioutil.ReadFile("./README.md")211 if string(dat) != `<h1 class="bar">` {212 t.Errorf("Failed: %s", string(dat))213 }214 })215}216func TestAtMark(t *testing.T) {217 RunInTmpRepo(func() {218 CommitFile("README.md", "foo@example.com")219 _, err := RunGitGsub("foo@example.com", "bar@example.com")220 if err != nil {221 t.Errorf("Command failed: %s", err)222 }223 dat, _ := ioutil.ReadFile("./README.md")224 if string(dat) != "bar@example.com" {225 t.Errorf("Failed: %s", string(dat))226 }227 })228}229func TestConsequesingAtMark(t *testing.T) {230 RunInTmpRepo(func() {231 CommitFile("README.md", "foo@example.com")232 _, err := RunGitGsub("foo@example.com", "bar@@example.com")233 if err != nil {234 t.Errorf("Command failed: %s", err)235 }236 dat, _ := ioutil.ReadFile("./README.md")237 if string(dat) != "bar@@example.com" {238 t.Errorf("Failed: %s", string(dat))239 }240 })241}242func TestDoubleQuoteToSingleQuote(t *testing.T) {243 RunInTmpRepo(func() {244 CommitFile("README.md", `hello this is "git"`)245 _, err := RunGitGsub(`"git"`, `'svn'`)246 if err != nil {247 t.Errorf("Command failed: %s", err)248 }249 dat, _ := ioutil.ReadFile("./README.md")250 if string(dat) != "hello this is 'svn'" {251 t.Errorf("Failed: %s", string(dat))252 }253 })254}255func TestSingleQuoteToDoubleQuote(t *testing.T) {256 RunInTmpRepo(func() {257 CommitFile("README.md", `hello this is 'git'`)258 _, err := RunGitGsub(`'git'`, `"svn"`)259 if err != nil {260 t.Errorf("Command failed: %s", err)261 }262 dat, _ := ioutil.ReadFile("./README.md")263 if string(dat) != `hello this is "svn"` {264 t.Errorf("Failed: %s", string(dat))265 }266 })267}268func TestBracket(t *testing.T) {269 RunInTmpRepo(func() {270 CommitFile("README.md", `{git{svn}}`)271 _, err := RunGitGsub("{git{svn}}", "{hg{svn}}")272 if err != nil {273 t.Errorf("Command failed: %s", err)274 }275 dat, _ := ioutil.ReadFile("./README.md")276 if string(dat) != "{hg{svn}}" {277 t.Errorf("Failed: %s", string(dat))278 }279 })280}281func TestSubmatch(t *testing.T) {282 RunInTmpRepo(func() {283 CommitFile("README.md", "git-foo-1 git-bar-22 git-baz-3")284 _, err := RunGitGsub(`git-([a-z]+)-([\d]{1,2})`, `$2-$1`)285 if err != nil {286 t.Errorf("Command failed: %s", err)287 }288 dat, _ := ioutil.ReadFile("./README.md")289 if string(dat) != "1-foo 22-bar 3-baz" {290 t.Errorf("Failed: %s", string(dat))291 }292 })293}294func TestSubstituteToEmptyString(t *testing.T) {295 RunInTmpRepo(func() {296 CommitFile("README.md", "Git Svn Hg")297 _, err := RunGitGsub("Svn ", "")298 if err != nil {299 t.Errorf("Command failed: %s", err)300 }301 dat, _ := ioutil.ReadFile("./README.md")302 if string(dat) != "Git Hg" {303 t.Errorf("Failed: %s", string(dat))304 }305 })306}307func TestUTF8Filename(t *testing.T) {308 RunInTmpRepo(func() {309 CommitFile("ããã§ã.txt", "ããã§ã")310 _, err := RunGitGsub("ã§ã", "ã ã")311 if err != nil {312 t.Errorf("Command failed: %s", err)313 }314 dat, _ := ioutil.ReadFile("./ããã§ã.txt")315 if string(dat) != "ããã ã" {316 t.Errorf("Failed: %s", string(dat))317 }318 })319}320func TestSimpleRename(t *testing.T) {321 RunInTmpRepo(func() {322 CommitFile("README-git_gsub.md", "GitGsub git_gsub git-gsub")323 _, err := RunGitGsub("--snake", "--rename", "GitGsub", "SvnGsub")324 if err != nil {325 t.Errorf("Command failed: %s", err)326 }327 dat, _ := ioutil.ReadFile("./README-svn_gsub.md")328 if string(dat) != "SvnGsub svn_gsub git-gsub" {329 t.Errorf("Failed: %s", string(dat))330 }331 })332}333func TestRuby(t *testing.T) {334 RunInTmpRepo(func() {335 CommitFile("./foo_bar/baz.rb", "module FooBar::Baz; foo_bar baz # foo_bar/baz; end")336 _, err := RunGitGsub("--ruby", "--rename", "FooBar::Baz", "QuxQuux::Quuz")337 if err != nil {338 t.Errorf("Command failed: %s", err)339 }340 dat, _ := ioutil.ReadFile("./qux_quux/quuz.rb")341 if string(dat) != "module QuxQuux::Quuz; foo_bar baz # qux_quux/quuz; end" {342 t.Errorf("Failed: %s", string(dat))343 }344 })345}346func TestAll(t *testing.T) {347 RunInTmpRepo(func() {348 CommitFile("./foo_bar.rb", "module FooBar; foo_bar foo-bar; end")349 _, err := RunGitGsub("--all", "--rename", "FooBar", "BazQux")350 if err != nil {351 t.Errorf("Command failed: %s", err)352 }353 dat, _ := ioutil.ReadFile("./baz_qux.rb")354 if string(dat) != "module BazQux; baz_qux baz-qux; end" {355 t.Errorf("Failed: %s", string(dat))356 }357 })358}359func TestAllDoesntImplyRuby(t *testing.T) {360 RunInTmpRepo(func() {361 CommitFile("./foo_bar/baz.rb", "module FooBar::Baz; foo_bar baz # foo_bar/baz; end")362 _, err := RunGitGsub("--all", "--rename", "FooBar::Baz", "QuxQuux::Quuz")363 if err != nil {364 t.Errorf("Command failed: %s", err)365 }366 dat, _ := ioutil.ReadFile("./foo_bar/baz.rb")367 if string(dat) != "module QuxQuux::Quuz; foo_bar baz # foo_bar/baz; end" {368 t.Errorf("Failed: %s", string(dat))369 }370 })371}372func TestAllPlusRuby(t *testing.T) {373 RunInTmpRepo(func() {374 CommitFile("./foo_bar/baz.rb", "module FooBar::Baz; foo_bar baz # foo_bar/baz; end")375 _, err := RunGitGsub("--all", "--ruby", "--rename", "FooBar::Baz", "QuxQuux::Quuz")376 if err != nil {377 t.Errorf("Command failed: %s", err)378 }379 dat, _ := ioutil.ReadFile("./qux_quux/quuz.rb")380 if string(dat) != "module QuxQuux::Quuz; foo_bar baz # qux_quux/quuz; end" {381 t.Errorf("Failed: %s", string(dat))382 }383 })384}385func TestRenameWithPath(t *testing.T) {386 RunInTmpRepo(func() {387 CommitFile("foo/git.rb", "puts 'Git'")388 CommitFile("bar/git.rb", "puts 'Git'")389 _, err := RunGitGsub("git", "svn", "bar", "--rename")390 if err != nil {391 t.Errorf("Command failed: %s", err)392 }393 dat, _ := ioutil.ReadFile("./foo/git.rb")394 if string(dat) != "puts 'Git'" {395 t.Errorf("Failed: %s", string(dat))396 }397 dat, _ = ioutil.ReadFile("./bar/svn.rb")398 if string(dat) != "puts 'Git'" {399 t.Errorf("Failed: %s", string(dat))400 }401 })402}403func TestRenameWithSubmatch(t *testing.T) {404 RunInTmpRepo(func() {405 CommitFile("git/lib.rb", "puts 'Git'")406 CommitFile("svn/lib.rb", "puts 'Git'")407 CommitFile("bzr/lib.rb", "puts 'Git'")408 _, err := RunGitGsub("--rename", "(git|svn|bzr)/lib", "lib/$1")409 if err != nil {410 t.Errorf("Command failed: %s", err)411 }412 for _, path := range []string{"git", "svn", "bzr"} {413 files, _ := ioutil.ReadDir(path)414 if len(files) != 0 {415 t.Errorf("Failed: %d", len(files))416 }417 }418 files, _ := ioutil.ReadDir("./lib")419 if len(files) != 3 {420 t.Errorf("Failed: %d", len(files))421 }422 for _, path := range []string{"lib/git.rb", "lib/svn.rb", "lib/bzr.rb"} {423 dat, _ := ioutil.ReadFile(path)424 if string(dat) != "puts 'Git'" {425 t.Errorf("Failed: %s", string(dat))426 }427 }428 })429}430func TestRenameWithSpaceInPath(t *testing.T) {431 RunInTmpRepo(func() {432 CommitFile("git/l b.rb", "puts 'Git'")433 _, err := RunGitGsub("--rename", "l b.rb", "lib.rb")434 if err != nil {435 t.Errorf("Command failed: %s", err)436 }437 _, err = ioutil.ReadFile("git/lib.rb")438 if err != nil {439 t.Errorf("Failed")440 }441 })442}...
stats.go
Source:stats.go
1package ethos2import (3 "io/ioutil"4 "os"5 "os/exec"6 "strconv"7 "strings"8 "time"9 "github.com/ka2n/masminer/machine/metal/gpu/gpustat"10)11// Stat : gpuã®æ
å ±ãethOSã®APIã§åå¾ãã¾ã12func Stat() ([]gpustat.GPUStat, error) {13 return nil, nil14}15func GPUs() (string, error) {16 c, err := readFile("/var/run/ethos/gpucount.file")17 if err != nil {18 return "", err19 }20 return c, nil21}22func Driver() (string, error) {23 c, err := runScript(`/opt/ethos/sbin/ethos-readconf driver`)24 if err != nil {25 return "", err26 }27 return c, nil28}29func Miner() (string, error) {30 c, err := runScript(`/opt/ethos/sbin/ethos-readconf miner`)31 if err != nil {32 return "", err33 }34 return c, nil35}36func Defunct() (int64, error) {37 c, err := readFile("/var/run/ethos/defunct.file")38 if err != nil {39 return -1, err40 }41 return strconv.ParseInt(c, 10, 64)42}43func Off() (string, error) {44 c, err := runScript(`/opt/ethos/sbin/ethos-readconf off`)45 if err != nil {46 return "", err47 }48 return c, nil49}50func Allowed() (int64, error) {51 c, err := readFile("/opt/ethos/etc/allow.file")52 if err != nil {53 return -1, err54 }55 return strconv.ParseInt(c, 10, 64)56}57func Overheat() (int64, error) {58 c, err := readFile("/var/run/ethos/overheat.file")59 if err != nil {60 return -1, err61 }62 return strconv.ParseInt(c, 10, 64)63}64func PoolInfo() (string, error) {65 c, err := runScript(`cat /home/ethos/local.conf | grep -v '^#' | egrep -i 'pool|wallet|proxy'`)66 if err != nil {67 return "", err68 }69 return c, nil70}71func Pool() (string, error) {72 c, err := runScript(`/opt/ethos/sbin/ethos-readconf proxypool1`)73 if err != nil {74 return "", err75 }76 return c, nil77}78func MinerVersion() (string, error) {79 c, err := runScript(`cat /var/run/ethos/miner.versions | grep '$miner ' | cut -d" " -f2 | head -1`)80 if err != nil {81 return "", err82 }83 return c, nil84}85func BootMode() (string, error) {86 c, err := runScript(`/opt/ethos/sbin/ethos-readdata bootmode`)87 if err != nil {88 return "", err89 }90 return c, nil91}92func RackLoc() (string, error) {93 c, err := runScript(`/opt/ethos/sbin/ethos-readconf loc`)94 if err != nil {95 return "", err96 }97 return c, nil98}99func Motherboard() (string, error) {100 c, err := readFile("/var/run/ethos/motherboard.file")101 if err != nil {102 return "", err103 }104 return c, nil105}106func Rofs() (time.Duration, error) {107 c, err := readFile("/opt/ethos/etc/check-ro.file")108 if err != nil {109 return -1, err110 }111 i, err := strconv.ParseInt(c, 10, 64)112 if err != nil {113 return -1, err114 }115 t := time.Unix(i, 0)116 return time.Now().Sub(t), nil117}118func DriveName() (string, error) {119 c, err := runScript(`/opt/ethos/sbin/ethos-readdata driveinfo`)120 if err != nil {121 return "", err122 }123 return c, nil124}125func Temp() (string, error) {126 c, err := runScript(`/opt/ethos/sbin/ethos-readdata temps`)127 if err != nil {128 return "", err129 }130 return c, nil131}132func Version() (string, error) {133 c, err := readFile("/opt/ethos/etc/version")134 if err != nil {135 return "", err136 }137 return c, nil138}139func MinerSecs() (int64, error) {140 miner, err := Miner()141 if err != nil {142 return -1, err143 }144 c, err := runScript(`ps -eo pid,etime,command | grep ` + miner + ` | grep -v grep | head -1 | awk '{print $2}' | /opt/ethos/bin/convert_time.awk`)145 if err != nil {146 return -1, err147 }148 return strconv.ParseInt(c, 10, 64)149}150func AdlError() (string, error) {151 c, err := readFile("/var/run/ethos/adl_error.file")152 if err != nil {153 return "", err154 }155 return c, nil156}157func ProxyProblem() (string, error) {158 c, err := readFile("/var/run/ethos/proxy_error.file")159 if err != nil {160 return "", err161 }162 return c, nil163}164func Updating() (string, error) {165 c, err := readFile("/var/run/ethos/updating.file")166 if err != nil {167 return "", err168 }169 return c, nil170}171func ConnectedDisplays() (string, error) {172 c, err := runScript(`/opt/ethos/sbin/ethos-readdata connecteddisplays`)173 if err != nil {174 return "", err175 }176 return c, nil177}178func Resolution() (string, error) {179 c, err := runScript(`/opt/ethos/sbin/ethos-readdata resolution`)180 if err != nil {181 return "", err182 }183 return c, nil184}185func Gethelp() (string, error) {186 c, err := runScript(`tail -1 /var/log/gethelp.log`)187 if err != nil {188 return "", err189 }190 return c, nil191}192func ConfigError() (string, error) {193 c, err := runScript(`cat /var/run/ethos/config_mode.file`)194 if err != nil {195 return "", err196 }197 return c, nil198}199func SendRemote() (string, error) {200 c, err := runScript(`cat /var/run/ethos/send_remote.file`)201 if err != nil {202 return "", err203 }204 return c, nil205}206func Autorebooted() (string, error) {207 c, err := runScript(`cat /opt/ethos/etc/autorebooted.file`)208 if err != nil {209 return "", err210 }211 return c, nil212}213func Status() (string, error) {214 c, err := runScript(`cat /var/run/ethos/status.file`)215 if err != nil {216 return "", err217 }218 return c, nil219}220func SelectedGPUs() (string, error) {221 c, err := runScript(`/opt/ethos/sbin/ethos-readconf selectedgpus`)222 if err != nil {223 return "", err224 }225 return c, nil226}227func FanRPM() (string, error) {228 c, err := runScript(`/opt/ethos/sbin/ethos-readdata fanrpm | xargs | tr -s ' '`)229 if err != nil {230 return "", err231 }232 return c, nil233}234func FanPercent() (string, error) {235 c, err := runScript(`/opt/ethos/sbin/ethos-readdata fan | xargs | tr -s ' '`)236 if err != nil {237 return "", err238 }239 return c, nil240}241func Hash() (float64, error) {242 c, err := runScript(`tail -10 /var/run/ethos/miner_hashes.file | sort -V | tail -1 | tr ' ' '\n' | awk '{sum += $1} END {print sum}'`)243 if err != nil {244 return -1, err245 }246 return strconv.ParseFloat(c, 64)247}248func MinerHashes() (string, error) {249 c, err := runScript(`tail -10 /var/run/ethos/miner_hashes.file | sort -V | tail -1`)250 if err != nil {251 return "", err252 }253 return c, nil254}255func GPUModels() (string, error) {256 c, err := readFile("/var/run/ethos/gpulist.file")257 if err != nil {258 return "", err259 }260 return c, nil261}262func Bioses() (string, error) {263 c, err := runScript(`/opt/ethos/sbin/ethos-readdata bios | xargs | tr -s ' '`)264 if err != nil {265 return "", err266 }267 return c, err268}269func DefaultCore() (string, error) {270 c, err := readFile("/var/run/ethos/defaultcore.file")271 if err != nil {272 return "", err273 }274 return c, nil275}276func DefaultMem() (string, error) {277 c, err := readFile("/var/run/ethos/defaultmem.file")278 if err != nil {279 return "", err280 }281 return c, nil282}283func VRAMSize() (string, error) {284 c, err := readFile("/var/run/ethos/vrams.file")285 if err != nil {286 return "", err287 }288 return c, nil289}290func Core() (string, error) {291 c, err := runScript(`/opt/ethos/sbin/ethos-readdata core | xargs | tr -s ' '`)292 if err != nil {293 return "", err294 }295 return c, nil296}297func Mem() (string, error) {298 c, err := runScript(`/opt/ethos/sbin/ethos-readdata mem | xargs | tr -s ' '`)299 if err != nil {300 return "", err301 }302 return c, nil303}304func MemStates() (string, error) {305 c, err := runScript(`/opt/ethos/sbin/ethos-readdata memstate | xargs | tr -s ' '`)306 if err != nil {307 return "", err308 }309 return c, nil310}311func MemInfo() (string, error) {312 c, err := readFile("/var/run/ethos/meminfo.file")313 if err != nil {314 return "", err315 }316 return c, nil317}318func Voltage() (string, error) {319 c, err := runScript(`/opt/ethos/sbin/ethos-readdata voltage | xargs | tr -s ' '`)320 if err != nil {321 return "", err322 }323 return c, nil324}325func OverheatedGPU() (string, error) {326 c, err := readFile("/var/run/ethos/overheatedgpu.file")327 if err != nil {328 return "", err329 }330 return c, nil331}332func Throttled() (string, error) {333 c, err := readFile("/var/run/ethos/throttled.file")334 if err != nil {335 return "", err336 }337 return c, nil338}339func Powertune() (string, error) {340 c, err := runScript(`/opt/ethos/sbin/ethos-readdata powertune | xargs | tr -s ' '`)341 if err != nil {342 return "", err343 }344 return c, nil345}346func runScript(cmdStr string) (string, error) {347 out, err := exec.Command("bash", "-c", cmdStr).Output()348 return strings.TrimSpace(string(out)), err349}350func readFile(path string) (string, error) {351 f, err := os.Open(path)352 if err != nil {353 return "", err354 }355 defer f.Close()356 b, err := ioutil.ReadAll(f)357 if err != nil {358 return "", err359 }360 return strings.TrimSpace(string(b)), nil361}...
cloudController.go
Source:cloudController.go
...19 })20}2122// å¨çº¿å®¹å¨23func (dc CloudController) ContainerListRunning(c *gin.Context) {24 // è·å容å¨ä¿¡æ¯25 GetContainerInfoCmd := "sudo chmod +x ./sh/getContainerStatus.sh && sudo /bin/bash ./sh/getContainerStatus.sh"26 _, _, err := cmd.ShellOut(GetContainerInfoCmd)27 if err != nil {28 errOut := "èæ¬ [getContainerStatus.sh] æ§è¡å¤±è´¥ï¼è¯·æ£æ¥ã"29 tools.LogFileErr(errOut)30 fmt.Println(err.Error())31 }3233 containerRunNamePath := "./textfile/containerName.txt"34 containerRunName, err := tools.ReadFile(containerRunNamePath)35 if len(containerRunName) == 0 || err != nil {36 errOut := "没æè·åå°å®¹å¨åï¼è¯·ç»å½å°æå¡å¨æ£æ¥ã"37 tools.LogFileErr(errOut)38 }3940 containerRunIdPath := "./textfile/dockerRunId.txt"41 containerRunId, err := tools.ReadFile(containerRunIdPath)42 if len(containerRunId) == 0 || err != nil {43 errOut := "没æè·åå°å®¹å¨IDï¼è¯·ç»å½å°æå¡å¨æ£æ¥ã"44 tools.LogFileErr(errOut)45 }4647 // éåContainerStatus48 containerStatusPath := "./textfile/dockerStatus.txt"49 containerStatus, err := tools.ReadFile(containerStatusPath)50 if len(containerStatus) == 0 || err != nil {51 errOut := "没æè·åå°å®¹å¨è¿è¡ç¶æï¼è¯·ç»å½å°æå¡å¨æ£æ¥ã"52 tools.LogFileErr(errOut)53 }5455 // å¨çº¿å®¹å¨æä½ éå¯ãåæ¢ãå é¤ãæ¥å¿56 //éå¯57 containerRunResPath := "./textfile/dockerRunRes.txt"58 containerRunRes, err := tools.ReadFile(containerRunResPath)59 if len(containerRunRes) == 0 || err != nil {60 errOut := "没æè·åå°å®¹å¨ï¼Ruuningç¶æï¼éå¯æé®ï¼è¯·æ£æ¥ã"61 tools.ReadFile(errOut)62 }63 // åæ¢64 containerRunStopPath := "./textfile/dockerRunStop.txt"65 containerRunStop, err := tools.ReadFile(containerRunStopPath)66 if len(containerRunStop) == 0 || err != nil {67 errOut := "没æè·åå°å®¹å¨ï¼Ruuningç¶æï¼åæ¢æé®ï¼è¯·æ£æ¥ã"68 tools.ReadFile(errOut)69 }70 // å é¤71 containerRunDelPath := "./textfile/dockerRunDel.txt"72 containerRunDel, err := tools.ReadFile(containerRunDelPath)73 if len(containerRunDel) == 0 || err != nil {74 errOut := "没æè·åå°å®¹å¨ï¼Ruuningç¶æï¼å é¤æé®ï¼è¯·æ£æ¥ã"75 tools.ReadFile(errOut)76 }77 //æ¥å¿78 containerRunLogPath := "./textfile/dockerRunLog.txt"79 containerRunLog, err := tools.ReadFile(containerRunLogPath)80 if len(containerRunLog) == 0 || err != nil {81 errOut := "没æè·åå°å®¹å¨ï¼Ruuningç¶æï¼æ¥å¿æé®ï¼è¯·æ£æ¥ã"82 tools.ReadFile(errOut)83 }8485 c.HTML(http.StatusOK, "view/cloud/containerListRunning.html", gin.H{86 "title": "å¨çº¿å®¹å¨",87 "containerRunName": containerRunName,88 "containerRunId": containerRunId,89 "containerStatus": containerStatus,90 "containerRunRes": containerRunRes,91 "containerRunStop": containerRunStop,92 "containerRunDel": containerRunDel,93 "containerRunLog": containerRunLog,94 })95}9697// 离线容å¨98func (dc CloudController) ContainerListExit(c *gin.Context) {99 containerExitNamePath := "./textfile/containerExitName.txt"100 containerExitName, err := tools.ReadFile(containerExitNamePath)101 if len(containerExitName) == 0 || err != nil {102 errOut := "没æè·åå°å®¹å¨åï¼è¯·ç»å½å°æå¡å¨æ£æ¥ã"103 tools.LogFileErr(errOut)104 }105106 containerExitIdPath := "./textfile/dockerExitId.txt"107 containerExitId, err := tools.ReadFile(containerExitIdPath)
...
Run
Using AI Code Generation
1import (2func main() {3 file, err := os.Open("file.txt")4 if err != nil {5 fmt.Println(err)6 }7 defer file.Close()8 buf := make([]byte, 1024)9 n, err := file.Read(buf)10 if err != nil {11 fmt.Println(err)12 }13 fmt.Println(string(buf[:n]))14}15func ReadFile(filename string) ([]byte, error)16import (17func main() {18 data, err := ioutil.ReadFile("file.txt")19 if err != nil {20 fmt.Println(err)21 }22 fmt.Println(string(data))23}
Run
Using AI Code Generation
1import (2func main() {3 f, err := os.Open("readfile.go")4 if err != nil {5 fmt.Println(err)6 }7 r := bufio.NewReader(f)8 for {9 line, err := r.ReadString('10 if err != nil {11 }12 fmt.Print(line)13 }14}15import (16func main() {17 f, err := os.Open("readfile.go")18 if err != nil {19 fmt.Println(err)20 }21 r := bufio.NewReader(f)22 for {23 line, err := r.ReadString('24 if err != nil {25 }26 fmt.Print(line)27 }28}29import (30func main() {31 f, err := os.Open("readfile.go")32 if err != nil {33 fmt.Println(err)34 }35 r := bufio.NewReader(f)36 b := make([]byte, 5)37 for {38 n, err := r.Read(b)39 if err != nil {40 }41 fmt.Print(string(b[:n]))42 }43}44import (45func main() {46 f, err := os.Open("readfile.go")47 if err != nil {48 fmt.Println(err)49 }50 r := bufio.NewReader(f)51 b := make([]byte, 5)52 for {53 n, err := r.Read(b)54 if err != nil {55 }56 fmt.Print(string(b[:n]))57 }58}59import (60func main() {61 f, err := os.Open("readfile.go")62 if err != nil {63 fmt.Println(err)64 }
Run
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello")4 r := readfile{}5 r.Run()6}7import (8func main() {9 fmt.Println("Hello")10 r := readfile{}11 r.Run()12}13import (14func main() {15 fmt.Println("Hello")16 r := readfile{}17 r.Run()18}19import (20func main() {21 fmt.Println("Hello")22 r := readfile{}23 r.Run()24}25import (26func main() {27 fmt.Println("Hello")28 r := readfile{}29 r.Run()30}31import (32func main() {33 fmt.Println("Hello")34 r := readfile{}35 r.Run()36}37import (38func main() {39 fmt.Println("Hello")40 r := readfile{}41 r.Run()42}43import (44func main() {45 fmt.Println("Hello")46 r := readfile{}47 r.Run()48}49import (50func main() {51 fmt.Println("Hello")52 r := readfile{}53 r.Run()54}55import (56func main() {57 fmt.Println("Hello")58 r := readfile{}59 r.Run()60}61import (
Run
Using AI Code Generation
1import (2func main() {3 fmt.Println("The readfile class is used to read a file")4 s, _ = readfile.Run("1.txt")5 fmt.Println(s)6}7import (8func main() {9 fmt.Println("The readfile class is used to read a file")10 s, _ = readfile.Run("2.txt")11 fmt.Println(s)12}13import (14func main() {15 fmt.Println("The readfile class is used to read a file")16 s, _ = readfile.Run("3.txt")17 fmt.Println(s)18}19import (20func main() {21 fmt.Println("The readfile class is used to read a file")22 s, _ = readfile.Run("4.txt")23 fmt.Println(s)24}25import (26func main() {27 fmt.Println("The readfile class is used to read a file")28 s, _ = readfile.Run("5.txt")29 fmt.Println(s)30}31import (32func main() {33 fmt.Println("The readfile class is used to read a file")34 s, _ = readfile.Run("6.txt")35 fmt.Println(s)36}37import (38func main() {39 fmt.Println("The readfile class is used to read a file")40 s, _ = readfile.Run("7.txt")41 fmt.Println(s)42}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!