Esempio n. 1
0
    def makeforks(self):
        """
        takes a list of devices and forks a separate process for uploading a file
        """

        for d in self.devlist:
            m=utils(hostname=d,options=self.options,silent=True)
            m.setupworkspace()
            print("uploading %s to %s" % (self.options.binfile,d))
            pid=os.fork()
            if pid == 0:
                uploadbin(hostname=d,options=self.options,multi=True)
            else:
                pids = (os.getpid(), pid)
        for i in range(len(self.devlist)):
            finished = os.waitpid(0, 0)
        print("all done")
Esempio n. 2
0
    def avas(self, id):
        #please pu try block here
        url = "https://avas.mv/" + str(id)
        html = requests.get(url, timeout=30)
        parsed_html = BeautifulSoup(html.text, 'html.parser')

        try:

            if len(parsed_html) >= 3:
                headline = (parsed_html.h1).get_text()
                image = parsed_html.find("figure").find(
                    "img"
                )["src"]  # stupid lazy oneliner,but it works might have to redo it
                time_tag = parsed_html.find(
                    "div", {"class", "ltr text-sm text-grey-dark pl-2"
                            }).find("timeago")["datetime"]  #get the date/time
                #author = parsed_html.find("div",{"class":"font-waheed text-grey ml-3 pl-3 text-lg border-l border-grey border-dotted"}).find('a').get_text() #me back again with my lazy onliners
                author = ""  #author empty as rrors sometimes occur during fetching this
                category = parsed_html.find(
                    "div", {
                        "class": "rtl container mx-auto mb-7 mt-8 px-4 md:px-0"
                    }).find("a").get_text()

                #paragraphs are seperate so loops and adds them up
                article_div = parsed_html.find(
                    "div", {"class", "w-full md:w-5/6"}).find_all("p")
                article = ""
                for x in article_div:
                    article += "\n" + x.get_text()

                u = utils()
                valid_data = self.u.ParseData(url, headline, image, author,
                                              category, article, time_tag,
                                              "avas", id)
                return (valid_data)

        except:
            print("{} not found".format(id))
            valid_data = self.u.ParseData("", "", "", "", "", "", "", "avas",
                                          id)

            return (valid_data)
Esempio n. 3
0
    def sun(self, id):

        url = "https://sun.mv/" + str(id)
        html = requests.get(url, timeout=30)
        parsed_html = BeautifulSoup(html.text, 'html.parser')

        try:
            if len(parsed_html) >= 4:
                headline = (parsed_html.h1).get_text()
                image = parsed_html.find("figure").find("img")["src"]
                time_tag = parsed_html.find("span", {
                    "class": "time"
                }).get_text()
                category = ""
                author = ""

                #get the article content
                article_div = parsed_html.find(
                    "div", {"class", "component-article-content clearfix"
                            }).find_all("p")
                article = ""
                for x in article_div:
                    article += "\n" + x.get_text()

                u = utils()

                valid_data = self.u.ParseData(url, headline, image, author,
                                              category, article, time_tag,
                                              "sun", id)

                return (valid_data)

        except:
            print("{} not found".format(id))
            valid_data = self.u.ParseData("", "", "", "", "", "", "", "sun",
                                          id)

            return (valid_data)
Esempio n. 4
0
    def __init__(self):
        """
        Takes command line variables and does 1 of the following: uploads,prepares,upgrades,backout
        """
        parser = OptionParser("usage: ftosupgrade <options>")
        parser.add_option("-d", "--devices", dest="devices",
            help="List of devices to upgrade separated by a ','", default=None)
        parser.add_option("-r", "--region", dest="region",
            help="Any region e.g us-east (for uploads only!)", default=None)
        parser.add_option("-t", "--type",dest="type",
            help="This can be prepare,upgrade,backout, or upload",
            choices=['upload','prepare','upgrade','backout'],
            default='prepare')
        parser.add_option("-b","--binfile",dest="binfile",
            help="The name of the binary file you are using for the upgrade e.g. FTOS-SK-9.14.1.0.bin")
        parser.add_option("-n","--numforks",dest="numforks",
            help="The number of scp sessions you want to run at once, default is 20 (only for uploads!)",default=20)
        parser.add_option("-f", "--force", dest="noforce",
            action="store_false",
            help="use -f to force scripts to run (only works with prepare at the moment)", default=True)
        parser.add_option("--test", dest="notest",
            action="store_false",
            help="use --test to run the upgrade command without reloading the switch", default=True)
        parser.add_option("-p","--binfilepath",dest="binfilepath",
            default=BINFILEPATH,
            help="The path where all your binary files are stored")
        (options, args) = parser.parse_args()
        dl = os.getcwd().split('/')
        self.options=options
        if options.type=='upload' and options.binfile is not None and (options.devices is not None or options.region is not None):
            #upload bin files to multiple devices
            self.devlist=list()
            self.sqllist=list()
            if options.devices:
                self.devlist=options.devices.split(',')
                self.makeforks()
            else:
                self.region=options.region
                self.gethosts()
                i=1
                for hn in self.sqllist:
                    if i<=int(options.numforks):
                        self.devlist.append(hn)
                        i=i+1
                    else:
                        i=0
                        self.makeforks()
                        self.devlist=[hn]
                self.makeforks()
        elif options.devices is not None and options.binfile is not None:
            # prepare and upgrade devices
            self.devlist=options.devices.split(",")
            for d in self.devlist:
                m=utils(hostname=d,options=options)
                m.setupworkspace()
                if options.type=='prepare':
                    prepare(hostname=d,options=options)
                elif options.type=='backout':
                    backout(hostname=d,options=options)
                elif options.type=='upgrade':
                    p=prepare(hostname=d,options=options)
                    if len(p.errors[d]['critical'])<1:
                        u=upgrade(hostname=d,options=options)
                        if len(u.errors[d]['critical'])>0:
                            m.warning('Found Errors with upgrade...exiting!')
                            sys.exit()
                    else:
                        m.warning('Found Errors with prepare... exiting!')
                        sys.exit()

        else:
            print("Please specify at least 1 device and a binary file name")
            parser.print_help()
Esempio n. 5
0
#!/usr/bin/env python

import os, math, sys, random
import numpy as np
import ROOT
ROOT.gROOT.SetBatch(True)
from root_numpy import hist2array
from cameraChannel import cameraTools

from snakes import SnakesProducer
from output import OutputTree
from treeVars import AutoFillTreeProducer
import swiftlib as sw

import utilities
utilities = utilities.utils()


class analysis:
    def __init__(self, options):
        self.xmax = 2048
        self.rebin = options.rebin
        self.options = options
        self.pedfile_fullres_name = options.pedfile_fullres_name
        self.tmpname = options.tmpname

        if not os.path.exists(self.pedfile_fullres_name):
            print("WARNING: pedestal file with full resolution ",
                  self.pedfile_fullres_name,
                  " not existing. First calculate them...")
            self.calcPedestal(options, 1)
Esempio n. 6
0
 def __init__(self):
     self.u = utils()
     pass