Esempio n. 1
0
def start_section(learn):
    result = learn.SetListeningResponseInformation('0', '0')
    status = result['SetListeningResponseInformationResult']
    if status == '1':
        library.success('started section ' + learn.SectionID + ' successfully')
    else:
        library.fail('started section ' + learn.SectionID + ' failed')
        exit()
    return status
Esempio n. 2
0
def update_unit(learn):
    result = learn.SetListeningUnitLearnStaus('1')
    status = result['SetListeningUnitLearnStausResult']
    if status == '1':
        library.success('update unit learn status success: unit ' +
                        learn.UnitID)
    else:
        library.fail('update unit learn status fail: unit ' + learn.UnitID)
        exit()
    return status
Esempio n. 3
0
def login(learn):
    result = learn.LoginListening()
    status = result['LoginListeningResult']
    if status == '1':
        library.warning('user ' + learn.username + ' need activation')
        exit()
    elif status != '2':
        library.fail('user ' + learn.username + ' login failed: ' +
                     result['ReturnMessage'])
        exit()
    else:
        library.success('user ' + learn.username + ' login successfully')
    return status
Esempio n. 4
0
 def __check_connect(self):
     if self.available == 0:
         try:
             r = requests.get('http://' + self.path +
                              '/WebService/ServiceV3.asmx?WSDL',
                              headers={
                                  'Content-Type':
                                  'application/x-www-form-urlencoded'
                              })
             text = r.text
             if text.find('LoginListeningResponse') != -1:
                 self.available = 1
         except:
             library.fail('fail to connect server: ' + self.path)
             exit()
     return
Esempio n. 5
0
def end_section(learn, score):
    result = learn.SetListeningResponseInformation("%.1f" % score, '1')
    status = result['SetListeningResponseInformationResult']
    if status == '1':
        library.success('ended section ' + learn.SectionID +
                        ' successfully: score ' + "%.1f" % score)
    else:
        library.fail('ended section ' + learn.SectionID + ' failed')
        # Retry login
        status = login(learn)
        # Retry set response
        result = learn.SetListeningResponseInformation("%.1f" % score, '1')
        status = result['SetListeningResponseInformationResult']
        if status == '1':
            library.success('ended section ' + learn.SectionID +
                            ' successfully: score ' + "%.1f" % score)
        else:
            library.fail('ended section ' + learn.SectionID + ' failed twice')
            exit()
    return status
Esempio n. 6
0
def active(learn, SerialNumber, LicenseNumber, ActivationCode):
    result = learn.LoginListening()
    status = result['LoginListeningResult']
    if status == '2':
        library.warning('user ' + learn.username + ' have been actived')
        return '1'
    elif status != '1':
        if result['ReturnMessage'].find('Activation') == -1:
            library.fail('user ' + learn.username + ' login failed: ' +
                         result['ReturnMessage'])
            exit()

    result = learn.SetListeningUserActiveInfo(SerialNumber, LicenseNumber,
                                              ActivationCode)
    status = result['SetListeningUserActiveInfoResult']
    if status == '1':
        library.success('user ' + learn.username + ' active successfully')
    else:
        library.fail('user ' + learn.username + ' active failed: ' +
                     result['ReturnMessage'])
        exit()
    return status
Esempio n. 7
0
def end_section(learn, score):
    if int(score) == score:
        score_str = "%d" % int(score)
    else:
        score_str = "%.1f" % score
    result = learn.SetReadingResponseInformation(score_str, '1')
    status = result['SetReadingResponseInformationResult']
    if status == '1':
        library.success('ended section ' + learn.SectionID +
                        ' successfully: score ' + score_str)
    else:
        library.fail('ended section ' + learn.SectionID + ' failed')
        # Retry login
        status = login(learn)
        # Retry set response
        result = learn.SetReadingResponseInformation(score_str, '1')
        status = result['SetReadingResponseInformationResult']
        if status == '1':
            library.success('ended section ' + learn.SectionID +
                            ' successfully: score ' + score_str)
        else:
            library.fail('ended section ' + learn.SectionID + ' failed twice')
            exit()
    return status
Esempio n. 8
0
                    except:
                        obj[name] = None
                    if var[name] is None:
                        var[name] = obj[name]
                    elif var[name] != obj[name]:
                        obj[name] = var[name]

        sync(var, obj, [name for name in var])
        f.seek(0)
        f.truncate()  # discard the previous config or the file might go wrong
        json.dump(obj, f)

# check necessary arguments
if var['path'] is None or var['username'] is None or var['password'] is None \
        or var['type'] is None or var['level'] is None:
    library.fail('missing required var')
    exit()

# Var init
if var['type'] == 'rwt':
    from rwt import *

    learn = learn_rwt(var['path'], var['username'], var['password'],
                      var['level'])
else:
    from vls import *

    learn = learn_vls(var['path'], var['username'], var['password'],
                      var['level'])
# Activation
if args.activation == True: