예제 #1
0
def sabnzbdMakeUrl(extrapart):
    config = readSettings();
    useSSL = '';
    if config.get('nzb_ssl') == 'yes':
        useSSL = 's';
    url = 'http' + useSSL + '://' + config.get('nzb_ip') + ':' + str(config.get('nzb_port')) + '/sabnzbd/api?' + extrapart + '&output=json&apikey=' + config.get('nzb_apikey') + '&ma_username='******'nzb_username') + '&ma_password='******'nzb_password');
    return url
예제 #2
0
파일: run.py 프로젝트: csangani/Moss
def CrossQuarterAnalysis(courseNumber, assignmentName, currentQuarter, quarters):

    assignmentSettings = st.readSettings('{}/{}/{}'.format(moss.archivePath, courseNumber, assignmentName))
        
    # Build file list
    extensions = list(moss.languages[assignmentSettings['language']])
    
    IDs = moss.ListIDs(courseNumber, assignmentName, currentQuarter) + [f.split('/')[-2] for f in glob.glob('{}/{}/{}/multiple/*/{}'.format(moss.archivePath, courseNumber, assignmentName, currentQuarter))]
    
    files = []
    for q in set(quarters + [currentQuarter]):
        for e in extensions:
            f = glob.glob('{}/{}/{}/{}/*/{}'.format(moss.archivePath, courseNumber, assignmentName, q, e))
            if f is not None: files += f
            
    for e in extensions:
        files2 = glob.glob('{}/{}/{}/multiple/*/*/{}'.format(moss.archivePath, courseNumber, assignmentName, e))
        
    if len(files) + len(files2) == 0: raise Exception("No files found")
    
    files = dict([('{}{}/{}'.format(('{}/'.format(moss.InterpretQuarter(f.split('/')[-3])) if f.split('/')[-3] != currentQuarter else ''), f.split('/')[-2], f.split('/')[-1]), f) for f in files])
    
    files.update(dict([('{}/{}/{}-{}'.format(moss.InterpretQuarter(f.split('/')[-4]), f.split('/')[-3], moss.InterpretQuarter(f.split('/')[-2]), f.split('/')[-1]) if f.split('/')[-3] not in IDs else '{}/{}'.format(f.split('/')[-3], f.split('/')[-1]), f) for f in files2 if f.split('/')[-3] not in IDs or (f.split('/')[-3] in IDs and f.split('/')[-2] == currentQuarter)]))
        
    # Check for starter code
    baseFiles = None
    if os.path.isfile('{}/{}/{}/{}/base'.format(moss.starterCodePath, courseNumber, assignmentName, currentQuarter)):
        baseFiles = ['{}/{}/{}/{}/base'.format(moss.starterCodePath, courseNumber, assignmentName, currentQuarter)]
    else:
        baseFiles = []
        
    # Run MOSS
    return RunMoss(files, assignmentSettings['language'], baseFiles, 'Course: {}<br/>Assignment: {}<br/>Current Quarter: {}<br/>Compared Against: {}'.format(courseNumber.upper(), assignmentName.capitalize(), moss.InterpretQuarter(currentQuarter), quarters))
예제 #3
0
def xbmcGetThumb(thumb, thumbWidth, thumbHeight, thumbOpacity):

    thumbParts = thumb.split('/')
    thumbFile = thumbParts.pop()

    xbmc_thumbs = os.path.join(htpc.userdata, 'xbmc_thumbs/')
    if not os.path.isdir(xbmc_thumbs):
        os.makedirs(xbmc_thumbs)

    thumbOnDisk = os.path.join(xbmc_thumbs, thumbFile)
    if not os.path.isfile(thumbOnDisk + '_' + thumbWidth + '_' + thumbHeight +
                          '.png'):

        config = readSettings()
        url = 'http://' + config.get('xbmc_ip') + ':' + str(
            config.get('xbmc_port')) + '/vfs/' + thumb

        request = urllib2.Request(url)
        base64string = base64.encodestring(
            '%s:%s' % (config.get('xbmc_username'),
                       config.get('xbmc_password'))).replace('\n', '')
        request.add_header("Authorization", "Basic %s" % base64string)
        fileObject = urllib2.urlopen(request)

        fileData = fileObject.read()

        # Thumbnail opslaan
        f = open(thumbOnDisk, 'wb')
        f.write(fileData)
        f.close()

        # Plaatje resizen
        thumbOpacity = float(thumbOpacity)
        enhanceOpacity = (thumbOpacity / 100)

        width = int(thumbWidth)
        height = int(thumbHeight)
        image = Image.open(thumbOnDisk)
        newimage = image.resize((width, height),
                                Image.ANTIALIAS).convert('RGBA')
        alpha = newimage.split()[3]
        alpha = ImageEnhance.Brightness(alpha).enhance(enhanceOpacity)
        newimage.putalpha(alpha)
        newimage.save(thumbOnDisk + '_' + thumbWidth + '_' + thumbHeight +
                      '.png')

        # Oude weg gooien
        os.unlink(thumbOnDisk)

    # Plaatje weer uitlezen
    f = open(thumbOnDisk + '_' + thumbWidth + '_' + thumbHeight + '.png', 'rb')
    data = f.read()
    f.close()

    # Header setten en data returnen
    cherrypy.response.headers['Content-Type'] = "image/png"
    return data
