Пример #1
0
 def store16(self, inputs, outputs, arguments):
     #print 'store16 {} {}'.format(inputs, arguments)
     if not os.path.exists(self.get_cid() + '_hex'):
         utils.make_file(self.get_cid() + '_hex', 32 * 1024)
     mem_fd = os.open(self.get_cid() + '_hex', os.O_RDWR)
     os.lseek(mem_fd, arguments[0], 0)
     val = self.pop_input(inputs[0]).astype(np.int16)
     assert val.size == (arguments[1] * arguments[2]), 'size not matching'
     os.write(mem_fd, val[:])
Пример #2
0
    def create_files(self, indent=0):
        # Make config/config.mcfunction - just calls config/config/config.mcfunction
        make_file("../config.mcfunction", "# Generated with ericthelemur's Datapack Settings Generator\n\nfunction %s:config/config" % namespace, overwrite=True)

        # Fill out config function from contents
        with open("config.mcfunction", "w", encoding="utf-8") as f:
            print("# Generated with ericthelemur's Datapack Settings Generator\n", file=f)
            for c in self.contents:
                print(c.render(indent=0), file=f)

        
        with open("load_config.mcfunction", "w", encoding="utf-8") as f:
            print("""scoreboard objectives add constants dummy
scoreboard players set zero constants 0

scoreboard objectives add %(root_sb)s dummy
scoreboard players operation %(root)s += zero constants
execute if score %(root)s = zero constants run function generated:config/init_config""" % {"root": datapack_scoreboard, "root_sb": datapack_scoreboard.scoreboard}, file=f)

        # Generate scoreboard initialization commands
        with open("init_config.mcfunction", "w", encoding="utf-8") as f:
            print("# Generated with ericthelemur's Datapack Settings Generator\n", file=f)
            for s in scoreboards:
                print("\nscoreboard objectives add %s dummy" % s, file=f)
                for p, s1 in players:
                    if s == s1:
                        print("scoreboard players set %s %s %s" % (p, s1, players[(p, s1)]), file=f)

        # Generate uninstall scoreboard commands
        with open("uninstall_config.mcfunction", "w", encoding="utf-8") as f:
            print("# Generated with ericthelemur's Datapack Settings Generator\n", file=f)
            # Objectives remove, ignore SBs in SBs_no_remove
            for s in scoreboards:
                if s not in SBs_no_remove:
                    print("scoreboard objectives remove %s" % s, file=f)
            # Players reset, ignore SBs in SBs_no_reset
            for p, s in players:
                if s in SBs_no_remove and s not in SBs_no_reset:
                    print("scoreboard players reset %s %s" % (p, s), file=f)


        for c in self.contents:
            c.create_files()

        print("Finished generating config files.")
        print("\nIf you did not generate the base datapack with this generator, these changes should be made:")
        print("\tAdded to load: execute if score %s = zero constants run function %s:config/load_config" % (datapack_scoreboard, namespace))
        print("\tAdded to uninstall: function %s:config/uninstall_config" % namespace)
        print("\tWhen comparing a toggle setting, it is recommended to check it is <= or > 0 instead of = 1 or = 0, to allow for uninitialized values.")
        print("\t\tFor toggles: 0 = uninitialized, -1 = off, 1 = on, including datapack flag.")
Пример #3
0
def graph_to_png(graph, dot_abs_name, png_abs_name, conf):
	print("        + Construct graph")
	
	nl = pcsts.nl
	
	dot_string = ''
	dot_string += 'digraph file_graph {' + nl
	dot_string += 'node [shape=rectangle]' + nl
	dot_string += 'nodesep = 0.1' + nl
	dot_string += 'ranksep = 0.3' + nl
	
	for node,neighs in graph.items():
		for n in neighs:
			dot_string += '"' + node + '" -> "' + n + '"' + nl
	
	dot_string += '}' + nl
	
	if needs_run_dot(dot_string, dot_abs_name):
		print("            - Running dot ...")
		
		dot_file = utils.make_file(dot_abs_name)
		dot_file.write(dot_string)
		dot_file.close()	
		
		os.system('dot ' + dot_abs_name + ' -T png > ' + png_abs_name)
		
		if not conf.CACHE_FILES:
			os.remove(dot_abs_name)
	else:
		print("            - No need to run dot")
Пример #4
0
def write_cache(dest_dir, all_info):
    cache_name = join(dest_dir, '.cache', 'files.cache')

    f = utils.make_file(cache_name)
    for abs_name in all_info:
        f.write(abs_name + ' ' + str(getmtime(abs_name)) + pcsts.nl)
    f.close()
