Ejemplo n.º 1
0
    def search_roles(self, search, platforms=None, categories=None):

        search_url = self.baseurl + '/roles/?page=1'

        if search:
            search_url += '&search=' + urlquote(search)

        if categories is None:
            categories = []
        elif isinstance(categories, basestring):
            categories = categories.split(',')

        for cat in categories:
            search_url += '&chain__categories__name=' + urlquote(cat)

        if platforms is None:
            platforms = []
        elif isinstance(platforms, basestring):
            platforms = platforms.split(',')

        for plat in platforms:
            search_url += '&chain__platforms__name=' + urlquote(plat)

        self.galaxy.display.debug("Executing query: %s" % search_url)
        try:
            data = json.load(urlopen(search_url))
        except HTTPError as e:
            raise AnsibleError("Unsuccessful request to server: %s" % str(e))

        return data
Ejemplo n.º 2
0
    def search_roles(self, search, platforms=None, tags=None):

        search_url = self.baseurl + '/roles/?page=1'

        if search:
            search_url += '&search=' + urlquote(search)

        if tags is None:
            tags = []
        elif isinstance(tags, basestring):
            tags = tags.split(',')

        for tag in tags:
            search_url += '&chain__tags__name=' + urlquote(tag)

        if platforms is None:
            platforms = []
        elif isinstance(platforms, basestring):
            platforms = platforms.split(',')

        for plat in platforms:
            search_url += '&chain__platforms__name=' + urlquote(plat)

        display.debug("Executing query: %s" % search_url)
        try:
            data = json.load(
                open_url(search_url,
                         validate_certs=self.galaxy.options.validate_certs))
        except HTTPError as e:
            raise AnsibleError("Unsuccessful request to server: %s" % str(e))

        return data
Ejemplo n.º 3
0
    def search_roles(self, search, platforms=None, categories=None):

        search_url = self.baseurl + '/roles/?page=1'

        if search:
            search_url += '&search=' + urlquote(search)

        if categories is None:
            categories = []
        elif isinstance(categories, basestring):
            categories = categories.split(',')

        for cat in categories:
            search_url += '&chain__categories__name=' + urlquote(cat)

        if platforms is None:
            platforms = []
        elif isinstance(platforms, basestring):
            platforms = platforms.split(',')

        for plat in platforms:
            search_url += '&chain__platforms__name=' + urlquote(plat)

        self.galaxy.display.debug("Executing query: %s" % search_url)
        try:
            data = json.load(open_url(search_url))
        except HTTPError as e:
            raise AnsibleError("Unsuccessful request to server: %s" % str(e))

        return data
Ejemplo n.º 4
0
    def search_roles(self, search, platforms=None, tags=None):

        search_url = self.baseurl + '/roles/?page=1'

        if search:
            search_url += '&search=' + urlquote(search)

        if tags is None:
            tags = []
        elif isinstance(tags, basestring):
            tags = tags.split(',')

        for tag in tags:
            search_url += '&chain__tags__name=' + urlquote(tag)

        if platforms is None:
            platforms = []
        elif isinstance(platforms, basestring):
            platforms = platforms.split(',')

        for plat in platforms:
            search_url += '&chain__platforms__name=' + urlquote(plat)

        self.galaxy.display.debug("Executing query: %s" % search_url)
        try:
            data = json.load(open_url(search_url, validate_certs=self.galaxy.options.validate_certs))
        except HTTPError as e:
            raise AnsibleError("Unsuccessful request to server: %s" % str(e))

        return data
Ejemplo n.º 5
0
 def __init__(self, name, path=None, source=None, username=None,
              password=None, repo_type=HG):
     self.name = name
     self.path = path
     self.source = source
     self.username = None if username is None else urlquote(username)
     self.password = None if password is None else urlquote(password)
     self._uri = None
     self._muri = None
     self.repo_type = repo_type
     if self.repo_type == Repository.HG:
         self.scm = Hg(self)
     else:
         self.scm = Git(self)
