Beispiel #1
1
def runcmd(cmd):
    """ Run command.
    """

    logging.info("%s" % cmd)
    return
    os.system(cmd)
Beispiel #2
1
    def Log(self, format_str, *args):
        """Logs the message using the flow's standard logging.

    Args:
      format_str: Format string
      *args: arguments to the format string
    Raises:
      RuntimeError: on parent missing logs_collection
    """
        format_str = utils.SmartUnicode(format_str)

        try:
            # The status message is always in unicode
            status = format_str % args
        except TypeError:
            logging.error("Tried to log a format string with the wrong number " "of arguments: %s", format_str)
            status = format_str

        logging.info("%s: %s", self.session_id, status)

        self.SetStatus(utils.SmartUnicode(status))

        with self.OpenLogsCollection(self.args.logs_collection_urn, mode="w") as logs_collection:
            logs_collection.Add(
                rdf_flows.FlowLog(
                    client_id=self.args.client_id,
                    urn=self.session_id,
                    flow_name=self.flow_obj.__class__.__name__,
                    log_message=status,
                )
            )
 def do_mythtv_getwatched(self, line):
     """Process MythTV get all watched/saved video details"""
     if self.verbose:
         print
         print u"Getting details on watched/saved Miro videos"
     self.videofiles = []
     if len(views.watchableItems):
         if self.verbose:
             print u"%-20s %-10s %s" % (u"State", u"Size", u"Name")
             print "-" * 70
         for item in views.watchableItems:
             # Skip any audio file as MythTV Internal player may abort the MythTV Frontend on a MP3
             if not item.isVideo:
                 continue
             state = item.get_state()
             if state == u"newly-downloaded":
                 continue
             # Skip any bittorrent video downloads for legal concerns
             if filetypes.is_torrent_filename(item.getURL()):
                 continue
             self.printItems(item)
             self.videofiles.append(self._get_item_dict(item))
         if self.verbose:
             print
     if not len(self.videofiles):
         logging.info(u"No watched/saved Miro videos")
Beispiel #4
1
    def append(self, tr):

        # Give the transaction an id
        tr.set_id(self.get_tr_id())

        # Check the size
        tr_size = tr.get_size()

        logging.info(
            "New transaction to add, total size of queue would be: %s KB" % ((self._total_size + tr_size) / 1024)
        )

        if (self._total_size + tr_size) > self._MAX_QUEUE_SIZE:
            logging.warn("Queue is too big, removing old messages...")
            new_trs = sorted(self._transactions, key=attrgetter("_next_flush"), reverse=True)
            for tr2 in new_trs:
                if (self._total_size + tr_size) > self._MAX_QUEUE_SIZE:
                    logging.warn("Removing transaction %s from queue" % tr2.get_id())
                    self._transactions.remove(tr2)
                    self._total_count = self._total_count - 1
                    self._total_size = self._total_size - tr2.get_size()

        # Done
        self._transactions.append(tr)
        self._total_count = self._total_count + 1
        self._total_size = self._total_size + tr_size

        logging.info("Transaction %s added" % (tr.get_id()))
        self.print_queue_stats()
def cookie2user(cookie_str):
    """
    Parse cookie and load user if cookie is valid.
    """
    if not cookie_str:
        return None
    try:
        L = cookie_str.split("-")
        if len(L) != 3:
            return None
        uid, expires, sha1 = L
        if int(expires) < time.time():
            return None
        user = yield from User.find(uid)
        if user is None:
            return None
        s = "%s-%s-%s-%s" % (uid, user.passwd, expires, _COOKIE_KEY)
        if sha1 != hashlib.sha1(s.encode("utf-8")).hexdigest():
            logging.info("invalid sha1")
            return None
        user.passwd = "******"
        return user
    except Exception as e:
        logging.exception(e)
        return None
Beispiel #6
1
def generate_pdf(*args, **kwargs):
    tmpfolder = tempfile.mkdtemp()
    html_tmp_file_path = "%s/export.html" % (tmpfolder)
    html_tmp_file = file(html_tmp_file_path, "w")
    html_tmp_file.write(render_to_string(*args, **kwargs).encode("utf-8"))
    html_tmp_file.close()

    pdf_tmp_file_path = "%s/export.pdf" % (tmpfolder)
    cmd = """wkhtmltopdf -s A4 -T 5 -L 5 -R 5 -B 10\
    --encoding utf-8 \
    --footer-font-size 8 \
    --footer-left '{0}' \
    --footer-center 'Incident: {1}' \
    --footer-right '[page]/[toPage]' {2} {3}
    """.format(
        datetime.date.today().strftime("%d/%m/%y"),
        args[1]["report"].get_ticket_number(),
        html_tmp_file_path,
        pdf_tmp_file_path,
    )
    logging.info(cmd)
    os.system(cmd)

    pdf_tmp_file = file(pdf_tmp_file_path, "r")
    return pdf_tmp_file
Beispiel #7
0
    def __init__(self, section):
        self._config = Config(section=section)
        self._config.read(CONFIG_FILE)
        logging.debug("-------------------------------------------")
        logging.debug("Running section " + self._config.section)

        known_circular_depends = []
        for kcd in self._config["known_circular_depends"].split():
            known_circular_depends.append(kcd)
            # logging.debug("circular depends: " + kcd)

        logging.debug("Loading and parsing Packages file")
        logging.info("Fetching %s" % self._config["packages-url"])
        packages_file = piupartslib.open_packages_url(self._config["packages-url"])
        self._binary_db = piupartslib.packagesdb.PackagesDB()
        self._binary_db.read_packages_file(packages_file)
        self._binary_db.set_known_circular_depends(known_circular_depends)
        packages_file.close()

        if self._config["sources-url"]:
            logging.info("Fetching %s" % self._config["sources-url"])
            sources_file = piupartslib.open_packages_url(self._config["sources-url"])
            self._source_db = piupartslib.packagesdb.PackagesDB()
            self._source_db.read_packages_file(sources_file)
            sources_file.close()
 def Analyze(self, check_sanity=False):
     filenames = glob.glob(self.log_dir + "/tsan.*")
     analyzer = tsan_analyze.TsanAnalyzer(self._source_dir)
     ret = analyzer.Report(filenames, check_sanity)
     if ret != 0:
         logging.info(self.INFO_MESSAGE)
     return ret
Beispiel #9
0
 def has_errors(self):
     ret_val = False
     for t in self.test_suites:
         if t.failures > 0 or t.passes <= 0:
             ret_val = True
             logging.info("test_suite {0} has {1} error(s) and {2} passes".format(t, t.failures, t.passes))
     return ret_val
    def get_all(self):
        """
        Reads all implemented parameters from the instrument,
        and updates the wrapper.

        Input:
            None

        Output:
            None
        """
        logging.info(__name__ + " : Reading all data from instrument")
        #        logging.warning(__name__ + ' : get all not yet fully functional')

        self.get_trigger_mode()
        self.get_trigger_impedance()
        self.get_trigger_level()
        self.get_numpoints()
        self.get_clock()

        for i in range(1, 5):
            self.get("ch%d_amplitude" % i)
            self.get("ch%d_offset" % i)
            self.get("ch%d_marker1_low" % i)
            self.get("ch%d_marker1_high" % i)
            self.get("ch%d_marker2_low" % i)
            self.get("ch%d_marker2_high" % i)
            self.get("ch%d_status" % i)
Beispiel #11
0
    def run(self):
        """Will run this algorithm"""
        if self.verbose:
            column_names = ["gen", "evals", "best"]
            if self.stats is not None:
                column_names += self.stats.functions.keys()
            self.logbook = tools.Logbook()
            self.logbook.header = column_names

        for _ in range(self.ngen):
            # Check if the user has cancelled:
            if self._user_cancelled():
                logger.info("User cancelled execution, stopping ...")
                break

            # ASK: Generate a new population:
            population = self._ask()
            # TELL: Update the strategy with the evaluated individuals
            self._tell(population)
            # RECORD: For stagnation checking & logging:
            self._record(population)
            # CHECK: whether we are stagnating:
            if self._is_stagnating():
                logging.info("CMA: stagnation detected!")
                break

        return self.context.best_solution, population