예제 #4
0
def xbmcMakeUrl():
    config = readSettings()
    if config.has_key('xbmc_port') and config.has_key(
            'xbmc_ip') and config.has_key('xbmc_username') and config.has_key(
                'xbmc_password'):
        url = 'http://' + config.get('xbmc_username') + ':' + config.get(
            'xbmc_password') + '@' + config.get('xbmc_ip') + ':' + str(
                config.get('xbmc_port'))
        return url
예제 #5
0
def sabnzbdMakeUrl(extrapart):
    config = readSettings()
    useSSL = ''
    if config.get('nzb_ssl') == 'yes':
        useSSL = 's'
    url = 'http' + useSSL + '://' + config.get('nzb_ip') + ':' + str(
        config.get('nzb_port')
    ) + '/sabnzbd/api?' + extrapart + '&output=json&apikey=' + config.get(
        'nzb_apikey') + '&ma_username='******'nzb_username') + '&ma_password='******'nzb_password')
    return url
예제 #6
0
    def _index(self, client):
        ip = self.wifiManager.getIp()
        netId, essid, group = settings.readSettings()

        interpolate = {
            "IP": ip,
            "NET_ID": netId,
            "ESSID": essid,
            "GROUP": group
        }

        self.webServer.index(client, interpolate)
예제 #7
0
def xbmcNotify(text):
    text = urllib2.unquote(text)
    config = readSettings()
    command = {'command': 'ExecBuiltIn', 'parameter': 'Notification(\'HTPC Manager\', \'' + text + '\')' }
    url = 'http://' + config.get('xbmc_ip') + ':' + str(config.get('xbmc_port')) + '/xbmcCmds/xbmcHttp/?' + urllib.urlencode(command)

    request = urllib2.Request(url)
    base64string = base64.encodestring('%s:%s' % (config.get('xbmc_username'), config.get('xbmc_password'))).replace('\n', '')
    request.add_header("Authorization", "Basic %s" % base64string)
    result = urllib2.urlopen(request)

    return result.read()
예제 #8
0
파일: moss.py 프로젝트: csangani/Moss
def Run():
    try:
        print """   __  __  ___  ____ ____  
  |  \/  |/ _ \/ ___/ ___| 
  | |\/| | | | \___ \___ \ 
  | |  | | |_| |___) |__) |
  |_|  |_|\___/|____/____/
"""
        # Setup autocomplete
        readline.parse_and_bind("tab: complete")
        readline.set_completer(Completer)

        # Load global settings
        settings = st.readSettings(scriptDir)
        
        if set(settings.keys()) == set(settingsDescriptions.keys()):
            try:
                for s in settings:
                    print "{}: {}".format(settingsDescriptions[s], settings[s])
                answer = None
                while answer != 'Y' and answer != 'n' and answer != '':
                    answer = raw_input("Is the above information correct? [Y/n]: ")
                    
                if answer == 'n':
                    settings = dict()
            finally:
                print
        
        # Check that all global settings are valid
        if len(settings) != len(settingsDescriptions) and len(settingsDescriptions) != 0:
            try:
                print "Please enter the following information:"
                for s in settingsDescriptions:
                    if s not in settings:
                        settings[s] = raw_input('{}: '.format(settingsDescriptions[s]))
                st.writeSettings(scriptDir, settings)
            finally:    
                print

        modes = ["Run MOSS", "Archive submissions"]
        mode = modes.index(ui.selectOption('What would you like to do?', modes))

        if mode == 0:
            run.RunMode(settings)
        elif mode == 1:
            archive.ArchiveMode(settings)
        else:
            raise Exception('Invalid mode')
    
    except KeyboardInterrupt, SystemExit:
        print '\nCancelled!'