Ejemplo n.º 6
0
    def lookup_role_by_name(self, role_name, notify=True):
        """
        Find a role by name
        """
        role_name = urlquote(role_name)

        try:
            parts = role_name.split(".")
            user_name = ".".join(parts[0:-1])
            role_name = parts[-1]
            if notify:
                self.galaxy.display.display("- downloading role '%s', owned by %s" % (role_name, user_name))
        except:
            raise AnsibleError("- invalid role name (%s). Specify role as format: username.rolename" % role_name)

        url = '%s/roles/?owner__username=%s&name=%s' % (self.baseurl, user_name, role_name)
        self.galaxy.display.vvvv("- %s" % (url))
        try:
            data = json.load(urlopen(url))
            if len(data["results"]) != 0:
                return data["results"][0]
        except:
            # TODO: report on connection/availability errors
            pass

        return None
Ejemplo n.º 7
0
    def lookup_role_by_name(self, role_name, notify=True):
        """
        Find a role by name
        """
        role_name = urlquote(role_name)

        try:
            parts = role_name.split(".")
            user_name = ".".join(parts[0:-1])
            role_name = parts[-1]
            if notify:
                self.galaxy.display.display(
                    "- downloading role '%s', owned by %s" %
                    (role_name, user_name))
        except:
            raise AnsibleError(
                "- invalid role name (%s). Specify role as format: username.rolename"
                % role_name)

        url = '%s/roles/?owner__username=%s&name=%s' % (self.baseurl,
                                                        user_name, role_name)
        self.galaxy.display.vvvv("- %s" % (url))
        try:
            data = json.load(urlopen(url))
            if len(data["results"]) != 0:
                return data["results"][0]
        except:
            # TODO: report on connection/availability errors
            pass

        return None
Ejemplo n.º 8
0
    def search_roles(self, search, **kwargs):

        search_url = self.baseurl + '/search/roles/?'

        if search:
            search_url += '&autocomplete=' + urlquote(search)

        tags = kwargs.get('tags', None)
        platforms = kwargs.get('platforms', None)
        page_size = kwargs.get('page_size', None)
        author = kwargs.get('author', None)

        if tags and isinstance(tags, basestring):
            tags = tags.split(',')
            search_url += '&tags_autocomplete=' + '+'.join(tags)

        if platforms and isinstance(platforms, basestring):
            platforms = platforms.split(',')
            search_url += '&platforms_autocomplete=' + '+'.join(platforms)

        if page_size:
            search_url += '&page_size=%s' % page_size

        if author:
            search_url += '&username_autocomplete=%s' % author

        data = self.__call_galaxy(search_url)
        return data
Ejemplo n.º 9
0
def process_repositories(items):
    from urllib2 import quote as urlquote

    repos = []

    for i in items:
        if i.section != "repo":
            continue
        if i.get("skip", "n") == "y":
            continue
        if i.usercommits == "0":
            continue

        repo = i.copy()
        repos.append(repo)

        if i.service == "github":
            repo.linkname = MupLink("https://github.com/" + urlquote(i.name), i.name)
        else:
            repo.linkname = i.name

        repo.commit_frac = "%.0f%%" % (100.0 * int(i.usercommits) / int(i.allcommits))
        if repo.commit_frac == "0%":
            repo.commit_frac = "<1%"

        repo.luc_year, repo.luc_month, repo.luc_day = [int(x) for x in i.lastusercommit.split("/")]
        repo.date = "%04d %s" % (repo.luc_year, months[repo.luc_month - 1])
        repo._datekey = repo.luc_year * 10000 + repo.luc_month * 100 + repo.luc_day

    return sorted(repos, key=lambda r: r._datekey)
Ejemplo n.º 10
0
    def search_roles(self, search, **kwargs):

        search_url = self.baseurl + '/search/roles/?'

        if search:
            search_url += '&autocomplete=' + urlquote(search)

        tags = kwargs.get('tags',None)
        platforms = kwargs.get('platforms', None)
        page_size = kwargs.get('page_size', None)
        author = kwargs.get('author', None)

        if tags and isinstance(tags, basestring):
            tags = tags.split(',')
            search_url += '&tags_autocomplete=' + '+'.join(tags)
        
        if platforms and isinstance(platforms, basestring):
            platforms = platforms.split(',')
            search_url += '&platforms_autocomplete=' + '+'.join(platforms)

        if page_size:
            search_url += '&page_size=%s' % page_size

        if author:
            search_url += '&username_autocomplete=%s' % author
   
        data = self.__call_galaxy(search_url)
        return data