Beispiel #12
0
def get_options_from_ini():
    """f() -> {}

	Tries to read the INI_FILE and returns the sections as python dictionaries.
	If the INI_FILE doesn't exist, it will be populated with defaults for the
	user.
	"""
    ret = {}
    if not os.path.isfile(INI_FILE):
        logging.info("No %r file, creating from template", INI_FILE)
        with closing(open(INI_FILE, "wt")) as out:
            out.write(INI_TEMPLATE)
        return ret

    try:
        c = ConfigParser.SafeConfigParser()
        c.read(INI_FILE)
        # Retrieve configuration sets along with expanded paths.
        for section in c.sections():
            ret[section] = dict([(x, os.path.expanduser(y)) for x, y in c.items(section)])
            # Convert width option to integer.
            if KEY_WIDTH in ret[section]:
                try:
                    ret[section][KEY_WIDTH] = int(ret[section][KEY_WIDTH])
                except ValueError, e:
                    logging.error("Couldn't parse int for [%s]%s", section, KEY_WIDTH)
                    del ret[section][KEY_WIDTH]
    except ConfigParser.NoSectionError, e:
        pass
Beispiel #13
0
def main():
    """f() -> None

	Main entry point of the application.
	"""
    options = process_arguments(sys.argv)
    # sizes = [get_image_size(x) for x in panels]
    # Prepare a target size which is taller than the expected width.
    S = "%dx%d" % (options.strip_width, 10 * options.strip_width)
    if run_command(
        [
            options.convert_path,
            options.panels[0],
            "-resize",
            S,
            options.panels[1],
            "-resize",
            S,
            options.panels[2],
            "-resize",
            S,
            options.panels[3],
            "-resize",
            S,
            "-quality",
            "85",
            "-append",
            options.output,
        ]
    ):
        logging.error("Unexpected return value from %r", options.convert_path)
    else:
        logging.info("Done.")
 def get_measured_intensity(self):
     logging.info("<PX2 MultiCollect> TODO - get measured intensity")
     try:
         val = self.getChannelObject("image_intensity").getValue()
         return float(val)
     except:
         return 0
Beispiel #15
0
    def get(self, location_id=None):
        logging.info("################ LocationProfile::get ################")
        user = self.current_user  # this is the logged in User

        location_bean = models.LocationBean.get_by_key_name(location_id)
        category_leaders = getCategoryLeaders()
        location_leaders = getLocationLeaders()
        leaders = getLeaders()
        if isFacebook(self.request.path):
            count = 4
            template = "facebook/fb_base_location_profile.html"
        else:
            count = 10
            template = "base_location_profile.html"

        deref_brags = getLocationBrags(location_id, count)
        self.generate(
            template,
            {
                "host": self.request.host_url,
                "location_bean": location_bean,
                "brags": deref_brags,
                "leaders": leaders,
                "category_leaders": category_leaders,
                "location_leaders": location_leaders,
                "current_user": self.current_user,
                "facebook_app_id": FACEBOOK_APP_ID,
            },
        )
Beispiel #16
0
    def provides(self, name):
        """
        Searches for what provides a given file.

        @param name: File path.
        """
        p_cmd = self.base_command + " what-provides " + name
        list_provides = []
        try:
            p_output = utils.system_output(p_cmd).split("\n")[4:]
            for line in p_output:
                line = [a.strip() for a in line.split("|")]
                try:
                    # state, pname, type, version, arch, repository = line
                    pname = line[1]
                    if pname not in list_provides:
                        list_provides.append(pname)
                except IndexError:
                    pass
            if len(list_provides) > 1:
                logging.warning("More than one package found, " "opting by the first queue result")
            if list_provides:
                logging.info("Package %s provides %s", list_provides[0], name)
                return list_provides[0]
            return None
        except error.CmdError:
            return None
Beispiel #17
0
def getFBUser(fb_id=None):
    """Returns a User for the given fb_id.
    """
    logging.info("################ getFBUser(" + fb_id + ") ####################")
    user_query = models.User.all().filter("fb_id =", fb_id)
    user = user_query.get()  # this is the profiled User
    return user