Пример #5
0
 def test_compress(self):
     filen = utils.make_file('test.txt',dirn=self.dir_,text="This is some text")
     f = ArchiveFile(filen)
     self.assertEqual(f.compression,'')
     self.assertEqual(f.compress(),0)
     self.assertEqual(f.path,filen+'.bz2')
     self.assertEqual(f.compression,'bz2')
     self.assertEqual(f.get_md5sums(),('c032b31c8a39aaa53b0c6df004e95a64',
                                       '97214f63224bc1e9cc4da377aadce7c7'))
Пример #6
0
 def test_get_md5sums(self):
     filen = utils.make_file('test.txt',dirn=self.dir_,text="This is some text")
     f = arqvist.core.ArchiveFile(filen)
     self.assertEqual(f.md5,None)
     self.assertEqual(f.uncompressed_md5,None)
     self.assertEqual(f.get_md5sums(),('97214f63224bc1e9cc4da377aadce7c7',
                                       '97214f63224bc1e9cc4da377aadce7c7'))
     self.assertEqual(f.md5,'97214f63224bc1e9cc4da377aadce7c7')
     self.assertEqual(f.uncompressed_md5,'97214f63224bc1e9cc4da377aadce7c7')
Пример #7
0
 def test_get_md5sums_compressed_file(self):
     filen = utils.make_file('test.txt.bz2',dirn=self.dir_,text="This is some text",
                             compress='bz2')
     f = ArchiveFile(filen)
     self.assertEqual(f.md5,None)
     self.assertEqual(f.uncompressed_md5,None)
     self.assertEqual(f.get_md5sums(),('c032b31c8a39aaa53b0c6df004e95a64',
                                       '97214f63224bc1e9cc4da377aadce7c7'))
     self.assertEqual(f.md5,'c032b31c8a39aaa53b0c6df004e95a64')
     self.assertEqual(f.uncompressed_md5,'97214f63224bc1e9cc4da377aadce7c7')
Пример #8
0
 def setUp(self):
     # Create test directory
     self.dir_ = utils.make_temp_dir()
     # Make files and symlinks for tests
     #
     # File to link to 'test.txt'
     self.filen = utils.make_file('test.txt',dirn=self.dir_)
     # Absolute and relative links to this file
     self.abslink = utils.make_symlink('abslink',self.filen,dirn=self.dir_)
     self.rellink = utils.make_symlink('rellink',os.path.basename(self.filen),
                                       dirn=self.dir_)
     # A broken link (relative)
     self.brklink = utils.make_symlink('brklink','missing.txt',
                                       dirn=self.dir_)
     # A bzipped file and a broken link that points to the uncompressed
     # file name (an example of an "alternative target")
     self.bzfilen = utils.make_file('test2.txt.bz2',dirn=self.dir_,
                                    compress='bz2')
     self.altlink = utils.make_symlink('altlink','test2.txt',dirn=self.dir_)
     # A link that points outside of the temp dir (broken)
     extfilen = os.path.normpath(os.path.join(self.dir_,'..','elsewhere','test3.txt'))
     self.extlink = utils.make_symlink('extlink',extfilen,dirn=self.dir_)
