def main(argv):
    if len(argv) < 2:
        print __doc__
        sys.exit(-1)

    pathname = argv[1]

    store = getStore(False)
    store.load(pathname)
    wlib = getWeblib()

    print "Loaded %s\ncategory_description:\n%s\n#tags %s\n#webpages %s" % (
        argv[1],
        wlib.category.getDescription().encode("raw_unicode_escape")[:300],
        len(wlib.tags),
        len(wlib.webpages),
    )

    newTag = weblib.Tag(name="hello tag")
    print >> sys.stderr, "id", newTag.id
    newTag = store.writeTag(newTag)
    print >> sys.stderr, "id", newTag.id
    store.removeItem(newTag)

    # save
    if len(argv) > 2:
        store.save(wlib, argv[2])
Example #2
0
def menu():
	try:
		menu_print()
		user_input = input('\033[47m' + 'Please choose: ')
		if int(user_input) == 1:
			commands.lists(store.load())

		elif int(user_input) == 2:
			commands.add(store.load())
			commands.lists(store.load())

		elif int(user_input) == 3:
			commands.lists(store.load())
			commands.complete(store.load())

		elif int(user_input) == 4:
			commands.lists(store.load())
			commands.removes(store.load())

		elif int(user_input) == 5:
			commands.remove_completed(store.load())

		elif int(user_input) == 6:
			exit()
		else:
			print('\n' + '\033[31m' + 'Wrong input!\n')

	except ValueError:
		print('\n' + '\033[31m' + 'Please only enter numbers!\n')
		menu()
Example #3
0
def saveCurPos (fileName, line, col):
	assert fileName != None

	if (line == 0) and (col == 0):
		pass
	else:
		db = store.load(storeName, {})

		key = os.path.realpath(fileName)
		oldVal = db.get(key)
		if oldVal == None:
			toDel = None
			for k, v in db.iteritems():
				l, c, last = v
				if last == CUR_POS_DB_LEN - 1:
					assert toDel == None
					toDel = k
				else:
					db[k] = (l, c, last + 1)
			if toDel != None:
				del db[toDel]
				if Trace: print toDel, 'removed from cursor position db'
		else:
			oldLast = oldVal[2]
			for k, v in db.iteritems():
				l, c, last = v
				if last < oldLast:
					db[k] = (l, c, last + 1)

		db[key] = (line, col, 0)

		ok = store.save(storeName, db)
		if ok:
			if Trace: print 'saved cursor position:', line, col
Example #4
0
    def load(self):
        '''
        t.load()

        Loads the results from file.
        '''
        assert self.can_load()
        self._result = store.load(self.filename())
        self.finished = True
Example #5
0
def loadCurPos (fileName):
	assert fileName != None

	db = store.load(storeName, None)
	if db != None:
		r = db.get( os.path.realpath(fileName) )
		if r != None:
			line, col, last = r
			if Trace: print 'loaded cursor position:', line, col
			return line, col
		else:
			if Trace: print 'can not restore cursor position: not saved'
			return 0, 0
	else:
		return 0, 0
Example #6
0
	dialog.set_transient_for(parent)
	if old != None:
		r = dialog.set_font_name(old)
		if Trace: print 'set font name:', r
	resp = dialog.run()
	if resp == gtk.RESPONSE_OK:
		new = dialog.get_font_name()
		if Trace: print 'selected font:', new
	else:
		new = old
	dialog.destroy()
	return new

defaultSettings = { 'font': None }
_settingsStoreName = 'settings'
loadSettings = lambda: store.load(_settingsStoreName, defaultSettings)
saveSettings = lambda settings: store.save(_settingsStoreName, settings)

def translateBuilder (builder):
	for obj in builder.get_objects():
		# делаем так, потому что при попытке получения свойств по крейней мере у SeparatorMenuItem он исчезает (где-то ошибка в gtk или в pygtk)
		if type(obj) in (gtk.Window, gtk.MenuItem, gtk.Label, gtk.Button, gtk.CheckButton):
			if type(obj) is gtk.Window:
				label = obj.get_title().decode('utf-8')
			else:
				label = obj.get_property('label').decode('utf-8')
			# print label
			if label.startswith('#'):
				label = tr(label.encode('ascii'))
				if type(obj) is gtk.Window:
					obj.set_title(label.encode('utf-8'))