Beispiel #18
0
def install_distro_packages(distro_pkg_map, interactive=False):
    """
    Installs packages for the currently running distribution

    This utility function checks if the currently running distro is a
    key in the distro_pkg_map dictionary, and if there is a list of packages
    set as its value.

    If these conditions match, the packages will be installed using the
    software manager interface, thus the native packaging system if the
    currenlty running distro.

    @type disto_pkg_map: dict
    @param distro_pkg_map: mapping of distro name, as returned by
        utils.get_os_vendor(), to a list of package names
    @returns: True if any packages were actually installed, False otherwise
    """
    if not interactive:
        os.environ["DEBIAN_FRONTEND"] = "noninteractive"

    result = False
    distro = utils.get_os_vendor()
    if distro_pkg_map.has_key(distro):
        pkgs = distro_pkg_map.get(distro, None)
        needed_pkgs = []
        if pkgs is not None:
            s = SoftwareManager()
            for p in pkgs:
                if not s.check_installed(p):
                    needed_pkgs.append(p)
        if needed_pkgs:
            text = " ".join(needed_pkgs)
            logging.info('Installing packages "%s"', text)
            result = s.install(text)
    return result
Beispiel #19
0
    def pre(self, emulator=None):
        """
        _pre_

        Pre execution checks

        """
        if emulator is not None:
            return emulator.emulatePre(self.step)
        logging.info("Pre-executing CMSSW step")
        if hasattr(self.step.application.configuration, "configCacheUrl"):
            # means we have a configuration & tweak in the sandbox
            psetFile = self.step.application.command.configuration
            psetTweak = self.step.application.command.psetTweak
            self.stepSpace.getFromSandbox(psetFile)

            if psetTweak:
                self.stepSpace.getFromSandbox(psetTweak)

        if hasattr(self.step, "pileup"):
            self.stepSpace.getFromSandbox("pileupconf.json")

        # add in ths scram env PSet manip script whatever happens
        self.step.runtime.scramPreScripts.append("SetupCMSSWPset")
        return None
    def set_backup(self):
        """ Set the current router to backup """
        if not self.cl.is_redundant():
            logging.error("Set backup called on non-redundant router")
            return

        self.set_lock()
        logging.debug("Setting router to backup")
        ads = [o for o in self.address.get_ips() if o.is_public()]
        dev = ""
        for o in ads:
            if dev == o.get_device():
                continue
            logging.info("Bringing public interface %s down" % o.get_device())
            cmd2 = "ip link set %s down" % o.get_device()
            CsHelper.execute(cmd2)
            dev = o.get_device()
        cmd = "%s -C %s" % (self.CONNTRACKD_BIN, self.CONNTRACKD_CONF)
        CsHelper.execute("%s -d" % cmd)
        CsHelper.service("ipsec", "stop")
        CsHelper.service("xl2tpd", "stop")
        ads = [o for o in self.address.get_ips() if o.needs_vrrp()]
        for o in ads:
            CsPasswdSvc(o.get_gateway()).stop()
        CsHelper.service("dnsmasq", "stop")

        self.cl.set_master_state(False)
        self.cl.save()
        self.release_lock()
        logging.info("Router switched to backup mode")
Beispiel #21
0
    def finalizeJar(self, jarPath, chromebasepath, register, doZip=True):
        """Helper method to write out the chrome registration entries to
         jarfile.manifest or chrome.manifest, or both.

        The actual file processing is done in updateManifest.
        """

        # rewrite the manifest, if entries given
        if not register:
            return

        chromeManifest = os.path.join(os.path.dirname(jarPath), "..", "chrome.manifest")

        if self.useJarfileManifest:
            self.updateManifest(jarPath + ".manifest", chromebasepath.format(""), register)
            addEntriesToListFile(chromeManifest, ["manifest chrome/{0}.manifest".format(os.path.basename(jarPath))])
        if self.useChromeManifest:
            self.updateManifest(chromeManifest, chromebasepath.format("chrome/"), register)

        # If requested, add a root chrome manifest entry (assumed to be in the parent directory
        # of chromeManifest) with the application specific id. In cases where we're building
        # lang packs, the root manifest must know about application sub directories.

        if self.rootManifestAppId:
            rootChromeManifest = os.path.join(
                os.path.normpath(os.path.dirname(chromeManifest)), "..", "chrome.manifest"
            )
            rootChromeManifest = os.path.normpath(rootChromeManifest)
            chromeDir = os.path.basename(os.path.dirname(os.path.normpath(chromeManifest)))
            logging.info("adding '%s' entry to root chrome manifest appid=%s" % (chromeDir, self.rootManifestAppId))
            addEntriesToListFile(
                rootChromeManifest, ["manifest %s/chrome.manifest application=%s" % (chromeDir, self.rootManifestAppId)]
            )