Ejemplo n.º 11
0
def call():
    print("  == Calling home...", end=' ')
    try:
        f = urlopen(
            'http://etetoolkit.org/et_phone_home.php?VERSION=%s&ID=%s' %
            (__VERSION__, __ETEID__))
    except:
        print("No answer :(")
    else:
        print("Got answer!")
        print(f.read())

        module_name = __name__.split(".")[0]
        try:
            f = urlopen('http://etetoolkit.org/releases/ete3/%s.latest' %
                        module_name)
        except:
            latest = None
        else:
            latest = int(f.read())

        try:
            current = int(__VERSION__.split("rev")[1])
        except (IndexError, ValueError):
            current = None

        if not latest:
            print("I could not find data about your version [%s]" %
                  module_name)
            print("Are you ok?")
        elif not current:
            print("I could not determine your version [%s]" % module_name)
            print("Are you ok?")
            print("Latest stable ETE version is", latest)
        elif latest > current:
            print("You look a bit old.")
            print("A newer version is available: rev%s" % latest)
            print("Use 'easy_install -U %s' to upgrade" % module_name)
        else:
            print("I see you are in shape.")
            print("No updates are available.")
        try:
            msg = input(
                "\n  == Do you want to leave any message?\n(Press enter to finish)\n\n"
            ).strip()
        except KeyboardInterrupt:
            msg = None

        if msg:
            msg = urlquote(msg)
            try:
                f = urlopen(
                    'http://etetoolkit.org/et_phone_home.php?VERSION=%s&ID=%s&MSG=%s'
                    % (__VERSION__, __ETEID__, msg))
            except:
                print("Message could be delivered :(")
            else:
                print(f.read())
Ejemplo n.º 12
0
Archivo: _ph.py Proyecto: abdo3a/ete
def call():
    print("  == Calling home...", end=' ')
    try:
        f = urlopen('http://etetoolkit.org/et_phone_home.php?VERSION=%s&ID=%s'
                %(__VERSION__, __ETEID__))
    except:
        print("No answer :(")
    else:
        print("Got answer!")
        print(f.read())

        module_name = __name__.split(".")[0]
        try:
            f = urlopen('http://etetoolkit.org/releases/ete3/%s.latest'
                    %module_name)
        except:
            latest = None
        else:
            latest = int(f.read())

        try:
            current = int(__VERSION__.split("rev")[1])
        except (IndexError, ValueError):
            current = None

        if not latest:
            print("I could not find data about your version [%s]" %module_name)
            print("Are you ok?")
        elif not current:
            print("I could not determine your version [%s]" %module_name)
            print("Are you ok?")
            print("Latest stable ETE version is", latest)
        elif latest > current:
            print("You look a bit old.")
            print("A newer version is available: rev%s" %latest)
            print("Use 'easy_install -U %s' to upgrade" %module_name)
        else:
            print("I see you are in shape.")
            print("No updates are available.")
        try:
            msg = input("\n  == Do you want to leave any message?\n(Press enter to finish)\n\n").strip()
        except KeyboardInterrupt:
            msg = None

        if msg:
            msg = urlquote(msg)
            try:
                f = urlopen('http://etetoolkit.org/et_phone_home.php?VERSION=%s&ID=%s&MSG=%s'
                                %(__VERSION__, __ETEID__, msg))
            except:
                print("Message could be delivered :(")
            else:
                print(f.read())
