示例#1
0
    def settings(self, s):
        user = self.getSessionUser()
        if user is None or user.get('uid', '') == '':
            s.redirect('login?redirect_uri={0}'.format('settings'))
            return

        update = checkupdate()
        confJSON = json.dumps(configuration)
        public_url = getTunnelUrl()
        message = ''
        meta = '<!-- <meta http-equiv="refresh" content="5"> -->'
        code = readFile(os.path.join(FILE_DIR, CONFIGFILE))
        logs = readFile(os.path.join(logfilepath, LOGFILE))
        template = TEMPLATE.format(message=message,
                                   uptime=uptime(),
                                   list=deviceList,
                                   meta=meta,
                                   code=code,
                                   conf=confJSON,
                                   public_url=public_url,
                                   logs=logs,
                                   update=update,
                                   branch=branch,
                                   dzversion=settings['dzversion'])

        s.send_message(200, template)
示例#2
0
def mergeLines(filePathBase, filePathNew, filePathLatest, copyPath, f, new=False):
    conflict = False
    conflicts = ''
    baseLines = helpers.readFile(filePathBase)
    newLines = helpers.readFile(filePathNew)
    latestLines = helpers.readFile(filePathLatest)
    baseLines = [line.rstrip() for line in baseLines]
    newLines = [line.rstrip() for line in newLines]
    latestLines = [line.rstrip() for line in latestLines]
    #print baseLines
    #print newLines
    #print latestLines

    mg = Merge3(baseLines, newLines, latestLines)
    merg = mg.merge_lines(name_a=filePathNew,name_b=filePathLatest,name_base=filePathBase)
    merged = '\n'.join(merg)
    #print merged
    if merged:
        if '<<<<<<<' in merged:
            s = 'Merge conflict in file '+ os.path.join(copyPath,f)
            print s
            conflicts = conflicts + '\n' + s
            conflict = True
        else:
            print 'Merged without conflict '+ os.path.join(copyPath,f)
        if not os.path.exists(copyPath):
            os.makedirs(copyPath)
        f = open(os.path.join(copyPath, f), 'w')
        f.write(merged)
        f.close()
    elif new:
        print 'Deleting file after merge '+ os.path.join(copyPath,f)
    return conflicts, conflict
示例#3
0
	def dataProvider_testRender(self):
		# 0
		yield '{{name}}', {'name': 'John'}, 'John'
		yield '{{names[0]}}', {'names': ['John', 'Tom']}, 'John'
		yield '{{concate(v1, v2)}}', {'v1': 'hello', 'v2': 'world', 'concate': lambda x,y: x+y}, 'helloworld'
		yield '{{R(v23)}}', {'v23': '"FALSE"'}, '\'"FALSE"\''
		yield '{{R(v3)}}', {'v3': 'false'}, "FALSE"
		# 5
		yield '{{realpath(v4)}}', {'v4': __file__}, path.realpath(__file__)
		#yield ('{{readlink(v5)}}', {'v5': path.join(path.dirname(path.realpath(path.abspath(__file__))), 'helpers.py')yield , path.relpath(path.jo(path.dirname(path.dirname(path.abspath(__file__))), 'bin', 'helpers.py'))),
		yield '{{dirname(v6)}}', {'v6': '/a/b/c'}, '/a/b'
		yield '{{basename(v7)}}{{bn(v7)}}', {'v7': '/a/b/c.txt'}, 'c.txtc.txt'
		yield '{{basename(v8)}}{{bn(v8)}}', {'v8': '/a/b/[1]c.txt'}, 'c.txtc.txt'
		yield '{{basename(v9, v9b)}}{{bn(v9, v9b)}}', {'v9': '/a/b/c.txt', 'v9b': True}, 'c.txtc.txt'
		# 10
		yield '{{basename(v10, v10b)}}{{bn(v10, v10b)}} {{ext(v10)}}', {'v10': '/a/b/c[1].txt', 'v10b': True}, 'c[1].txtc[1].txt .txt'
		yield '{{filename(v11)}}{{fn(v11)}} {{prefix(v11)}}', {'v11': '/a/b/a.txt'}, 'aa /a/b/a'
		yield '{{filename(v12)}}{{fn(v12)}}', {'v12': '/a/b/[1]b.txt'}, 'bb'
		yield '{{filename(v13, v13b)}}{{fn(v13, v13b)}}', {'v13': '/a/b/d.txt', 'v13b': True}, 'dd'
		yield '{{filename(v14, v14b)}}{{fn(v14, v14b)}}', {'v14': '/a/b/[1]c.txt', 'v14b': True}, '[1]c[1]c'
		# 15
		yield '{{R(var1)}}', {'var1': 'NULL'}, 'NULL'
		yield '{{R(var2)}}', {'var2': 'abc'}, "'abc'"
		yield '{% for var in varlist %}{{R(var)}}{% endfor %}', {'varlist': ['abc', 'True', 1, False]}, "'abc'TRUE1FALSE"
		yield '{% if bool(var3) %}1{% else %}0{% endif %}', {'var3': 'abc', 'bool': bool}, '1'
		yield '{% for k,v in data.items() %}{{k}}:{{v}}{% endfor %}', {'data': OrderedDict([('a', 1), ('b', 2)])}, 'a:1b:2'
		# 20
		yield '{{quote(a)}}', {'a':''}, '""'
		yield '{{R(x)}}', {'x': OrderedDict([(u'key1', 'val1'), ('key2', u'val2')])}, "list(`key1`='val1',`key2`='val2')"
		yield '{{asquote(b)}}', {'b':[1,2]}, '"1" "2"'
		yield '{{acquote(c)}}', {'c':[1,2]}, '"1", "2"'
		yield '{{squote(d)}}', {'d':'1'}, "'1'"
		# 25
		yield '{{json(e["f"])}}', {'e':{'f':[1,2]}}, '[1, 2]'
		yield '{{os.path.join(g,h)}}', {'g': 'a', 'h': 'b', 'os': __import__('os')}, 'a/b'
		yield """
		#!/usr/bin/env python
		{% if x %}
		{% for y in ylist %}
		{{y}}
		{% endfor %}
		{% endif %}
		""", {'x': True, 'ylist': [1,2,3,4,5]}, """
		#!/usr/bin/env python\n\t\t\n\t\t
		1\n\t\t
		2\n\t\t
		3\n\t\t
		4\n\t\t
		5\n\t\t
		\n\t\t"""
		yield '{{read(a)}}', {'a': __file__}, helpers.readFile(__file__)
		file2read = path.join(path.dirname(__file__), 'helpers.py')
		yield '{{"\\n".join(readlines(a))}}', {'a': file2read}, helpers.readFile(file2read, lambda x: '\n'.join(str(y) for y in x.splitlines() if y))
		yield '{{render(x)}}', {'x': '{{i}}', 'i': 2}, '2'
		yield '{{render(x[0])}}', {'x': ('{{i}}', 1), 'i': 2}, '2'