Beispiel #22
0
def _ExtractTimeToFirstMeaningfulPaint(loading_trace):
    """Extracts the time to first meaningful paint from a given trace.

  Args:
    loading_trace: loading_trace_module.LoadingTrace.

  Returns:
    Time to first meaningful paint in milliseconds.
  """
    required_categories = set(sandwich_runner.TTFMP_ADDITIONAL_CATEGORIES)
    if not required_categories.issubset(loading_trace.tracing_track.Categories()):
        return _UNAVAILABLE_CSV_VALUE
    logging.info("  Extracting first_meaningful_paint")
    events = [e.ToJsonDict() for e in loading_trace.tracing_track.GetEvents()]
    with common_util.TemporaryDirectory(prefix="sandwich_tmp_") as tmp_dir:
        chrome_trace_path = os.path.join(tmp_dir, "chrome_trace.json")
        with open(chrome_trace_path, "w") as output_file:
            json.dump({"traceEvents": events, "metadata": {}}, output_file)
        catapult_run_metric_bin_path = os.path.join(_SRC_DIR, "third_party", "catapult", "tracing", "bin", "run_metric")
        output = subprocess.check_output([catapult_run_metric_bin_path, "firstPaintMetric", chrome_trace_path])
    json_output = json.loads(output)
    for metric in json_output[chrome_trace_path]["pairs"]["values"]:
        if metric["name"] == "firstMeaningfulPaint_avg":
            return metric["numeric"]["value"]
    logging.info("  Extracting first_meaningful_paint: failed")
    return _FAILED_CSV_VALUE
Beispiel #23
0
 def tr_error(self, tr):
     tr.inc_error_count()
     tr.compute_next_flush(self._MAX_WAIT_FOR_REPLAY)
     logging.info(
         "Transaction %d in error (%s error%s), it will be replayed after %s"
         % (tr.get_id(), tr.get_error_count(), plural(tr.get_error_count()), tr.get_next_flush())
     )
 def verify_auth(self, command, data):
     mac = hmac.new(self.password, self.auth, hashlib.sha1)
     if data == mac.digest().encode("hex"):
         self.auth = "Done"
         logging.info("Authenticated other end")
     else:
         self.handle_close()
Beispiel #25
0
    def post(self):
        """Post handler for model requests from the web daemon.

        Attempts to build a model from its known models (essentially performing
        parameter verification) then places a request in the queue if it succeeds.
        Additionally, it will send out an e-mail to the user for confirmation of
        the request
        """

        if not self.checkSecret():
            return

        task_json = tornado.escape.json_decode(self.get_argument("task_json"))
        task = modelManager.getModelFromTaskDict(task_json)
        task.taskId = glb.newTaskId()
        code = glb.confirmationMap.putRequest(task)

        emailAddress = task.emailAddress
        logging.info("Generated a request for %s, confirmation %s required", emailAddress, code)
        subject = config.confirmEmailSubject.generate(task=task)
        body = config.confirmEmailTemplate.generate(code=code, task=task, expireDelta=config.confirmTimeout)
        emailObject = Email(emailAddress, subject, body)
        npsgd.email_manager.backgroundEmailSend(emailObject)
        glb.syncShelve()
        self.write(tornado.escape.json_encode({"response": {"task": task.asDict(), "code": code}}))
