Example #1
0
def importTrashIter():
	yield 1
	yield 0
	jsonPath = join(oldEventDir, 'trash.json')
	newJsonPath = join(newEventDir, 'trash.json')
	try:
		data = json.loads(open(jsonPath).read())
	except Exception as e:
		print(e)
		return
	if 'history' in data:
		print('skipping "%s": history already exists'%jsonPath)
		return
	try:
		tm = data.pop('modified')
	except KeyError:
		tm = now()
	###
	basicData = {}
	#basicData['modified'] = tm
	###
	## remove extra params from data and add to basicData
	for param in (
		'idList',
	):
		try:
			basicData[param] = data.pop(param)
		except KeyError:
			pass
	###
	_hash = saveBsonObject(data)
	basicData['history'] = [(tm, _hash)]
	open(newJsonPath, 'w').write(dataToPrettyJson(basicData, sort_keys=True))
Example #2
0
def importTrashIter():
    yield 1
    yield 0
    jsonPath = join(oldEventDir, 'trash.json')
    newJsonPath = join(newEventDir, 'trash.json')
    try:
        data = json.loads(open(jsonPath).read())
    except Exception as e:
        print(e)
        return
    if 'history' in data:
        print('skipping "%s": history already exists' % jsonPath)
        return
    try:
        tm = data.pop('modified')
    except KeyError:
        tm = now()
    ###
    basicData = {}
    #basicData['modified'] = tm
    ###
    ## remove extra params from data and add to basicData
    for param in ('idList', ):
        try:
            basicData[param] = data.pop(param)
        except KeyError:
            pass
    ###
    _hash = saveBsonObject(data)
    basicData['history'] = [(tm, _hash)]
    open(newJsonPath, 'w').write(dataToPrettyJson(basicData, sort_keys=True))
Example #3
0
def importTrashIter():
	yield 1
	yield 0
	jsonPath = join(oldEventDir, "trash.json")
	newJsonPath = join(newEventDir, "trash.json")
	try:
		data = json.loads(open(jsonPath).read())
	except Exception as e:
		print(e)
		return
	if "history" in data:
		print("skipping \"%s\": history already exists" % jsonPath)
		return
	try:
		tm = data.pop("modified")
	except KeyError:
		tm = now()
	###
	basicData = {}
	#basicData["modified"] = tm
	###
	## remove extra params from data and add to basicData
	for param in (
		"idList",
	):
		try:
			basicData[param] = data.pop(param)
		except KeyError:
			pass
	###
	_hash = saveBsonObject(data)
	basicData["history"] = [(tm, _hash)]
	open(newJsonPath, "w").write(dataToPrettyJson(basicData, sort_keys=True))
Example #4
0
def importTrashIter():
    yield 1
    yield 0
    jsonPath = join(oldEventDir, "trash.json")
    newJsonPath = join(newEventDir, "trash.json")
    try:
        data = json.loads(open(jsonPath).read())
    except Exception as e:
        print(e)
        return
    if "history" in data:
        print("skipping \"%s\": history already exists" % jsonPath)
        return
    try:
        tm = data.pop("modified")
    except KeyError:
        tm = now()
    ###
    basicData = {}
    #basicData["modified"] = tm
    ###
    ## remove extra params from data and add to basicData
    for param in ("idList", ):
        try:
            basicData[param] = data.pop(param)
        except KeyError:
            pass
    ###
    _hash = saveBsonObject(data)
    basicData["history"] = [(tm, _hash)]
    open(newJsonPath, "w").write(dataToPrettyJson(basicData, sort_keys=True))
Example #5
0
def importAccountsIter():
	makeDir(newAccountsDir)
	###
	oldFiles = os.listdir(oldAccountsDir)
	yield len(oldFiles)
	index = 0
	###
	for fname in oldFiles:
		yield index; index += 1
		jsonPath = join(oldAccountsDir, fname)
		newJsonPath = join(newAccountsDir, fname)
		if not isfile(jsonPath):
			print("\"%s\": not such file" % jsonPath)
			continue
		jsonPathNoX, ext = splitext(fname)
		if ext != ".json":
			continue
		try:
			_id = int(jsonPathNoX)
		except ValueError:
			continue
		try:
			data = json.loads(open(jsonPath).read())
		except Exception as e:
			print("error while loading json file \"%s\"" % jsonPath)
			continue
		if "history" in data:
			print("skipping \"%s\": history already exists" % jsonPath)
			continue
		try:
			tm = data.pop("modified")
		except KeyError:
			tm = now()
		###
		basicData = {}
		#basicData["modified"] = tm
		###
		## remove extra params from data and add to basicData
		for param in (
			"enable",
		):
			try:
				basicData[param] = data.pop(param)
			except KeyError:
				pass
		###
		_hash = saveBsonObject(data)
		basicData["history"] = [(tm, _hash)]
		open(newJsonPath, "w").write(
			dataToPrettyJson(basicData, sort_keys=True)
		)