예제 #9
0
def xbmcGetThumb(thumb, thumbWidth, thumbHeight, thumbOpacity):

    thumbParts = thumb.split('/')
    thumbFile = thumbParts.pop()

    xbmc_thumbs = os.path.join(htpc.userdata, 'xbmc_thumbs/')
    if not os.path.isdir(xbmc_thumbs):
        os.makedirs(xbmc_thumbs)

    thumbOnDisk = os.path.join(xbmc_thumbs, thumbFile)
    if not os.path.isfile(thumbOnDisk + '_' + thumbWidth + '_' + thumbHeight + '.png'):

        config = readSettings()
        url = 'http://' + config.get('xbmc_ip') + ':' + str(config.get('xbmc_port')) + '/vfs/' + thumb

        request = urllib2.Request(url)
        base64string = base64.encodestring('%s:%s' % (config.get('xbmc_username'), config.get('xbmc_password'))).replace('\n', '')
        request.add_header("Authorization", "Basic %s" % base64string)
        fileObject = urllib2.urlopen(request)

        fileData = fileObject.read()

        # Thumbnail opslaan
        f = open(thumbOnDisk, 'wb')
        f.write(fileData)
        f.close()

        # Plaatje resizen
        thumbOpacity = float(thumbOpacity)
        enhanceOpacity = (thumbOpacity / 100)

        width = int(thumbWidth)
        height = int(thumbHeight)
        image = Image.open(thumbOnDisk)
        newimage = image.resize((width, height), Image.ANTIALIAS).convert('RGBA')
        alpha = newimage.split()[3]
        alpha = ImageEnhance.Brightness(alpha).enhance(enhanceOpacity)
        newimage.putalpha(alpha)
        newimage.save(thumbOnDisk + '_' + thumbWidth + '_' + thumbHeight + '.png')

        # Oude weg gooien
        os.unlink(thumbOnDisk)

    # Plaatje weer uitlezen
    f = open(thumbOnDisk + '_' + thumbWidth + '_' + thumbHeight + '.png', 'rb')
    data = f.read()
    f.close()

    # Header setten en data returnen
    cherrypy.response.headers['Content-Type'] = "image/png"
    return data
예제 #10
0
파일: run.py 프로젝트: csangani/Moss
def RunMode(settings):
    # Select course
    courseNumber = ui.selectOption('Select a course:', moss.ListCourses(), transform = string.upper)

    # Select assignment
    assignmentName = ui.selectOption('Select an assignment:', moss.ListAssignments(courseNumber), transform = string.capitalize)
    
    # Load assignment settings
    assignmentSettings = st.readSettings('{}/{}/{}'.format(moss.archivePath, courseNumber, assignmentName))
    
    # Check for assignment settings validity
    if 'language' not in assignmentSettings:
        assignmentSettings['language'] = ui.selectOption("Select language: ", moss.languages.keys())
        st.writeSettings('{}/{}/{}'.format(moss.archivePath, courseNumber, assignmentName), assignmentSettings)

    modes = ['Run MOSS on submissions from a single quarter',
             'Run MOSS on submissions from multiple quarters',
             'Run MOSS on current quarter submissions for specific SUnet IDs']

    mode = modes.index(ui.selectOption('What would you like to do?', modes))

    if mode == 0:
    
        quarter = ui.selectOption('Select a quarter:', moss.ListQuarters(courseNumber, assignmentName), transform = moss.InterpretQuarter)
        result = IntraQuarterAnalysis(courseNumber, assignmentName, quarter)
        
    elif mode == 1:
    
        currentQuarter = ui.selectOption('Select current quarter:', moss.ListQuarters(courseNumber, assignmentName), transform = moss.InterpretQuarter)
        quarters = ui.askQuestion('Please enter a comma-separated list of quarters to compare against (wildcards will be expanded) [default: *]:').split(',')
        quarters = [q.strip() for q in quarters]
        if '' in quarters: quarters.remove('')
        if len(quarters) == 0: quarters = ['*']
        result = CrossQuarterAnalysis(courseNumber, assignmentName, currentQuarter, quarters)
        
    elif mode == 2:
    
        quarter = ui.selectOption('Select current quarter:', moss.ListQuarters(courseNumber, assignmentName), transform = moss.InterpretQuarter)
        IDs = ui.askQuestion('Please enter a comma-separated list of SUnet IDs:').split(',')
        IDs = [i.strip() for i in IDs]
        result = SpecificAnalysis(courseNumber, assignmentName, quarter, IDs)
        
    print "Result: {}\n".format(result)