Пример #9
0
def create_blank():
    make_file("pack.mcmeta", '{ \n\t"pack": {\n\t\t"pack_format": 6,\n\t\t"description": "Datapack generated with ericthelemur''s config generator"\n\t}\n}')
    
    make_dir("data/minecraft/tags/functions")
    make_file("data/minecraft/tags/functions/load.json", '{\n\t"values": [\n\t\t"%s:load"\n\t]\n}' % namespace)
    make_file("data/minecraft/tags/functions/tick.json", '{\n\t"values": [\n\t\t"%s:tick"\n\t]\n}' % namespace)
    
    make_dir("data/global/advancements")
    make_file("data/global/advancements/root.json", '{\n\t"display": {\n\t\t"title": "Installed Datapacks",\n\t\t"description": "",\n\t\t"icon": {\n\t\t\t"item": "minecraft:knowledge_book"\n\t\t},\n\t\t"background": "minecraft:textures/block/gray_concrete.png",\n\t\t"show_toast": false,\n\t\t"announce_to_chat": false\n\t},\n\t"criteria": {\n\t\t"trigger": {\n\t\t\t"trigger": "minecraft:tick"\n\t\t}\n\t}\n}')
    make_file("data/global/advancements/%s.json" % author, '{\n\t"display": {\n\t\t"title": "%(author)s",\n\t\t"description": "",\n\t\t"icon": {\n\t\t\t"item": "minecraft:player_head",\n\t\t\t"nbt": "{SkullOwner: ''%(author)s''}"\n\t\t},\n\t\t"show_toast": false,\n\t\t"announce_to_chat": false\n\t},\n\n\t"parent": "global:root",\n\t"criteria": {\n\t\t"trigger": {\n\t\t\t"trigger": "minecraft:tick"\n\t\t}\n\t}\n}' % {"author": author})
    
    make_dir("data/%s/advancements" % namespace)
    make_file("data/%s/advancements/%s.json" % (namespace, namespace), '{\n\t"display": {\n\t\t"title": "Generated Datapack",\n\t\t"description": "Datapack generated by ericthelemur''s datapack config generator.",\n\t\t"icon": {\n\t\t\t"item": "minecraft:white_dye"\n\t\t},\n\t\t"announce_to_chat": false,\n\t\t"show_toast": false\n\t},\n\t"parent": "global:%s",\n\t"criteria": {\n\t\t"trigger": {\n\t\t\t"trigger": "minecraft:tick"\n\t\t}\n\t}\n}' % author)

    make_dir("data/%s/functions" % namespace)
    make_file("data/%s/functions/load.mcfunction" % namespace, "execute if score %s = zero constants run function %s:config/load_config" % (datapack_scoreboard, namespace))
    make_file("data/%s/functions/tick.mcfunction" % namespace, "")
    make_file("data/%s/functions/uninstall.mcfunction" % namespace, """function %(namespace)s:config/uninstall_config\nscoreboard players reset %(dp_sb)s\n\ntellraw @s {"text":"\\n                                                                                ","color":"%(line_colour)s","strikethrough":true}\ntellraw @s "Datapack uninstalled. Remove from datapacks folder before next restart or reload."\ntellraw @s {"text":"                                                                                ","color":"%(line_colour)s","strikethrough":true}""" % {"namespace": namespace, "line_colour": line_colour, "dp_sb": datapack_scoreboard})


    print("""
Template datapack created.
You now need to replace the placeholders in these files:
\tpack.mcmeta
\tdata/%s/advancements/%s.json
\t
""" % (namespace, namespace))
Пример #10
0
	def start(self):
		env = 'html'
		self._multi_line_env(env)
		self._html = utils.make_file(self._name)
		self._open('<%s>' % env)
Пример #11
0
 def test_repr_(self):
     filen = utils.make_file('test.txt',dirn=self.dir_)
     f = ArchiveFile(filen)
     self.assertEqual(str(f),filen)
Пример #12
0
 def test_get_size_for_dir(self):
     filen = utils.make_file('test.txt',dirn=self.dir_,text="This is some text")
     self.assertEqual(get_size(self.dir_),os.stat(filen).st_size + 4096)
Пример #13
0
 def test_classifier(self):
     filen = utils.make_file('test.txt',dirn=self.dir_)
     self.assertEqual(ArchiveFile(filen).classifier,'')
     self.assertEqual(ArchiveFile(self.dir_).classifier,'/')
Пример #14
0
 def test_basename(self):
     filen = utils.make_file('test.txt',dirn=self.dir_,text="This is some text")
     self.assertEqual(ArchiveFile(filen).basename,'test.txt')
Пример #15
0
 def setUp(self):
     # Create test directory
     self.dir_ = utils.make_temp_dir()
     # Add some files, directories and links
     self.example_dir = utils.make_subdir(self.dir_,'example')
     # Primary data that looks like SOLiD
     d = utils.make_subdir(self.example_dir,'primary_data')
     utils.make_file('test1.csfasta',dirn=d)
     utils.make_file('test1_QV.qual',dirn=d)
     utils.make_file('test2.csfasta',dirn=d)
     utils.make_file('test2_QV.qual',dirn=d)
     self.primary_data_dir = d
     # Analysis with links to primary data
     d = utils.make_subdir(self.example_dir,'analysis')
     utils.make_symlink('test1.csfasta','../primary_data/test1.csfasta',dirn=d)
     utils.make_symlink('test1_QV.qual','../primary_data/test1_QV.qual',dirn=d)
     utils.make_symlink('test2.csfasta','../primary_data/test2.csfasta',dirn=d)
     utils.make_symlink('test2_QV.qual','../primary_data/test2_QV.qual',dirn=d)
     utils.make_file('test1.fastq',dirn=d)
     utils.make_file('test2.fastq',dirn=d)
     utils.make_file('test1_analysis.bam.bz2',dirn=d,compress='bz2')
     utils.make_file('test2_analysis.bam.bz2',dirn=d,compress='bz2')
     utils.make_file('organism.gff3',dirn=d)
     self.analysis_dir = d