Example #6
0
def importAccountsIter():
    makeDir(newAccountsDir)
    ###
    oldFiles = os.listdir(oldAccountsDir)
    yield len(oldFiles)
    index = 0
    ###
    for fname in oldFiles:
        yield index
        index += 1
        jsonPath = join(oldAccountsDir, fname)
        newJsonPath = join(newAccountsDir, fname)
        if not isfile(jsonPath):
            print('"%s": not such file' % jsonPath)
            continue
        jsonPathNoX, ext = splitext(fname)
        if ext != '.json':
            continue
        try:
            _id = int(jsonPathNoX)
        except ValueError:
            continue
        try:
            data = json.loads(open(jsonPath).read())
        except Exception as e:
            print('error while loading json file "%s"' % jsonPath)
            continue
        if 'history' in data:
            print('skipping "%s": history already exists' % jsonPath)
            continue
        try:
            tm = data.pop('modified')
        except KeyError:
            tm = now()
        ###
        basicData = {}
        #basicData['modified'] = tm
        ###
        ## remove extra params from data and add to basicData
        for param in ('enable', ):
            try:
                basicData[param] = data.pop(param)
            except KeyError:
                pass
        ###
        _hash = saveBsonObject(data)
        basicData['history'] = [(tm, _hash)]
        open(newJsonPath,
             'w').write(dataToPrettyJson(basicData, sort_keys=True))
Example #7
0
def importEventsIter():
    makeDir(newEventEventsDir)
    oldFiles = os.listdir(oldEventEventsDir)
    yield len(oldFiles)
    index = 0
    for dname in oldFiles:
        yield index
        index += 1
        ####
        try:
            _id = int(dname)
        except ValueError:
            continue
        dpath = join(oldEventEventsDir, dname)
        newDpath = join(newEventEventsDir, dname)
        if not isdir(dpath):
            print('"%s" must be a directory' % dpath)
            continue
        jsonPath = join(dpath, 'event.json')
        if not isfile(jsonPath):
            print('"%s": not such file' % jsonPath)
            continue
        try:
            data = json.loads(open(jsonPath).read())
        except Exception as e:
            print('error while loading json file "%s"' % jsonPath)
            continue
        try:
            tm = data.pop('modified')
        except KeyError:
            tm = now()
        ###
        basicData = {}
        #basicData['modified'] = tm
        ###
        ## remove extra params from data and add to basicData
        for param in (
                'remoteIds',
                'notifiers',  ## FIXME
        ):
            try:
                basicData[param] = data.pop(param)
            except KeyError:
                pass
        ###
        _hash = saveBsonObject(data)
        basicData['history'] = [(tm, _hash)]
        open(newDpath + '.json',
             'w').write(dataToPrettyJson(basicData, sort_keys=True))
Example #8
0
def importEventsIter():
	makeDir(newEventEventsDir)
	oldFiles = os.listdir(oldEventEventsDir)
	yield len(oldFiles)
	index = 0
	for dname in oldFiles:
		yield index; index += 1
		####
		try:
			_id = int(dname)
		except ValueError:
			continue
		dpath = join(oldEventEventsDir, dname)
		newDpath = join(newEventEventsDir, dname)
		if not isdir(dpath):
			print("\"%s\" must be a directory" % dpath)
			continue
		jsonPath = join(dpath, "event.json")
		if not isfile(jsonPath):
			print("\"%s\": not such file" % jsonPath)
			continue
		try:
			data = json.loads(open(jsonPath).read())
		except Exception as e:
			print("error while loading json file \"%s\"" % jsonPath)
			continue
		try:
			tm = data.pop("modified")
		except KeyError:
			tm = now()
		###
		basicData = {}
		#basicData["modified"] = tm
		###
		## remove extra params from data and add to basicData
		for param in (
			"remoteIds",
			"notifiers",## FIXME
		):
			try:
				basicData[param] = data.pop(param)
			except KeyError:
				pass
		###
		_hash = saveBsonObject(data)
		basicData["history"] = [(tm, _hash)]
		open(newDpath + ".json", "w").write(
			dataToPrettyJson(basicData, sort_keys=True)
		)