예제 #11
0
def xbmcNotify(text):
    text = urllib2.unquote(text)
    config = readSettings()
    command = {
        'command': 'ExecBuiltIn',
        'parameter': 'Notification(\'HTPC Manager\', \'' + text + '\')'
    }
    url = 'http://' + config.get('xbmc_ip') + ':' + str(config.get(
        'xbmc_port')) + '/xbmcCmds/xbmcHttp/?' + urllib.urlencode(command)

    request = urllib2.Request(url)
    base64string = base64.encodestring(
        '%s:%s' %
        (config.get('xbmc_username'), config.get('xbmc_password'))).replace(
            '\n', '')
    request.add_header("Authorization", "Basic %s" % base64string)
    result = urllib2.urlopen(request)

    return result.read()
예제 #12
0
파일: run.py 프로젝트: csangani/Moss
def SpecificAnalysis(courseNumber, assignmentName, quarter):
    assignmentSettings = st.readSettings('{}/{}/{}'.format(moss.archivePath, courseNumber, assignmentName))
    
    # Make sure (courseNumber, assignmentName, quarter) is valid
    if not os.path.isdir('{}/{}/{}/{}'.format(moss.archivePath, courseNumber, assignmentName, quarter)):
        print "No submissions found for course {} assignment {} in quarter {}".format(courseNumber, assignmentName, quarter)
	return

    # Check for assignment settings
    if 'language' not in assignmentSettings:
        assignmentSettings['language'] = ui.selectOption("Select language: ", moss.languages.keys())
        st.writeSettings('{}/{}/{}'.format(moss.archivePath, courseNumber, assignmentName), assignmentSettings)
        
    # Check validity of patterns
    extensions = list(moss.languages[assignmentSettings['language']])
    
    dirs = [d for d in os.listdir('{}/{}/{}'.format(moss.archivePath, courseNumber, assignmentName)) if os.path.isdir('{}/{}/{}/{}'.format(moss.archivePath, courseNumber, assignmentName, d))]
    dirs.remove(quarter)
    if 'multiple' in dirs: dirs.remove('multiple')
    
    patterns = ['*/{}'.format(e) for e in extensions] + ['../{}/*/{}'.format(d, e) for d in dirs for e in extensions]
    
    rejects = []
    cwd = os.getcwd()
    os.chdir('{}/{}/{}/{}'.format(moss.archivePath, courseNumber, assignmentName, quarter))
    for p in patterns:
        try:
            glob.iglob(p).next()
        except StopIteration:
            rejects += [p]
    for r in rejects:
        patterns.remove(r)
        
    # Check for starter code
    baseFiles = None
    if os.path.isfile('{}/{}/{}/{}/base'.format(moss.starterCodePath, courseNumber, assignmentName, quarter)):
        baseFiles = ['{}/{}/{}/{}/base'.format(moss.starterCodePath, courseNumber, assignmentName, quarter)]
    else:
        baseFiles = []
        
    # Run MOSS
    runMoss(moss.mossScript, '{}/{}/{}/{}'.format(moss.archivePath, courseNumber, assignmentName, quarter), patterns, language = assignmentSettings['language'], baseFiles = baseFiles, verbose = True)
예제 #13
0
def nzbMatrixMakeUrl(options):
    config = readSettings()
    if config.has_key('nzbmatrix_apikey'):
        url = 'http://api.nzbmatrix.com/v1.1/search.php?apikey=' + config.get(
            'nzbmatrix_apikey') + '&' + urllib.urlencode(options)
        return url
예제 #14
0
def sbMakeUrl(command):
    config = readSettings()
    if config.has_key('sb_port') and config.has_key('sb_ip') and config.has_key('sb_apikey'):
        url = 'http://' + config.get('sb_ip') + ':' + str(config.get('sb_port')) + '/api/' + config.get('sb_apikey') + '/?cmd=' + command;
        return url
예제 #15
0
def nzbMatrixMakeUrl(options):
    config = readSettings()
    if config.has_key('nzbmatrix_apikey'):
        url = 'http://api.nzbmatrix.com/v1.1/search.php?apikey=' + config.get('nzbmatrix_apikey') + '&' + urllib.urlencode(options)
        return url
예제 #16
0
def xbmcMakeUrl():
    config = readSettings()
    if config.has_key('xbmc_port') and config.has_key('xbmc_ip') and config.has_key('xbmc_username') and config.has_key('xbmc_password'):
        url = 'http://' + config.get('xbmc_username') + ':' + config.get('xbmc_password') + '@' + config.get('xbmc_ip') + ':' + str(config.get('xbmc_port'))
        return url