示例#4
0
文件: repo.py 项目: shivanshuag/gaea
def diff(id1=None,id2=None):
    head = globals.REPOINFO['HEAD']
    difference = ''
    if head != '0':
        if id1 == None:
            dir1 = os.path.join(globals.ROOT,'.gaea', 'snaps', head)
        else:
            id1 = helpers.getFullSnapId(id1)
            dir1 = os.path.join(globals.ROOT, '.gaea', 'snaps', id1)
        if id2 == None:
            dir2 = globals.ROOT
        else:
            id2 = helpers.getFullSnapId(id2)
            dir2 = os.path.join(globals.ROOT, '.gaea', 'snaps', id2)
        filesDone = []
        for root, subFolders, files in os.walk(dir2):
            if '.gaea' in subFolders:
                subFolders.remove('.gaea')
            for f in files:
                filesDone.append(os.path.join(os.path.relpath(root, dir2),f))
                filePath1 = os.path.join(dir1, os.path.relpath(root, dir2), f)
                filePath2 = os.path.join(root, f)
                f1 = helpers.readFile(filePath1)
                f2 = helpers.readFile(filePath2)
                unifiedDiff = difflib.unified_diff(f1, f2, fromfile=filePath1, tofile=filePath2)
                difference = difference + ''.join(unifiedDiff)
        for root, subFolders, files in os.walk(dir1):
            if '.gaea' in subFolders:
                subFolders.remove('.gaea')
            for f in files:
                if os.path.join(os.path.relpath(root, dir1), f) not in filesDone:
                    filePath1 = os.path.join(root, f)
                    filePath2 = os.path.join(dir2, os.path.relpath(root, dir1), f)
                    f1 = helpers.readFile(filePath1)
                    f2 = helpers.readFile(filePath2)
                    unifiedDiff = difflib.unified_diff(f1, f2, fromfile=filePath1, tofile=filePath2)
                    difference = difference + ''.join(unifiedDiff)


    else:
        dir2 = globals.ROOT
        for root, subFolders, files in os.walk(dir2):
            if '.gaea' in subFolders:
                subFolders.remove('.gaea')
            for f in files:
                filePath2 = os.path.join(root, f)
                f2 = helpers.readFile(filePath2)
                unifiedDiff = difflib.unified_diff('', f2, tofile=filePath2)
                difference = difference + ''.join(unifiedDiff)
    print difference
    return difference