Example #9
0
def importGroupsIter():
	groupsEnableDict = {} ## {groupId -> enable}
	###
	makeDir(newGroupsDir)
	###
	oldFiles = os.listdir(oldGroupsDir)
	yield len(oldFiles) + 1
	index = 0
	###
	for fname in oldFiles:
		yield index ; index += 1
		jsonPath = join(oldGroupsDir, fname)
		newJsonPath = join(newGroupsDir, fname)
		if not isfile(jsonPath):
			print('"%s": not such file'%jsonPath)
			continue
		jsonPathNoX, ext = splitext(fname)
		if ext != '.json':
			continue
		try:
			_id = int(jsonPathNoX)
		except ValueError:
			continue
		try:
			data = json.loads(open(jsonPath).read())
		except Exception as e:
			print('error while loading json file "%s"'%jsonPath)
			continue
		####
		groupsEnableDict[_id] = data.pop('enable', True)
		####
		if 'history' in data:
			print('skipping "%s": history already exists'%jsonPath)
			continue
		try:
			tm = data.pop('modified')
		except KeyError:
			tm = now()
		###
		basicData = {}
		#basicData['modified'] = tm
		###
		## remove extra params from data and add to basicData
		for param in (
			'remoteIds',
		):
			basicData[param] = data.pop(param, None)
		for param in (
			'enable',
			'idList',
			'remoteSyncData',
			'deletedRemoteEvents',
		):
			try:
				basicData[param] = data.pop(param)
			except KeyError:
				pass
		###
		_hash = saveBsonObject(data)
		basicData['history'] = [(tm, _hash)]
		open(newJsonPath, 'w').write(dataToPrettyJson(basicData, sort_keys=True))
	####
	yield index ; index += 1
	oldGroupListFile = join(oldEventDir, 'group_list.json')
	newGroupListFile = join(newEventDir, 'group_list.json')
	try:
		groupIds = json.loads(open(oldGroupListFile).read())
	except Exception as e:
		print('error while loading %s: %s'%(oldGroupListFile, e))
	else:
		if isinstance(groupIds, list):
			signedGroupIds = [
				(1 if groupsEnableDict.get(gid, True) else -1) * gid \
				for gid in groupIds
			]
			try:
				open(newGroupListFile, 'w').write(dataToPrettyJson(signedGroupIds))
			except Exception as e:
				print('error while writing %s: %s'%(newGroupListFile, e))
		else:
			print('file "%s" contains invalid data, must contain a list'%oldGroupListFile)
Example #10
0
def importGroupsIter():
    groupsEnableDict = {}  ## {groupId -> enable}
    ###
    makeDir(newGroupsDir)
    ###
    oldFiles = os.listdir(oldGroupsDir)
    yield len(oldFiles) + 1
    index = 0
    ###
    for fname in oldFiles:
        yield index
        index += 1
        jsonPath = join(oldGroupsDir, fname)
        newJsonPath = join(newGroupsDir, fname)
        if not isfile(jsonPath):
            print('"%s": not such file' % jsonPath)
            continue
        jsonPathNoX, ext = splitext(fname)
        if ext != '.json':
            continue
        try:
            _id = int(jsonPathNoX)
        except ValueError:
            continue
        try:
            data = json.loads(open(jsonPath).read())
        except Exception as e:
            print('error while loading json file "%s"' % jsonPath)
            continue
        ####
        groupsEnableDict[_id] = data.pop('enable', True)
        ####
        if 'history' in data:
            print('skipping "%s": history already exists' % jsonPath)
            continue
        try:
            tm = data.pop('modified')
        except KeyError:
            tm = now()
        ###
        basicData = {}
        #basicData['modified'] = tm
        ###
        ## remove extra params from data and add to basicData
        for param in ('remoteIds', ):
            basicData[param] = data.pop(param, None)
        for param in (
                'enable',
                'idList',
                'remoteSyncData',
                'deletedRemoteEvents',
        ):
            try:
                basicData[param] = data.pop(param)
            except KeyError:
                pass
        ###
        _hash = saveBsonObject(data)
        basicData['history'] = [(tm, _hash)]
        open(newJsonPath,
             'w').write(dataToPrettyJson(basicData, sort_keys=True))
    ####
    yield index
    index += 1
    oldGroupListFile = join(oldEventDir, 'group_list.json')
    newGroupListFile = join(newEventDir, 'group_list.json')
    try:
        groupIds = json.loads(open(oldGroupListFile).read())
    except Exception as e:
        print('error while loading %s: %s' % (oldGroupListFile, e))
    else:
        if isinstance(groupIds, list):
            signedGroupIds = [
                (1 if groupsEnableDict.get(gid, True) else -1) * gid \
                for gid in groupIds
            ]
            try:
                open(newGroupListFile,
                     'w').write(dataToPrettyJson(signedGroupIds))
            except Exception as e:
                print('error while writing %s: %s' % (newGroupListFile, e))
        else:
            print('file "%s" contains invalid data, must contain a list' %
                  oldGroupListFile)