Ejemplo n.º 13
0
    def lookup_role_by_name(self, role_name, notify=True):
        """
        Find a role by name.
        """
        role_name = urlquote(role_name)

        try:
            parts = role_name.split(".")
            user_name = ".".join(parts[0:-1])
            role_name = parts[-1]
            if notify:
                display.display("- downloading role '%s', owned by %s" % (role_name, user_name))
        except:
            raise AnsibleError("Invalid role name (%s). Specify role as format: username.rolename" % role_name)

        url = '%s/roles/?owner__username=%s&name=%s' % (self.baseurl, user_name, role_name)
        data = self.__call_galaxy(url)
        if len(data["results"]) != 0:
            return data["results"][0]
        return None
Ejemplo n.º 14
0
    def lookup_role_by_name(self, role_name, notify=True):
        """
        Find a role by name.
        """
        role_name = urlquote(role_name)

        try:
            parts = role_name.split(".")
            user_name = ".".join(parts[0:-1])
            role_name = parts[-1]
            if notify:
                display.display("- downloading role '%s', owned by %s" % (role_name, user_name))
        except:
            raise AnsibleError("Invalid role name (%s). Specify role as format: username.rolename" % role_name)

        url = '%s/roles/?owner__username=%s&name=%s' % (self.baseurl, user_name, role_name)
        data = self.__call_galaxy(url)
        if len(data["results"]) != 0:
            return data["results"][0]
        return None
Ejemplo n.º 15
0
    def remote_url(self):
	return self.search_url % (urlquote(self.path_tail), )
Ejemplo n.º 16
0
            print("Latest stable ETE version is", latest)
        elif latest > current:
            print("You look a bit old.")
            print("A newer version is available: rev%s" % latest)
        else:
            print("I see you are in good shape.")
            print("No updates are available.")
        try:
            msg = input(
                "\n  == Do you want to leave any message?\n(Press enter to finish)\n\n"
            ).strip()
        except KeyboardInterrupt:
            msg = None

        if msg:
            msg = urlquote(msg)
            try:
                f = urlopen(
                    'http://etetoolkit.org/static/et_phone_home.php?VERSION=%s&ID=%s&MSG=%s'
                    % (__version__, __ETEID__, msg))
            except:
                print("Message could be delivered :(")
            else:
                print("Message delivered")