Example #7
0
def computer(function,**kwargs):

	"""
	Compute function figures out how to run a calculation over a simulation.
	"""

	work = kwargs['workspace']
	calc = kwargs['calc']
	
	#---perform a calculation over all collections
	if 'collections' in calc: 
		cols = tuple([calc['collections']]) if type(calc['collections'])==str else calc['collections']
		sns = unique(flatten([work.vars['collections'][i] for i in cols]))
	else: sns = work.sns()
	
	#---get slices (required)
	slice_name = calc['slice_name']
	group = calc['group'] if 'group' in calc else None
	
	#---pass data to the function according to upstream data type
	incoming_type = calc['uptype']
	jobs,data = [],dict([(sn,{}) for sn in sns])
	combined_slices = []
	for sn in sns:
		new_job = {'sn':sn,'slice_name':slice_name,'group':group}
		if incoming_type == 'simulation':
			#---prepare combinations in a dictionary
			if slice_name not in work.slice(sn):
				raise Exception(
					'\n[ERROR] the slices yaml file is missing a slice named "%s" for simulation "%s"'%
					(slice_name,sn))
			try: mfp = work.slice(sn)[slice_name][group]['missing_frame_percent']
			except: 
				print "[WARNING] no missing frame percentage here"
				mfp = 0.0
			if mfp>work.missing_frame_tolerance:
				status('upstream slice failure: %s,%s,%s missing_frame_percent=%.1f'%(
					sn,slice_name,group,mfp),tag='warning')
				continue
			#---defaulting to 'all' group if group is None
			new_job['grofile'] = work.postdir+\
				work.slice(sn)[slice_name][group if group else 'all']['gro']
			#---! xtc must become a flag. recommend 'xtc' becomes work.cursor[1]
			#---defaulting to 'all' group if group is None
			new_job['trajfile'] = work.postdir+work.slice(sn)[slice_name][group if group else 'all']['xtc']
		if 'specs' not in calc: calc['specs'] = ''
		if 'upstream' in calc['specs']:
			#---if no loop on upstream you can use a list
			if type(calc['specs']['upstream'])==list: 
				upstream_ask = dict([(key,None) for key in calc['specs']['upstream']])
			elif type(calc['specs']['upstream'])==str: 
				upstream_ask = {calc['specs']['upstream']:None}
			else: upstream_ask = calc['specs']['upstream']
			for key,val in upstream_ask.items():
				upspecs = deepcopy(work.calc[key])
				#---identify the list of particular options along with the stubs
				options,stubs = work.interpret_specs(upspecs,return_stubs=True)
				#---identify paths and values over which we "whittle" the total list of specs
				whittles = [(i,j) for i,j in catalog(val)]
				#---if no loop on upstream pickles we interpret none and send blank specs
				if val in ['None','none',None]: 
					specs = [options[ss] for r,v in whittles for ss,s in enumerate(stubs)]
				else:
					#---select the correct option by matching all catalogued routes from the incoming
					#---...key to the original calculation
					specs = [options[ss] for r,v in whittles for ss,s in enumerate(stubs) 
						if delve(s['specs'],*r)==v]
				if len(specs)!=1 and 'loop' not in upspecs['slice_name']: 
					import pdb;pdb.set_trace()
					raise Exception('[ERROR] redundant upstream selection %s'%str(select))
				#---if there are multiple slices
				#---! note that we expect that if slice_names is a list it will be ordered here too
				for slicenum,spec in enumerate(specs):
					#---if the upstream calculation has a group then use it in the filename
					if not group:
						if 'group' in work.calc[key]: upgroup = work.calc[key]['group']
						else: upgroup = None
					else: upgroup = group
					if not upgroup: 
						sl = work.slice(sn)[spec['slice_name']]
						fn_base = re.findall('^v[0-9]+\.[0-9]+-[0-9]+-[0-9]+',
							work.slice(sn)[upspecs['slice_name']]['all']['filekey']
							)[0]+'.%s'%key
					else: 
						sl = work.slice(sn)[spec['slice_name']][upgroup]
						fn_base = '%s.%s'%(sl['filekey'],key)
					#---! moved the following block left recently
					fn = work.select_postdata(fn_base,spec)
					if not fn: 
						print '[ERROR] missing %s'%fn
						import pdb;pdb.set_trace()
					outkey = key if len(specs)==1 else '%s%d'%(key,slicenum)
					#---before each calculation the master loop loads the filename stored here
					data[sn][outkey] = os.path.basename(fn)[:-4]+'dat'
			new_job['upstream'] = data[sn].keys()
		jobs.append(new_job)
	
	#---master loop
	for outgoing in jobs:
		sn,slice_name,group = outgoing['sn'],outgoing['slice_name'],outgoing['group']
		
		#---if we combine slices for this calculation we use the whole time span in the base filename
		if type(slice_name)==list:
			#---! simple method for making the combination file key
			start = min([work.slice(sn)[s]['all' if not group else group]['start'] for s in slice_name])
			end = max([work.slice(sn)[s]['all' if not group else group]['end'] for s in slice_name])
			skip = work.slice(sn)[s]['all' if not group else group]['skip']
			#---! this filekey construction means the user will have to anticipate the names of combos
			fn_base = '%s.%d-%d-%d.%s'%(work.prefixer(sn),start,end,skip,function.__name__)
		else:
			#---we index all calculations automatically in case we loop over specs later
			index,fn_key = -1,''
			if not group:
				fn_base = re.findall('^v[0-9]+\.[0-9]+-[0-9]+-[0-9]+',
					work.slice(sn)[slice_name][
					'all' if not group else group]['filekey'])[0]+'.%s'%function.__name__
			else:
				try: fn_base = work.slice(sn)[slice_name][
					'all' if not group else group]['filekey']+'.%s'%function.__name__
				except:
					print "no group and cannot get base filename"
					import pdb;pdb.set_trace()
		prev = glob.glob(work.postdir+fn_base+'*.dat')
		if prev == []: index = 0
		else: index = max(map(lambda x:int(re.findall('^.+\/%s\.n([0-9]+)\.dat'%fn_base,x)[0]),prev))+1
		fn_key = '.n%d'%index
		fn = fn_base+fn_key+'.dat'
		#---safety check for file errors to prevent overwriting however this should be handled by indices
		if os.path.isfile(work.postdir+fn): raise Exception('[ERROR] %s exists'%(work.postdir+fn))
		
		#---check for specs file with the exact same specifications
		exists = True if index != -1 and work.select_postdata(fn_base,calc) != None else False
		if not exists:
			import ipdb;ipdb.set_trace()
			status("%s %s"%(function.__name__,str(outgoing)),tag='compute')
			outgoing['workspace'] = work
			outgoing['calc'] = calc
			if 'upstream' in outgoing:
				sn = outgoing['sn']
				outgoing['upstream'] = dict([(k,
					load(data[sn][k],work.postdir)) for k in outgoing['upstream']])
			result,attrs = function(**outgoing)
			"""
			spec files are carefully constructed
			they prevent redundant calculations
			they allow us to loop over many parameters while saving files with a single index
			the calculation dictionary in the specs file contains meta-parameters for looping
			we are careful not to save meta parameters to the spec file
			we only save parameters which are relevant to the calculation itself
			the calculation dictionary in the spec file must therefore separate these parameters
			in a sub-dictionary called 'specs'
			we prefer attrs to be small and specific
			since attrs is also used to uniquely specify the data
			all big data should be stored as a result via numpy
			"""
			#---if any calculation specifications are not in attributes we warn the user here
			if 'specs' in calc: unaccounted = [i for i in calc['specs'] if i not in attrs]
			else: unaccounted = []
			if 'upstream' in unaccounted and 'upstream' not in attrs: 
				status('automatically appending upstream data',tag='status')
				unaccounted.remove('upstream')
				attrs['upstream'] = calc['specs']['upstream']
			if any(unaccounted):
				print computer_error_attrs_passthrough+'\n\n'
				status('some calculation specs were not saved: %s'%
					str(unaccounted),tag='STATUS')
				import pdb;pdb.set_trace()
			store(result,fn,work.postdir,attrs=attrs)
			with open(work.postdir+fn_base+fn_key+'.spec','w') as fp: fp.write(json.dumps(attrs)+'\n')
	#---no modifications to work so no save
	return