Example #11
0
def importGroupsIter():
	groupsEnableDict = {} ## {groupId -> enable}
	###
	makeDir(newGroupsDir)
	###
	oldFiles = os.listdir(oldGroupsDir)
	yield len(oldFiles) + 1
	index = 0
	###
	for fname in oldFiles:
		yield index; index += 1
		jsonPath = join(oldGroupsDir, fname)
		newJsonPath = join(newGroupsDir, fname)
		if not isfile(jsonPath):
			print("\"%s\": not such file" % jsonPath)
			continue
		jsonPathNoX, ext = splitext(fname)
		if ext != ".json":
			continue
		try:
			_id = int(jsonPathNoX)
		except ValueError:
			continue
		try:
			data = json.loads(open(jsonPath).read())
		except Exception as e:
			print("error while loading json file \"%s\"" % jsonPath)
			continue
		####
		groupsEnableDict[_id] = data.pop("enable", True)
		####
		if "history" in data:
			print("skipping \"%s\": history already exists" % jsonPath)
			continue
		try:
			tm = data.pop("modified")
		except KeyError:
			tm = now()
		###
		basicData = {}
		#basicData["modified"] = tm
		###
		## remove extra params from data and add to basicData
		for param in (
			"remoteIds",
		):
			basicData[param] = data.pop(param, None)
		for param in (
			"enable",
			"idList",
			"remoteSyncData",
			"deletedRemoteEvents",
		):
			try:
				basicData[param] = data.pop(param)
			except KeyError:
				pass
		###
		_hash = saveBsonObject(data)
		basicData["history"] = [(tm, _hash)]
		open(newJsonPath, "w").write(dataToPrettyJson(basicData, sort_keys=True))
	####
	yield index; index += 1
	oldGroupListFile = join(oldEventDir, "group_list.json")
	newGroupListFile = join(newEventDir, "group_list.json")
	try:
		groupIds = json.loads(open(oldGroupListFile).read())
	except Exception as e:
		print("error while loading %s: %s" % (oldGroupListFile, e))
	else:
		if isinstance(groupIds, list):
			signedGroupIds = [
				(1 if groupsEnableDict.get(gid, True) else -1) * gid
				for gid in groupIds
			]
			try:
				open(newGroupListFile, "w").write(dataToPrettyJson(signedGroupIds))
			except Exception as e:
				print("error while writing %s: %s" % (newGroupListFile, e))
		else:
			print(
				"file \"%s\" contains invalid data" % oldGroupListFile +
				", must contain a list"
			)
Example #12
0
def importGroupsIter():
    groupsEnableDict = {}  ## {groupId -> enable}
    ###
    makeDir(newGroupsDir)
    ###
    oldFiles = os.listdir(oldGroupsDir)
    yield len(oldFiles) + 1
    index = 0
    ###
    for fname in oldFiles:
        yield index
        index += 1
        jsonPath = join(oldGroupsDir, fname)
        newJsonPath = join(newGroupsDir, fname)
        if not isfile(jsonPath):
            print("\"%s\": not such file" % jsonPath)
            continue
        jsonPathNoX, ext = splitext(fname)
        if ext != ".json":
            continue
        try:
            _id = int(jsonPathNoX)
        except ValueError:
            continue
        try:
            data = json.loads(open(jsonPath).read())
        except Exception as e:
            print("error while loading json file \"%s\"" % jsonPath)
            continue
        ####
        groupsEnableDict[_id] = data.pop("enable", True)
        ####
        if "history" in data:
            print("skipping \"%s\": history already exists" % jsonPath)
            continue
        try:
            tm = data.pop("modified")
        except KeyError:
            tm = now()
        ###
        basicData = {}
        #basicData["modified"] = tm
        ###
        ## remove extra params from data and add to basicData
        for param in ("remoteIds", ):
            basicData[param] = data.pop(param, None)
        for param in (
                "enable",
                "idList",
                "remoteSyncData",
                "deletedRemoteEvents",
        ):
            try:
                basicData[param] = data.pop(param)
            except KeyError:
                pass
        ###
        _hash = saveBsonObject(data)
        basicData["history"] = [(tm, _hash)]
        open(newJsonPath,
             "w").write(dataToPrettyJson(basicData, sort_keys=True))
    ####
    yield index
    index += 1
    oldGroupListFile = join(oldEventDir, "group_list.json")
    newGroupListFile = join(newEventDir, "group_list.json")
    try:
        groupIds = json.loads(open(oldGroupListFile).read())
    except Exception as e:
        print("error while loading %s: %s" % (oldGroupListFile, e))
    else:
        if isinstance(groupIds, list):
            signedGroupIds = [
                (1 if groupsEnableDict.get(gid, True) else -1) * gid
                for gid in groupIds
            ]
            try:
                open(newGroupListFile,
                     "w").write(dataToPrettyJson(signedGroupIds))
            except Exception as e:
                print("error while writing %s: %s" % (newGroupListFile, e))
        else:
            print("file \"%s\" contains invalid data" % oldGroupListFile +
                  ", must contain a list")