Пример #1
0
def weekDaily():
    """tasks for weekdays"""
    # POST NEW TOP SONG
    periods = ["month", "week"]
    tops = []

    print "Logging in to reddit and retriving top rr song for for the week and month"
    rio = RedditIO()

    for period in periods:
        top = rio.getTopSong(period)
        tops.append(top)
        if top:
            print "Top song retrieved for", period, top
            # check for old post
            last = Last()
            if last.isStored(top):
                print "Not a new song.  Done."
            else:
                print "Is a new song!"
                # post to reddit
                print "Posting to reddit ..."
                try:
                    rio.postToReddit("music", "top for the %s on radio reddit: %s" % (period, top.title), top.url)
                    print "All done here!"
                except:
                    e = sys.exc_info()[1]
                    fatalError("Error: %s" % e)
                print "Posting to twitter ..."
                twit = TwitterIO()
                twit.postToTwitter("New top song: %s %s" % (top.title, top.url))
        else:
            fatalError("No top song found, time to die.")
    # store tops
    last.store(tops)
Пример #2
0
def weekDaily():
    """tasks for weekdays"""
    # POST NEW TOP SONG
    periods = ['month','week']
    tops = []

    print 'Logging in to reddit and retriving top rr song for for the week and month'
    rio = RedditIO()

    for period in periods:
        top = rio.getTopSong(period)
        tops.append(top)
        if top:
            print 'Top song retrieved for', period, top
            # check for old post
            last = Last()
            if last.isStored(top):
                print 'Not a new song.  Done.'
            else:
                print 'Is a new song!'
                # post to reddit
                print 'Posting to reddit ...'
                try:
                    rio.postToReddit('music','top for the %s on radio reddit: %s' % (period, top.title), top.url)
                    print 'All done here!'
                except:
                    e = sys.exc_info()[1]
                    fatalError("Error: %s" % e)
                print 'Posting to twitter ...'
                twit = TwitterIO()
                twit.postToTwitter('New top song: %s %s' % (top.title, top.url))
        else:
            fatalError('No top song found, time to die.')
    # store tops
    last.store(tops)
Пример #3
0
def insertStatementBefore(statement, target):
    """
    Insert target before statement in the AST, and correct the AST and CFG references to match
    """
    # TODO: Does this need to correct incoming GOTOs or is that handled by adjusting the AST edges
    
    if statement.parent is None:
        errors.fatalError("Cannot insert statement before %s at line %s" % (statement, statement.lineNum))
    
    parent_list = getattr(statement.parent, statement.parent_property)
    
    if isinstance(parent_list, list):
        parent_list.insert(statement.parent_index, target)
        target.parent = statement.parent
        target.parent_property = statement.parent_property
        target.parent_index = statement.parent_index
        statement.parent_index += 1
                  
    else:
        errors.fatalError("Cannot insert statement into non-list %s at line %s" % (statement, statement.lineNum))
        return
        
    # Reconnect CFG
    for prior_stmt in statement.inEdges:
        assert statement in prior_stmt.outEdges
        prior_stmt.outEdges.remove(statement)
        prior_stmt.outEdges.add(target)
        target.inEdges.add(prior_stmt)
    
    statement.clearInEdges()    
    statement.addInEdge(target)
    
    target.clearOutEdges()
    target.addOutEdge(statement)
 def visitNext(self, next_stmt):
     logging.debug("NEXT statement = %s", next_stmt)
     #logging.debug("NEXT identifiers = %s", next_stmt.identifiers[0].identifier)
     while True:
         if len(self.loops) == 0:
             errors.fatalError("Not in a FOR loop at line %d." % next_stmt.lineNum)
         peek = self.loops[-1]
         if not isinstance(peek, ForToStep):
             errors.fatalError("Not in a FOR loop at line %d; currently in %s loop opened at line %d" % (next_stmt.lineNum, peek.description, peek.lineNum))
         
         for_stmt = self.loops.pop()
         # If the next_stmt has no attached identifiers, it applies to the
         # top FOR statement on the stack
         if len(next_stmt.identifiers) == 0:
              next_stmt.identifiers.append(for_stmt.identifier)
         id1 = for_stmt.identifier.identifier
         print next_stmt.identifiers
         id2 = next_stmt.identifiers[0].identifier
         print "self.loops = ", self.loops
         print "id1 = ", id1
         print "id2 = ", id2
         # TODO: Check that the symbols are equal, not just the names
         if for_stmt.identifier.identifier == next_stmt.identifiers[0].identifier:
             connectLoop(next_stmt, for_stmt)
             break    
 def visitEndwhile(self, endwhile_stmt):
     if len(self.loops) == 0:
         errors.fatalError("Not in a WHILE loop at line %d." % endwhile_stmt.lineNum)
     peek = self.loops[-1]
     if not isinstance(peek, While):
         errors.fatalError("Not in a WHILE loop at line %d; currently in %s loop opened at line %d" % (endwhile_stmt.lineNum, peek.description, peek.lineNum))
     while_stmt = self.loops.pop()
     connectLoop(endwhile_stmt, while_stmt)
 def visitUntil(self, until_stmt):
     if len(self.loops) == 0:
         errors.fatalError("Not in a REPEAT loop at line %d." % until_stmt.lineNum)
     peek = self.loops[-1]
     if not isinstance(peek, Repeat):
         errors.fatalError("Not in a REPEAT loop at line %d; currently in %s loop opened at line %d" % (until_stmt.lineNum, peek.description, peek.lineNum))
     repeat_stmt = self.loops.pop()
     connectLoop(until_stmt, repeat_stmt)
 def depthFirstSearch(self, entry_point):
     self.to_visit.append(entry_point)
     while len(self.to_visit):
         v = self.to_visit.pop()
         # Restore the loop stack
         if hasattr(v, "loop_stack"):
             self.loops = v.loop_stack[:]
         if v not in self.visited:
             self.visited.add(v)
             v.accept(self)
             if len(v.outEdges) == 0 and len(self.loops) != 0:
                 # TODO: Improve this error message by printing an
                 # abstract stack trace
                 errors.fatalError("In loops at terminal statement at line %s" % v.lineNum)
             # If execution splits, take a copy of the current loop stack
             # and store a reference to it on each of the target nodes of
             # the out edges of the current node, so the state can be
             # restored later in the traversal
             if len(v.outEdges) > 1:
                 loop_stack = self.loops[:]
                 for target in v.outEdges:
                     target.loop_stack = loop_stack
             self.to_visit.extend(v.outEdges)
Пример #8
0
def removeStatement(statement):
    """
    Remove the statement from the AST
    """
    if statement.parent is None:
        errors.fatalError("Cannot remove statement %s at line %s" % (statement, statement.lineNum))
        
    # Remove from the parent list
    parent_list = getattr(statement.parent, statement.parent_property)
    parent_list.remove(statement)
    
    # Reconnect CFG
    for prior_stmt in statement.inEdges:
        assert statement in prior_stmt.outEdges
        prior_stmt.outEdges.remove(statement)
        prior_stmt.outEdges.update(statement.outEdges)
        
    for next_stmt in statement.outEdges:
        assert statement in next_stmt.inEdges
        next_stmt.inEdges.remove(statement)
        next_stmt.inEdges.update(statement.inEdges)

    statement.clearInEdges()
    statement.clearOutEdges()