def new_version(module_name=None, current=None):
    if not module_name:
        module_name = __name__.split(".")[0]
    try:
        f = urlopen('http://etetoolkit.org/releases/ete3/%s.latest' %
Ejemplo n.º 17
0
def url_encode(input, errors='strict'):
    output = urlquote(input)
    return (output, len(input))
Ejemplo n.º 18
0
Archivo: _ph.py Proyecto: dkagrawal/ete
            print("I could not determine your version [%s]" %__version__)
            print("Are you ok?")
            print("Latest stable ETE version is", latest)
        elif latest > current:
            print("You look a bit old.")
            print("A newer version is available: rev%s" %latest)
        else:
            print("I see you are in good shape.")
            print("No updates are available.")
        try:
            msg = input("\n  == Do you want to leave any message?\n(Press enter to finish)\n\n").strip()
        except KeyboardInterrupt:
            msg = None

        if msg:
            msg = urlquote(msg)
            try:
                f = urlopen('http://etetoolkit.org/static/et_phone_home.php?VERSION=%s&ID=%s&MSG=%s'
                                %(__version__, __ETEID__, msg))
            except:
                print("Message could be delivered :(")
            else:
                print("Message delivered")

def new_version(module_name=None, current=None):
    if not module_name:
        module_name = __name__.split(".")[0]
    try:
        f = urlopen('http://etetoolkit.org/releases/ete3/%s.latest'
                        %module_name)
    except:
Ejemplo n.º 19
0
def get_feed_render_info(url,feed_dict=None):
        return dict(get_feed_info(url,feed_dict),
            button_html='<form class="inline-form noborder" method="post" action="{0}">{1}</form>'.format(
                web.url('/channel'), urlquote(channel_form({'csrf_token':csrf_token(),'url':url}).render_css())))
Ejemplo n.º 20
0
def cite_info (oitem, context):
    """Create a Holder with citation text from a publication item. This can then
    be fed into a template however one wants. The various computed fields are
    are Unicode or Markups.

    `oitem` = original item; not to be modified
    `aitem` = augmented item; = oitem + new fields
    """

    aitem = oitem.copy ()

    # Canonicalized authors with bolding of self and underlining of advisees.
    cauths = [canonicalize_name (a) for a in oitem.authors.split (';')]

    myidx = int (oitem.mypos) - 1
    cauths[myidx] = MupBold (cauths[myidx])

    advposlist = oitem.get ('advpos', '')
    if len (advposlist):
        for i in [int (x) - 1 for x in advposlist.split (',')]:
            cauths[i] = MupUnderline (cauths[i])

    aitem.full_authors = MupJoin (', ', cauths)

    # Short list of authors, possibly abbreviating my name.
    sauths = [surname (a) for a in oitem.authors.split (';')]
    if context.my_abbrev_name is not None:
        sauths[myidx] = context.my_abbrev_name

    if len (advposlist):
        for i in [int (x) - 1 for x in advposlist.split (',')]:
            sauths[i] = MupUnderline (sauths[i])

    if len (sauths) == 1:
        aitem.short_authors = sauths[0]
    elif len (sauths) == 2:
        aitem.short_authors = MupJoin (' & ', sauths)
    elif len (sauths) == 3:
        aitem.short_authors = MupJoin (', ', sauths)
    else:
        aitem.short_authors = MupJoin (' ', [sauths[0], 'et' + nbsp + 'al.'])

    if oitem.refereed == 'y':
        aitem.refereed_mark = u'»'
    else:
        aitem.refereed_mark = u''

    # Title with replaced quotes, for nesting in double-quotes, and
    # optionally-bolded for first authorship.
    aitem.quotable_title = oitem.title.replace (u'“', u'‘').replace (u'”', u'’')

    if myidx == 0:
        aitem.bold_if_first_title = MupBold (oitem.title)
    else:
        aitem.bold_if_first_title = oitem.title

    # Pub year and nicely-formatted date
    aitem.year, aitem.month = map (int, oitem.pubdate.split ('/'))
    aitem.pubdate = u'%d%s%s' % (aitem.year, nbsp, months[aitem.month - 1])

    # Template-friendly citation count
    citeinfo = parse_ads_cites (oitem)
    if citeinfo is not None and citeinfo.cites > 0:
        aitem.citecountnote = u' [%d]' % citeinfo.cites
    else:
        aitem.citecountnote = u''

    # Citation text with link
    url = best_url (oitem)
    if url is None:
        aitem.lcite = aitem.cite
    else:
        aitem.lcite = MupLink (url, aitem.cite)

    # Other links for the web pub list
    from urllib2 import quote as urlquote

    aitem.abstract_link = u''
    aitem.preprint_link = u''
    aitem.official_link = u''
    aitem.other_link = u''

    if oitem.has ('bibcode'):
        aitem.abstract_link = MupLink ('http://adsabs.harvard.edu/abs/' + urlquote (oitem.bibcode),
                                      'abstract')

    if oitem.has ('arxiv'):
        aitem.preprint_link = MupLink ('http://arxiv.org/abs/' + urlquote (oitem.arxiv),
                                      'preprint')

    if oitem.has ('doi'):
        aitem.official_link = MupLink ('http://dx.doi.org/' + urlquote (oitem.doi),
                                      'official')

    if oitem.has ('url') and not oitem.has ('doi'):
        aitem.other_link = MupLink (oitem.url, oitem.kind)

    return aitem
Ejemplo n.º 21
0
def cite_info(oitem, context):
    """Create a Holder with citation text from a publication item. This can then
    be fed into a template however one wants. The various computed fields are
    are Unicode or Markups.

    `oitem` = original item; not to be modified
    `aitem` = augmented item; = oitem + new fields
    """

    aitem = oitem.copy()

    # Canonicalized authors with bolding of self and underlining of advisees.
    cauths = [canonicalize_name(a) for a in oitem.authors.split(";")]

    myidx = int(oitem.mypos) - 1
    cauths[myidx] = MupBold(cauths[myidx])

    advposlist = oitem.get("advpos", "")
    if len(advposlist):
        for i in [int(x) - 1 for x in advposlist.split(",")]:
            cauths[i] = MupUnderline(cauths[i])

    aitem.full_authors = MupJoin(", ", cauths)

    # Short list of authors, possibly abbreviating my name.
    sauths = [surname(a) for a in oitem.authors.split(";")]
    if context.my_abbrev_name is not None:
        sauths[myidx] = context.my_abbrev_name

    if len(advposlist):
        for i in [int(x) - 1 for x in advposlist.split(",")]:
            sauths[i] = MupUnderline(sauths[i])

    if len(sauths) == 1:
        aitem.short_authors = sauths[0]
    elif len(sauths) == 2:
        aitem.short_authors = MupJoin(" & ", sauths)
    elif len(sauths) == 3:
        aitem.short_authors = MupJoin(", ", sauths)
    else:
        aitem.short_authors = MupJoin(" ", [sauths[0], "et" + nbsp + "al."])

    if oitem.refereed == "y":
        aitem.refereed_mark = u"»"
    else:
        aitem.refereed_mark = u""

    # Title with replaced quotes, for nesting in double-quotes, and
    # optionally-bolded for first authorship.
    aitem.quotable_title = oitem.title.replace(u"“", u"‘").replace(u"”", u"’")

    if myidx == 0:
        aitem.bold_if_first_title = MupBold(oitem.title)
    else:
        aitem.bold_if_first_title = oitem.title

    # Pub year and nicely-formatted date
    aitem.year, aitem.month = map(int, oitem.pubdate.split("/"))
    aitem.pubdate = u"%d%s%s" % (aitem.year, nbsp, months[aitem.month - 1])

    # Template-friendly citation count
    citeinfo = parse_ads_cites(oitem)
    if citeinfo is not None and citeinfo.cites > 0:
        aitem.citecountnote = u" [%d]" % citeinfo.cites
    else:
        aitem.citecountnote = u""

    # Citation text with link
    url = best_url(oitem)
    if url is None:
        aitem.lcite = aitem.cite
    else:
        aitem.lcite = MupLink(url, aitem.cite)

    # Other links for the web pub list
    from urllib2 import quote as urlquote

    aitem.abstract_link = u""
    aitem.preprint_link = u""
    aitem.official_link = u""
    aitem.other_link = u""

    if oitem.has("bibcode"):
        aitem.abstract_link = MupLink("http://adsabs.harvard.edu/abs/" + urlquote(oitem.bibcode), "abstract")

    if oitem.has("arxiv"):
        aitem.preprint_link = MupLink("http://arxiv.org/abs/" + urlquote(oitem.arxiv), "preprint")

    if oitem.has("doi"):
        aitem.official_link = MupLink("http://dx.doi.org/" + urlquote(oitem.doi), "official")

    if oitem.has("url") and not oitem.has("doi"):
        aitem.other_link = MupLink(oitem.url, oitem.kind)

    return aitem
Ejemplo n.º 22
0
 def html(self):
     html = self['text']
     html = re.sub(r'(https?://[^\s,]+)', r'<a href="\1">\1</a>', html)
     html = re.sub(r'(#\w+)', lambda m: r'<a class="hash-link" href="http://twitter.com/#!/search?q=%s">%s</a>' % (urlquote(m.group(1)), m.group(1)), html)
     html = re.sub(r'@(\w+)', r'<a class="user-link" href="http://twitter.com/#!/\1">@\1</a>', html)
     html = re.sub(r'https?://t\.co/\w+', lambda m: self['unshortened_links'].get(m.group(0), m.group(0)), html)
     return html
Ejemplo n.º 23
0
 def _pdf_link(self):
     return urlquote(u"file://%s" % self.pdf_path, safe='/:')
Ejemplo n.º 24
0
    def format_url(self, name):
	return self.search_url % (urlquote(name), )
Ejemplo n.º 25
0
def url_encode(input, errors="strict"):
    output = urlquote(input)
    return (output, len(input))
Ejemplo n.º 26
0
 def quote(self, string, safe='/'):
     return urlquote(string, safe)