Example #8
0
def _get_shares_from_store(limit=settings.rss_limit):
    return store.load(limit)
Example #9
0
def get_shares(n=0, since=None):
    return store.load(n, since)
Example #10
0
	index = dict(index)

	print l, len(index)

	json.dump(index, file(os.path.join('test', 'filelist.json'), 'w'))



	root_index = store.dump(index, os.path.join('test', 'index'), index_depth=1)

##	##!!! this is not used in anything yet...
##	json.dump(root_index, file(os.path.join('test', 'index', 'file_index.json'), 'w'))

	store.pack(os.path.join('test', 'index'), keep_files=False)

	d = store.load(os.path.join('test', 'index'))


	print len(d)

	k = d.keys()[0]

	i = store.Index(os.path.join('test', 'index'))

	print len(i)

##	print i[k]

	ic = store.IndexWithCache(os.path.join('test', 'index'))

	print ic[k]
Example #11
0
import commands
import store

items = store.load('todos.txt')

menu = [
 '1. What you have to do this week',
 '2. Add new task',
 '3. Task already in progress',
 '4. How much time do you have?',
 '5. How lazy were you?',
 '6. Complete a task',
 '7. What you have done',
 '8. Remove a task',
 '9. Show all the tasks',
 '10. Switch a task to "in progress" state',
 '11. Exit menu '
]

while True:
    for i in menu:
        print(i)
    try:
        print('----' * 10)
        choice = int(input("Choose a task: "))
        print('----' * 10)
    except ValueError:
        print('You have to enter the number of your choice')
    else:
        if choice == 1:
            commands.print_todos(items)