Beispiel #26
0
 def get(self, user_id=None):
     logging.info("################# UserProfile::get ###################")
     user = self.current_user  # this is the logged in User
     profile_user = getFBUser(fb_id=user_id)  # this is the profiled User
     brag_query = models.Brag.all().order("-created")
     brag_query = brag_query.filter("user", profile_user)
     category_leaders = getCategoryLeaders()
     location_leaders = getLocationLeaders()
     leaders = getLeaders()
     if isFacebook(self.request.path):
         brags = brag_query.fetch(6)
         template = "facebook/fb_base_user_profile.html"
     else:
         brags = brag_query.fetch(10)
         template = "base_user_profile.html"
     self.generate(
         template,
         {
             "host": self.request.host_url,
             "brags": brags,
             "profile_user": profile_user,
             "categories": CATS,
             "leaders": leaders,
             "category_leaders": category_leaders,
             "location_leaders": location_leaders,
             "current_user": self.current_user,
             "facebook_app_id": FACEBOOK_APP_ID,
         },
     )
Beispiel #27
0
 def stop_loop():
     now = time.time()
     if now < deadline and (io_loop._callbacks or io_loop._timeouts):
         io_loop.add_timeout(now + 1, stop_loop)
     else:
         io_loop.stop()  # 处理完现有的 callback 和 timeout 后,可以跳出 io_loop.start() 里的循环
         logging.info("Shutdown")
Beispiel #28
0
 def post(self, user_id=None):
     """POSTs a new Brag.
     """
     logging.info("################## UserProfile::post #################")
     user = getFBUser(user_id)  # this is the profiled User
     message = self.request.get("message")
     origin = self.request.get("origin")
     categories = self.request.get_all("category")
     category_beans = []
     for c in categories:
         key = db.Key.from_path("CategoryBean", utils.slugify(c))
         category_beans.append(key)
     share = self.request.get("facebook")
     brag = models.Brag(
         user=user,
         categories=categories,
         category_beans=category_beans,
         message=message,
         origin=origin,
         fb_location_id=user.fb_location_id,
         fb_location_name=user.fb_location_name,
     )
     brag.put()
     if share.upper() == "TRUE":
         shareOnFacebook(self, user, brag)
     if isFacebook(self.request.path):
         self.redirect("/facebook/user/" + user_id)
     else:
         self.redirect("/user/" + user_id)
Beispiel #29
0
    def get_users_of_vpn(self, vpn, environment=None):
        """ Returns all products users who use a specifig messaging VPN

        :type vpn: str
        :param vpn: name of vpn to search for users of

        """
        self.populateDeployData()
        users = []
        logging.warn("Scaning for Products using vpn: %s" % vpn)
        for p in self.deploydata.product:
            logging.debug("Scanning Product: %s for messaging declarations" % p.name)
            if p.messaging:
                for m in p.messaging:
                    #  <messaging name="my_%s_sitemq" user="%s_um" password="somepassword"></messaging>
                    if m.name == vpn:
                        password = m.password
                        try:
                            # logging.debug("Dumping messaging environments: %s" % pprint.pprint(m.__dict__))
                            for e in m.env:
                                # logging.info("Env Searching %s" % e.name)
                                if e.name == environment:
                                    # logging.info("Env Matched %s" % e.name)
                                    for myp in e.messaging_conf:
                                        logging.info("Setting password %s" % myp.password)
                                        password = myp.password
                        except Exception, e:
                            logging.warn("No Environment Password Overrides %s" % e)
                            pass

                        logging.info(
                            "Product: %s using VPN: %s, adding user %s to users list" % (p.name, vpn, m.username)
                        )
                        users.append({"username": m.username, "password": password})
Beispiel #30
0
def compute_stats_prec(ids_gnd, ids_qry, k):
    nquery = ids_qry.shape[0]
    hit_map = np.zeros(ids_qry.shape, np.int)
    for i in xrange(nquery):
        hit_map[i, :] = [1 if ret_id in ids_gnd[i, :] else 0 for ret_id in ids_qry[i, :]]

    v_prec = []
    for i in [
        1,
        2,
        5,
        10,
        20,
        50,
        100,
        200,
        500,
        1000,
        2000,
        5000,
        10000,
        20000,
        50000,
        100000,
        200000,
        500000,
        1000000,
    ]:
        if i > k:
            break
        hit_cnt = hit_map[:, :i].sum()
        p_at_i = float(hit_cnt) / i / nquery
        logging.info("prec@%3d = %.4f" % (i, p_at_i))
        v_prec.append((i, p_at_i))
    return v_prec