示例#5
0
	def testSaveSettings(self, p, settings):
		self.maxDiff = None
		with helpers.log2str() as (out, err):
			p._buildInput()
			p._buildProcVars ()
			p._buildProps()
			# p._buildBrings()
			p._buildOutput()
			p._buildScript()
			p._saveSettings()
		psettings = helpers.readFile(path.join(p.workdir, 'proc.settings'), str)
		for setting in settings:
			self.assertIn(setting, psettings)
			psettings = psettings[(psettings.find(setting) + len(setting)):]
示例#6
0
        if countryName in countryDict:
            numberUsersInCountry = countryDict[countryName]

        return countryName != "" and int(user["playcount"]) >= MINIMUM_PLAYCOUNT and numberUsersInCountry < MAXIMUM_USER_PRO_COUNTRY and user not in uniqueUsers
    else:
        return False


if __name__ == "__main__":
    pathToBase = str(sys.argv[1])
    pathToOverall = str(sys.argv[2])
    minimumUsers = int(sys.argv[3])

    start = time.time()

    users = helpers.readFile(pathToBase)

    for i, user in enumerate(users):

        print "\n"
        print "Process user ", i
        print "Unique users", len(uniqueUsers)
        print "Users to process", len(users)

        if len(uniqueUsers) >= minimumUsers:
            break

        content = lfm.call("user.getInfo", params = {"user": user})
        userInfoTree = json.loads(content)

        if not "user" in userInfoTree:
示例#7
0
    if not "recenttracks" in eventTree:
        print "Recent tracks not found"
        return False

    if not "track" in listeningEventsTree["recenttracks"]:
        print "Tracks not found"
        return False

    return True

if __name__ == "__main__":
    pathToUniqueUsers = str(sys.argv[1])
    pathToOverall = str(sys.argv[2])

    users = helpers.readFile(pathToUniqueUsers, header = True)

    LEs = []

    for user in range(0, len(users)):
        print "Processing LEs for user ", user

        content = lfm.getLEs(users[user], 5, 200)

        try:
            # for all retrieved JSON pages of current user
            for page in range(0, len(content)):
                listening_events = json.loads(content[page])

                # get number of listening events in current JSON
                numberOfItems = 0
示例#8
0
    for t in threads:
        t.join()
        
    for k in range(0, q.qsize()):
        contentMerged.append(q.get(False))

    return contentMerged

# Main program
if __name__ == '__main__':

    pathToArtistInfo = str(sys.argv[1])
    pathToUniqueArtists = str(sys.argv[2])

    helpers.createPath(pathToArtistInfo)

    artists = helpers.readFile(pathToUniqueArtists, True, 1)

    for i in range(0, len(artists)):
        print "Fetching artist " + str(i)
        htmlFn = pathToArtistInfo + str(i) + ".html"
        if os.path.exists(htmlFn):
            print "File already fetched: " + htmlFn
            continue

        htmlContent = getArtistInfo(artists[i])
        print "Storing content to " + htmlFn
        with open(htmlFn, 'w') as f:
            f.write("".join(htmlContent))
示例#9
0
    def dataProvider_testRender(self):
        # 0
        yield '{{name}}', {'name': 'John'}, 'John'
        yield '{{names[0]}}', {'names': ['John', 'Tome']}, 'John'
        yield '{{names2.1}}', {'names2': ['John', 'Tome']}, 'Tome'
        yield '{{names3.1[:-1]}}', {'names3': ['John', 'Tome']}, 'Tom'
        yield '{{names4.1.upper()}}', {'names4': ['John', 'Tome']}, 'TOME'
        # 5
        yield '{{names5.1 | [:-1] | .upper()}}', {
            'names5': ['John', 'Tome']
        }, 'TOM'
        yield '{{names6 | [1][:-1] | .upper()}}', {
            'names6': ['John', 'Tome']
        }, 'TOM'
        yield '{{names7 | lambda x: x[1].upper()}}', {
            'names7': ['John', 'Tome']
        }, 'TOME'
        yield '{{v1, v2|concate}}', {
            'v1': 'hello',
            'v2': 'world',
            'concate': lambda x, y: x + y
        }, 'helloworld'
        yield '{{v3 | R}}', {'v3': 'false'}, "FALSE"
        # 10
        yield '{{v4|realpath}}', {'v4': __file__}, path.realpath(__file__)
        #yield ('{{v5|readlink}}', {'v5': path.join(path.dirname(path.realpath(path.abspath(__file__))), 'helpers.py')}, path.relpath(path.join(path.dirname(path.dirname(path.abspat(__file__))), bin', 'helpers.py'), start = path.dirname(__file__)))
        yield '{{v6|dirname}}', {'v6': '/a/b/c'}, '/a/b'
        yield '{{v7|basename}}{{v7|bn}}', {'v7': '/a/b/c.txt'}, 'c.txtc.txt'
        yield '{{v8|basename}}{{v8|bn}}', {'v8': '/a/b/c[1].txt'}, 'c.txtc.txt'
        yield '{{v9, v9b|basename}}{{v9, v9b|bn}}', {
            'v9': '/a/b/c.txt',
            'v9b': True
        }, 'c.txtc.txt'
        # 15
        yield '{{v10, v10b|basename}}{{v10, v10b|bn}} {{v10|ext}}', {
            'v10': '/a/b/c[1].txt',
            'v10b': True
        }, 'c[1].txtc[1].txt .txt'
        yield '{{v11|filename}}{{v11|fn}} {{v11|prefix}}', {
            'v11': '/a/b/a.txt'
        }, 'aa /a/b/a'
        yield '{{v12|filename}}{{v12|fn}}', {'v12': '/a/b/b[1].txt'}, 'bb'
        yield '{{v13, v13b|filename}}{{v13, v13b|fn}}', {
            'v13': '/a/b/d.txt',
            'v13b': True
        }, 'dd'
        yield '{{v14, v14b|filename}}{{v14, v14b|fn}}', {
            'v14': '/a/b/c[1].txt',
            'v14b': True
        }, 'c[1]c[1]'
        # 20
        yield '{{var1|R}}', {'var1': 'NULL'}, 'NULL'
        yield '{{var2|R}}', {'var2': 'abc'}, "'abc'"
        yield '{% for var in varlist %}{{var|R}}{% endfor %}', {
            'varlist': [
                'abc', 'True', 1, False, True, None, 'INF', '-INF', 'r:c()',
                [1, 2, 3]
            ]
        }, "'abc'TRUE1FALSETRUENULLInf-Infc()c(1,2,3)"
        yield '{% if var3|bool %}1{% else %}0{% endif %}', {
            'var3': 'abc',
            'bool': bool
        }, '1'
        yield '{% for k , v in data.items() %}{{k}}:{{v}}{% endfor %}', {
            'data': {
                'a': 1,
                'b': 2
            }
        }, 'a:1b:2'
        # 25
        yield '{{x|R}}', {
            'x': OrderedDict([(u'key1', 'val1'), ('key2', u'val2')])
        }, "list(key1='val1',key2='val2')"
        yield '{{x|Rlist}}', {
            'x': OrderedDict([(u'key1', 'val1'), ('key2', u'val2')])
        }, "list(key1='val1',key2='val2')"
        yield '{{x|Rlist}}', {'x': [1, 2, 3]}, "as.list(c(1,2,3))"
        yield '{{a|quote}}', {'a': ''}, '""'
        yield '{{b|asquote}}', {'b': [1, 2]}, '"1" "2"'
        # 30
        yield '{{c|acquote}}', {'c': [1, 2]}, '"1", "2"'
        yield '{{d|squote}}', {'d': "1"}, "'1'"
        yield '{{e.f|json}}', {'e': {'f': [1, 2]}}, '[1, 2]'
        yield '{{g,h | os.path.join}}', {
            'g': 'a',
            'h': 'b',
            'os': __import__('os')
        }, 'a/b'
        yield """
		#!/usr/bin/env python
		{% if x %}
		{% for y in ylist %}
		{{y}}
		{% endfor %}
		{% endif %}
		""", {
            'x': True,
            'ylist': [1, 2, 3, 4, 5]
        }, """
		#!/usr/bin/env python\n\t\t\n\t\t
		1\n\t\t
		2\n\t\t
		3\n\t\t
		4\n\t\t
		5\n\t\t
		\n\t\t"""
        yield '{{a|read}}', {'a': __file__}, helpers.readFile(__file__)
        file2read = path.join(path.dirname(__file__), 'helpers.py')
        yield '{{a|readlines|lambda x:"\\n".join(_ for _ in x if _)}}', {
            'a': file2read
        }, helpers.readFile(
            file2read,
            lambda x: '\n'.join(str(y) for y in x.splitlines() if y))

        yield '{{a.x, b.y | lambda x,y: x+y}}', {
            'a': {
                'x': 1
            },
            'b': {
                'y': 2
            }
        }, '3'
        yield '{{a.b["1"][0](",")}}', {'a': {'b': {"1": [lambda x: x]}}}, ','
        # python literals
        yield '{{1 | bool}}', {}, 'True'
        yield '{{True | int}}', {}, '1'
示例#10
0
    def __init__(self, input_txt_path, target_txt_path, solution_path_text):
        m = " ".join(readFile(input_txt_path))
        t = " ".join(readFile(target_txt_path))
        s = " ".join(readFile(solution_path_text))

        ver = self.validateSol(s, m, t)
示例#11
0
 def switchMap(self, mapPath):
     mapPath = mapPath[:3] + str((int(mapPath[3]) + 1))
     self.gameMapArr = readFile('maps/' + mapPath)
     self.mapPath = mapPath
示例#12
0
 def __init__(self, mapPath):
     self.gameMapArr = readFile('maps/' + mapPath)
     self.mapPath = mapPath