Ejemplo n.º 1
0
def __setup_db():

    homedir = os_path.expanduser('~')
    PYDATASET_HOME = path_join(homedir, '.pydataset/')

    if not os_path.exists(PYDATASET_HOME):
        # create $HOME/.pydataset/
        os_mkdir(PYDATASET_HOME)
        print('initiated datasets repo at: {}'.format(PYDATASET_HOME))

        # copy the resources.tar.gz from the module files.

        # # There should be a better way ? read from a URL ?
        import pydataset
        filename = path_join(pydataset.__path__[0], 'resources.tar.gz')
        tar = tarfile.open(filename, mode='r|gz')

        # # reading 'resources.tar.gz' from a URL
        # try:
        #     from urllib.request import urlopen # py3
        # except ImportError:
        #     from urllib import urlopen # py2
        # import tarfile
        #
        # targz_url = 'https://example.com/resources.tar.gz'
        # httpstrem = urlopen(targz_url)
        # tar = tarfile.open(fileobj=httpstrem, mode="r|gz")

        # extract 'resources.tar.gz' into PYDATASET_HOME
        # print('extracting resources.tar.gz ... from {}'.format(targz_url))
        tar.extractall(path=PYDATASET_HOME)
        # print('done.')
        tar.close()
Ejemplo n.º 2
0
def parse_and_check_args(parser: ArgumentParser) -> None:

    args = parser.parse_args()

    if args.kver is None and args.kpkg_install and args.kexec is not None:
        parser.error("--kexec requires --kver.")

    # Create outdir if does not exist
    if not os_path.exists(args.outdir):
        os_mkdir(args.outdir)

    if args.source_file is not None:
        if args.source_name is not None:
            parser.error("--source_name is not compliant with --source_file.")
        if args.source_inchi is not None:
            parser.error("--source_inchi is not compliant with --source_file.")
    else:
        if args.source_inchi is None:
            parser.error("--source_inchi is mandatory.")
        if args.source_name is None or args.source_name == '':
            args.source_name = 'target'
        # Create temporary source file
        args.source_file = os_path.join(args.outdir, 'source.csv')
        with open(args.source_file, 'w') as temp_f:
            temp_f.write('Name,InChI\n')
            temp_f.write('"%s","%s"' % (args.source_name, args.source_inchi))

    return args
Ejemplo n.º 3
0
def create_sub_dir(playlist_dir: str, sub_folder_name: str):
    new_path = os_path_join(playlist_dir, sub_folder_name)
    try:
        os_mkdir(new_path)
    except FileExistsError:
        pass
    return new_path
Ejemplo n.º 4
0
def create_one_model_keras(models_dirname, model_type, model_version,
                           model_index):
    '''
    Args:
        models_dirname: str, the name of the directory containing
                        all neural network models. It's a short dirname
                        relative to the project root.
        model_type: str, denoting the type of the model. E.g. alexnet, mlp.
        model_version: int,
    Returns:
        dirpath: str. The dirpath of the created model directory.
    '''
    # 1. Come up with a new model name
    timestamp = datetime_datetime.now().strftime('%Y%m%d%H%M%S')
    model_dirname = '{}_v{}_{}_{}_created'.format(model_type, model_version,
                                                  timestamp, model_index)
    model_dirpath = os_path_join(models_dirname, model_dirname)
    if os_path_isdir(model_dirpath):
        raise OSError(
            '{}: model folder {} should not exist, but it does'.format(
                __name__, model_dirpath))

    # 2. Make that directory
    os_mkdir(model_dirpath)

    return model_dirpath
Ejemplo n.º 5
0
 def load(self, url=None):
     tmpfile = ''.join((self.cachedir, quote_plus(url), '.jpg'))
     if os_path_isdir(self.cachedir) is False:
         print "cachedir not existing, creating it"
         os_mkdir(self.cachedir)
     if os_isfile(tmpfile):
         self.tmpfile = tmpfile
         self.onLoadFinished(None)
     elif url is not None:
         self.tmpfile = tmpfile
         head = {
             "Accept": "image/png,image/*;q=0.8,*/*;q=0.5",
             "Accept-Language": "de",
             "Accept-Encoding": "gzip,deflate",
             "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7",
             "Keep-Alive": "300",
             "Referer": "http://maps.google.de/",
             "Cookie:":
             "khcookie=fzwq1BaIQeBvxLjHsDGOezbBcCBU1T_t0oZKpA; PREF=ID=a9eb9d6fbca69f5f:TM=1219251671:LM=1219251671:S=daYFLkncM3cSOKsF; NID=15=ADVC1mqIWQWyJ0Wz655SirSOMG6pXP2ocdXwdfBZX56SgYaDXNNySnaOav-6_lE8G37iWaD7aBFza-gsX-kujQeH_8WTelqP9PpaEg0A_vZ9G7r50tzRBAZ-8GUwnEfl",
             "Connection": "keep-alive"
         }
         agt = "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.2) Gecko/2008091620 Firefox/3.0.2"
         downloadPage(url, self.tmpfile, headers=head,
                      agent=agt).addCallback(
                          self.onLoadFinished).addErrback(self.onLoadFailed)
     elif self.default:
         self.picload.startDecode(self.default)
Ejemplo n.º 6
0
def save_data_to_json_file(data, jsonFilePath, indentation=None):
    os_mkdir(jsonFilePath) if (not os_path_exists(jsonFilePath)) else True
    if (indentation):
        print("\n{}".format(indentation))
    print("Saving data to '{}'... ".format(indentation, jsonFilePath), end="")
    with open(jsonFilePath, "w", encoding="utf-8") as f:
        json_dump(data, f, ensure_ascii=False, sort_keys=True, indent=4)
    print("Done. \n")
Ejemplo n.º 7
0
 def mkdir(self, path):
     'Make directory. Do nothing if already existent.'
     if self.dir_exists(path):
         return path
     try:
         os_mkdir(path)
     except:
         raise RuntimeError('Could not create directory %s.' % path)
     return path
Ejemplo n.º 8
0
def init(reason, **kwargs):
	if reason == 0:
		if "session" in kwargs:
			if not os_path.exists("/root/.snes9x/snes9x.conf"):
				print "[Snes]: config  /root/.snes9x/snes9x.conf not found creating defaults..."
				if not os_path.exists("/root/.snes9x"):
					os_mkdir("/root/.snes9x")
					os_mkdir("/root/.snes9x/rom")
				copyfile(resolveFilename(SCOPE_PLUGINS, "Extensions/SDLSnes/snes9x.conf.default"), "/root/.snes9x/snes9x.conf")
Ejemplo n.º 9
0
def saver(path, content=True, txt=False):
    dir_path = ''.join(path.split('/')[:-1])

    os_mkdir(dir_path) if not os_path_exists(dir_path) else True
    if content:
        with open(path, 'wb') as f:
            f.write(content)
    elif (txt):
        with open(path, 'w', encoding='utf-8') as f:
            f.write(txt)
Ejemplo n.º 10
0
def main():
    parser = argparse_ArgumentParser("Input parameters")
    parser.add_argument("--input_file_name",
                        default="input_toy.yaml",
                        help="Input parameters file name")
    parser.add_argument("--graph_files_dir",
                        default="",
                        help="Graph files' folder path")
    parser.add_argument("--out_dir_name",
                        default="/results",
                        help="Output directory name")
    args = parser.parse_args()
    with open(args.input_file_name, 'r') as f:
        inputs = yaml_load(f, yaml_Loader)

    # Override output directory name if same as gen
    if args.out_dir_name or inputs['out_comp_nm'] == "/results/res":
        if not os_path.exists(inputs['dir_nm'] + args.out_dir_name):
            os_mkdir(inputs['dir_nm'] + args.out_dir_name)
        inputs['out_comp_nm'] = args.out_dir_name + "/res"

    inputs['graph_files_dir'] = ''
    if args.graph_files_dir:
        if not os_path.exists(inputs['dir_nm'] + args.graph_files_dir):
            os_mkdir(inputs['dir_nm'] + args.graph_files_dir)
        inputs['graph_files_dir'] = args.graph_files_dir

    with open(inputs['dir_nm'] + inputs['out_comp_nm'] + "_input.yaml",
              'w') as outfile:
        yaml_dump(inputs, outfile, default_flow_style=False)

    logging_basicConfig(filename=inputs['dir_nm'] + inputs['out_comp_nm'] +
                        "_logs.yaml",
                        level=logging_INFO)
    start_time_read = time_time()
    myGraph = read_graphs(inputs)
    read_time = time_time() - start_time_read

    myGraphName = inputs['dir_nm'] + inputs['graph_files_dir'] + "/res_myGraph"
    with open(myGraphName, 'wb') as f:
        pickle_dump(myGraph, f)

    tot_time = time_time() - start_time

    out_comp_nm = inputs['dir_nm'] + inputs['out_comp_nm']
    # Write to yaml file instead
    with open(out_comp_nm + '_runtime_performance.out', "a") as fid:
        print("Read network time (s) = ",
              read_time,
              "[",
              round(100 * float(read_time) / tot_time, 2),
              "%]",
              file=fid)
        print("Total time (s) = ", tot_time, file=fid)
Ejemplo n.º 11
0
    def test_not_a_file(self):
        os_mkdir(_TEMP_PATH_1)

        cvs_add_result: Tuple[str,
                              str] = self._changes_codec.cvs_add(_TEMP_PATH_1)

        self.assertEqual(cvs_add_result, ('not a file', _TEMP_PATH_1))

        self.assertFalse(os_path_exists(self._changes_codec._STAGED_PATH))

        shutil_rmtree(_TEMP_PATH_1)
Ejemplo n.º 12
0
    def cvs_init(self):
        """Initializes edu-cvs repository in current working directory"""
        try:
            if not os_path_exists(self._CVS_DIR_PATH):
                os_mkdir(self._CVS_DIR_PATH)

            # if not os_path_exists(self._COMMITTED_PATH):
            #     os_mkdir(self._COMMITTED_PATH)

        except OSError as occurred_err:
            raise OSError('init: cannot create folder', *occurred_err.args)
Ejemplo n.º 13
0
 def make_song_dir(dataset_dir, filename):
     new_dir = os_path_join(dataset_dir, filename)
     extentions = [
         '', 'inputs', 'output', ' output_raw', 'output_distribution',
         'offsets'
     ]
     for extention in extentions:
         try:
             os_mkdir(os_path_join(new_dir, extention))
         except FileExistsError:
             pass
     return new_dir + '/'
Ejemplo n.º 14
0
	def __init__(self, session, cmd):
		self.skin = """
				<screen position="80,70" size="e-160,e-110" title="">
					<widget name="list" position="0,0" size="e-0,e-0" scrollbarMode="showOnDemand" transparent="1" zPosition="2"/>
					<widget name="thumbnail" position="0,0" size="150,150" alphatest="on" />
				</screen>"""
		self.session = session
		Screen.__init__(self, session)

		self["thumbnail"] = Pixmap()
		self["thumbnail"].hide()

		self.cbTimer = eTimer()
		self.cbTimer.callback.append(self.timerCallback)

		self.Details = {}
		self.pixmaps_to_load = []
		self.picloads = {}
		self.color = "#33000000"

		self.page = 0
		self.numOfPics = 0
		self.isRtl = False
		self.isRtlBack = False
		self.isSbs = False
		self.channel = ''
		self.level = self.UG_LEVEL_ALL
		self.cmd = cmd
		self.timerCmd = self.TIMER_CMD_START

		self.png = LoadPixmap(resolveFilename(SCOPE_PLUGINS, "Extensions/OpenUitzendingGemist/oe-alliance.png"))

		self.tmplist = []
		self.mediaList = []

		self.imagedir = "/tmp/openUgImg/"
		if (os_path.exists(self.imagedir) != True):
			os_mkdir(self.imagedir)

		self["list"] = MPanelList(list = self.tmplist, selection = 0)
		self.updateMenu()
		self["actions"] = ActionMap(["WizardActions", "MovieSelectionActions", "DirectionActions"],
		{
			"up": self.key_up,
			"down": self.key_down,
			"left": self.key_left,
			"right": self.key_right,
			"ok": self.go,
			"back": self.Exit,
		}
		, -1)
		self.onLayoutFinish.append(self.layoutFinished)
		self.cbTimer.start(10)
Ejemplo n.º 15
0
 def makedir(self, name):
     # name.replace(' ', '').replace('.', 'ß')
     a = True
     for author in self.AUTHORS:
         if author in name:
             path = "./img-dl-threads/Gitograms/" + author + "/" + name
             os_mkdir(path) if (not os_path_exists(path)) else True
             a = False
     if a:
         path = "./img-dl-threads/Gitograms/Others/" + name
         os_mkdir(path)
     return path
Ejemplo n.º 16
0
	def __init__(self, session, cmd):
		self.skin = """
				<screen position="80,70" size="e-160,e-110" title="">
					<widget name="list" position="0,0" size="e-0,e-0" scrollbarMode="showOnDemand" transparent="1" zPosition="2"/>
					<widget name="thumbnail" position="0,0" size="150,150" alphatest="on" />
				</screen>"""
		self.session = session
		Screen.__init__(self, session)

		self["thumbnail"] = Pixmap()
		self["thumbnail"].hide()

		self.cbTimer = eTimer()
		self.cbTimer.callback.append(self.timerCallback)

		self.Details = {}
		self.pixmaps_to_load = []
		self.picloads = {}
		self.color = "#33000000"

		self.page = 0
		self.numOfPics = 0
		self.isAtotZ = False
		self.isRtl = False
		self.isRtlBack = False
		self.level = self.UG_LEVEL_ALL
		self.cmd = cmd
		self.timerCmd = self.TIMER_CMD_START

		self.png = LoadPixmap(resolveFilename(SCOPE_PLUGINS, "Extensions/OpenUitzendingGemist/oe-alliance.png"))
		
		self.tmplist = []
		self.mediaList = []

		self.imagedir = "/tmp/openUgImg/"
		if (os_path.exists(self.imagedir) != True):
			os_mkdir(self.imagedir)

		self["list"] = MPanelList(list = self.tmplist, selection = 0)
		self.updateMenu()
		self["actions"] = ActionMap(["WizardActions", "MovieSelectionActions", "DirectionActions"],
		{
			"up": self.key_up,
			"down": self.key_down,
			"left": self.key_left,
			"right": self.key_right,
			"ok": self.go,
			"back": self.Exit,
		}
		, -1)
		self.onLayoutFinish.append(self.layoutFinished)
		self.cbTimer.start(10)
Ejemplo n.º 17
0
    def make_offset_dir(self, save_dir):
        offsets_dir = os_path_join(save_dir, 'offsets')
        try:
            os_mkdir(offsets_dir)
        except FileExistsError:
            pass

        new_dir = os_path_join(offsets_dir, 'time_size_' + str(self.time_size))
        try:
            os_mkdir(new_dir)
        except FileExistsError:
            pass
        return new_dir + '/'
Ejemplo n.º 18
0
 def mkdir(newdir):
     """ Wrapper for the os.mkdir function
         returns status instead of raising exception
     """
     try:
         os_mkdir(newdir)
         sts = True
         msg = _('Directory "%s" has been created.') % newdir
     except:
         sts = False
         msg = _('Error creating directory "%s".') % newdir
         printExc()
     return sts,msg
Ejemplo n.º 19
0
 def mkdir(newdir):
     """ Wrapper for the os.mkdir function
         returns status instead of raising exception
     """
     try:
         os_mkdir(newdir)
         sts = True
         msg = _('Directory "%s" has been created.') % newdir
     except:
         sts = False
         msg = _('Error creating directory "%s".') % newdir
         printExc()
     return sts, msg
Ejemplo n.º 20
0
	def __init__(self, session, action, value, url):
		self.skin = """
				<screen position="80,70" size="e-160,e-110" title="">
					<widget name="list" position="0,0" size="e-0,e-0" scrollbarMode="showOnDemand" transparent="1" zPosition="2"/>
					<widget name="thumbnail" position="0,0" size="178,100" alphatest="on" />
				</screen>"""
		self.session = session
		Screen.__init__(self, session)

		self["thumbnail"] = Pixmap()
		self["thumbnail"].hide()

		self.cbTimer = eTimer()
		self.cbTimer.callback.append(self.timerCallback)

		self.Details = {}
		self.pixmaps_to_load = []
		self.picloads = {}
		self.color = "#33000000"

		self.page = 0
		self.numOfPics = 0
		self.isAtotZ = False
		self.cmd = action
		self.url = url
		self.title = value
		self.timerCmd = self.TIMER_CMD_START

		self.png = LoadPixmap(resolveFilename(SCOPE_PLUGINS, "Extensions/bbciplayer/logo.jpg"))
		
		self.tmplist = []
		self.mediaList = []

		self.imagedir = "/tmp/openBbcImg/"
		if (os_path.exists(self.imagedir) != True):
			os_mkdir(self.imagedir)

		self["list"] = MPanelList(list = self.tmplist, selection = 0)
		self.updateMenu()
		self["actions"] = ActionMap(["SetupActions", "WizardActions", "MovieSelectionActions", "DirectionActions"],
		{
			"up": self.key_up,
			"down": self.key_down,
			"left": self.key_left,
			"right": self.key_right,
			"ok": self.go,
			"back": self.Exit,
		}
		, -1)
		self.onLayoutFinish.append(self.layoutFinished)
		self.cbTimer.start(10)
Ejemplo n.º 21
0
def _cli():
    parser = build_args_parser(
        prog='rpcompletion',
        description=
        'Parse RP2 pathways to generate rpSBML collection of unique and complete (cofactors) pathways',
        m_add_args=add_arguments)
    args = parser.parse_args()

    from rptools.__main__ import init
    logger = init(parser, args)

    check_args(args.max_subpaths_filter, args.outdir, logger)

    cache = rrCache(attrs=[
        'rr_reactions',
        'template_reactions',
        'cid_strc',
        'deprecatedCompID_compid',
    ])

    pathways = rp_completion(rp2_metnet=args.rp2_metnet,
                             sink=args.sink,
                             rp2paths_compounds=args.rp2paths_compounds,
                             rp2paths_pathways=args.rp2paths_pathways,
                             cache=cache,
                             upper_flux_bound=int(args.upper_flux_bound),
                             lower_flux_bound=int(args.lower_flux_bound),
                             max_subpaths_filter=args.max_subpaths_filter,
                             logger=logger)

    # WRITE OUT
    if not os_path.exists(args.outdir):
        os_mkdir(args.outdir)
    # Write out selected pathways
    for pathway in pathways:
        pathway.to_rpSBML().write_to_file(
            os_path.join(args.outdir, 'rp_' + pathway.get_id()) + '.xml')
    # for pathway_id, sub_pathways in pathways.items():
    #     for sub_pathway in sub_pathways[-args.max_subpaths_filter:]:
    #         sub_pathway.to_rpSBML().write_to_file(
    #             os_path.join(
    #                 args.outdir,
    #                 'rp_'+sub_pathway.get_id()
    #             ) + '.xml'
    #         )
    StreamHandler.terminator = ""
    logger.info('{color}{typo}Results are stored in {rst}'.format(
        color=fg('white'), typo=attr('bold'), rst=attr('reset')))
    StreamHandler.terminator = "\n"
    logger.info('{color}{outdir}\n'.format(color=fg('grey_70'),
                                           outdir=args.outdir))
Ejemplo n.º 22
0
	def __init__(self, session):
		Screen.__init__(self, session)
		self.title = _("Weather Plugin")
		self["actions"] = ActionMap(["SetupActions", "DirectionActions"],
		{
			"cancel": self.close,
			"menu": self.config,
			"right": self.nextItem,
			"left": self.previousItem,
			"info": self.showWebsite
		}, -1)

		self["statustext"] = StaticText()
		self["currenticon"] = WeatherIcon()
		self["caption"] = StaticText()
		self["currentTemp"] = StaticText()
		self["condition"] = StaticText()
		self["wind_condition"] = StaticText()
		self["humidity"] = StaticText()
		self["observationtime"] = StaticText()
		self["observationpoint"] = StaticText()
		self["feelsliketemp"] = StaticText()
		
		i = 1
		while i <= 5:
			self["weekday%s" % i] = StaticText()
			self["weekday%s_icon" %i] = WeatherIcon()
			self["weekday%s_temp" % i] = StaticText()
			i += 1
		del i
		

		self.appdir = eEnv.resolve("${libdir}/enigma2/python/Plugins/Extensions/WeatherPlugin/icons/")
		if not os_path.exists(self.appdir):
			os_mkdir(self.appdir)

		self.weatherPluginEntryIndex = -1
		self.weatherPluginEntryCount = config.plugins.WeatherPlugin.entrycount.value
		if self.weatherPluginEntryCount >= 1:
			self.weatherPluginEntry = config.plugins.WeatherPlugin.Entry[0]
			self.weatherPluginEntryIndex = 1
		else:
			self.weatherPluginEntry = None

		self.language = config.osd.language.value.replace("_","-")
		if self.language == "en-EN": # hack
			self.language = "en-US"
		self.webSite = ""		
		self.onLayoutFinish.append(self.startRun)
Ejemplo n.º 23
0
    def __init__(self, session):
        Screen.__init__(self, session)
        self.title = _("Weather Plugin")
        self["actions"] = ActionMap(
            ["SetupActions", "DirectionActions"], {
                "cancel": self.close,
                "menu": self.config,
                "right": self.nextItem,
                "left": self.previousItem,
                "info": self.showWebsite
            }, -1)

        self["statustext"] = StaticText()
        self["currenticon"] = WeatherIcon()
        self["caption"] = StaticText()
        self["currentTemp"] = StaticText()
        self["condition"] = StaticText()
        self["wind_condition"] = StaticText()
        self["humidity"] = StaticText()
        self["observationtime"] = StaticText()
        self["observationpoint"] = StaticText()
        self["feelsliketemp"] = StaticText()

        i = 1
        while i <= 5:
            self["weekday%s" % i] = StaticText()
            self["weekday%s_icon" % i] = WeatherIcon()
            self["weekday%s_temp" % i] = StaticText()
            i += 1
        del i

        self.appdir = eEnv.resolve(
            "${libdir}/enigma2/python/Plugins/Extensions/WeatherPlugin/icons/")
        if not os_path.exists(self.appdir):
            os_mkdir(self.appdir)

        self.weatherPluginEntryIndex = -1
        self.weatherPluginEntryCount = config.plugins.WeatherPlugin.entrycount.value
        if self.weatherPluginEntryCount >= 1:
            self.weatherPluginEntry = config.plugins.WeatherPlugin.Entry[0]
            self.weatherPluginEntryIndex = 1
        else:
            self.weatherPluginEntry = None

        self.language = config.osd.language.value.replace("_", "-")
        if self.language == "en-EN":  # hack
            self.language = "en-US"
        self.webSite = ""
        self.onLayoutFinish.append(self.startRun)
Ejemplo n.º 24
0
 def load(self, url=None):
     tmpfile = ''.join((self.cachedir, quote_plus(url), ''))
     if os_path_isdir(self.cachedir) is False:
         print "cachedir not existing, creating it"
         os_mkdir(self.cachedir)
     if os_isfile(tmpfile):
         self.tmpfile = tmpfile
         self.onLoadFinished(None)
     elif url is not None:
         self.tmpfile = tmpfile
         head = {}
         agt = "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.2) Gecko/2008091620 Firefox/3.0.2"
         downloadPage(url, self.tmpfile, headers=head, agent=agt).addCallback(self.onLoadFinished).addErrback(self.onLoadFailed)
     elif self.default:
         self.picload.startDecode(self.default)
Ejemplo n.º 25
0
 def load(self, url = None):
     tmpfile = ''.join((self.cachedir, quote_plus(url), ''))
     if os_path_isdir(self.cachedir) is False:
         print "cachedir not existing, creating it"
         os_mkdir(self.cachedir)
     if os_isfile(tmpfile):
         self.tmpfile = tmpfile
         self.onLoadFinished(None)
     elif url is not None:
         self.tmpfile = tmpfile
         head = { }
         agt = "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.2) Gecko/2008091620 Firefox/3.0.2"
         downloadPage(url,self.tmpfile,headers=head,agent=agt).addCallback(self.onLoadFinished).addErrback(self.onLoadFailed)
     elif self.default:
         self.picload.startDecode(self.default)
Ejemplo n.º 26
0
	def callbackNewDir(self, answer):
		if answer is None:
			return
		dest = self["filelist"].getCurrentDirectory()
		if (" " in answer) or (" " in dest) or (answer==""):
			msg = self.session.open(MessageBox,_("Directory name error !"), MessageBox.TYPE_ERROR, windowTitle=_("Dream-Explorer"))
			return
		else:
			order = dest + answer
			try:
				if not pathExists(dest + answer):
					os_mkdir(order)
				self["filelist"].refresh()
			except:
				msg = self.session.open(MessageBox,_("%s \nfailed!" % order), MessageBox.TYPE_ERROR, windowTitle=_("Dream-Explorer"))
				self["filelist"].refresh()
Ejemplo n.º 27
0
    def __init__(self, session, action, value, url, name):
        self.skin = """
				<screen position="0,0" size="e,e" flags="wfNoBorder" >
					<widget name="lab1" position="0,0" size="e,e" font="Regular;24" halign="center" valign="center" transparent="0" zPosition="5" />
					<widget source="Title" render="Label" position="20,0" size="e,50" font="Regular;32" />
					<widget name="list" position="0,50" size="e,e-50" scrollbarMode="showOnDemand" transparent="1" />
				</screen>"""
        self.session = session
        Screen.__init__(self, session)
        self.skinName = [name, "StreamsThumbCommon"]

        self['lab1'] = Label(_('Wait please while gathering data...'))

        self.cbTimer = eTimer()
        self.cbTimer.callback.append(self.timerCallback)

        self.cmd = action
        self.url = url
        self.title = value
        self.timerCmd = self.TIMER_CMD_START

        self.tmplist = []
        self.mediaList = []

        self.refreshTimer = eTimer()
        self.refreshTimer.timeout.get().append(self.refreshData)
        self.hidemessage = eTimer()
        self.hidemessage.timeout.get().append(self.hidewaitingtext)

        self.imagedir = "/tmp/onDemandImg/"
        if (os_path.exists(self.imagedir) != True):
            os_mkdir(self.imagedir)

        self['list'] = EpisodeList(self.defaultImg, self.showIcon)
        self.updateMenu()

        self["actions"] = ActionMap(
            ["SetupActions", "DirectionActions"], {
                "up": self.key_up,
                "down": self.key_down,
                "left": self.key_left,
                "right": self.key_right,
                "ok": self.go,
                "cancel": self.exit,
            }, -1)
        self.onLayoutFinish.append(self.layoutFinished)
        self.cbTimer.start(10)
Ejemplo n.º 28
0
	def __init__(self, session, action, value, url, name):
		self.skin = """
				<screen position="0,0" size="e,e" flags="wfNoBorder" >
					<widget name="lab1" position="0,0" size="e,e" font="Regular;24" halign="center" valign="center" transparent="0" zPosition="5" />
					<widget source="Title" render="Label" position="20,0" size="e,50" font="Regular;32" />
					<widget name="list" position="0,50" size="e,e-50" scrollbarMode="showOnDemand" transparent="1" />
				</screen>"""
		self.session = session
		Screen.__init__(self, session)
		self.skinName = [name, "StreamsThumbCommon"]

		self['lab1'] = Label(_('Wait please while gathering data...'))

		self.cbTimer = eTimer()
		self.cbTimer.callback.append(self.timerCallback)

		self.cmd = action
		self.url = url
		self.title = value
		self.timerCmd = self.TIMER_CMD_START

		self.tmplist = []
		self.mediaList = []

		self.refreshTimer = eTimer()
		self.refreshTimer.timeout.get().append(self.refreshData)
		self.hidemessage = eTimer()
		self.hidemessage.timeout.get().append(self.hidewaitingtext)

		self.imagedir = "/tmp/onDemandImg/"
		if (os_path.exists(self.imagedir) != True):
			os_mkdir(self.imagedir)

		self['list'] = EpisodeList(self.defaultImg, self.showIcon)
		self.updateMenu()

		self["actions"] = ActionMap(["SetupActions", "DirectionActions"],
		{
			"up": self.key_up,
			"down": self.key_down,
			"left": self.key_left,
			"right": self.key_right,
			"ok": self.go,
			"cancel": self.exit,
		}, -1)
		self.onLayoutFinish.append(self.layoutFinished)
		self.cbTimer.start(10)
Ejemplo n.º 29
0
def find_idx(dpath=None):
    if not dpath:
        dpath = 'data/'
    if not os_path_exists(dpath):
        os_mkdir(dpath)
        # starting from zero index
        return 0

    # path/prefix length
    pl = len(dpath)
    # suffix/extension length
    sl = len('.jpg')

    # get next index
    idx = 1 + int(max(glob(dpath+'*.jpg'))[pl:-sl]) if glob(dpath+'*.jpg') else 0

    return idx
Ejemplo n.º 30
0
	def __init__(self, iconDefault):
		GUIComponent.__init__(self)
		self.picload = ePicLoad()
		self.l = eListboxPythonMultiContent()
		self.l.setBuildFunc(self.buildEntry)
		self.onSelChanged = [ ]

		self.titleFontName = "Regular"
		self.titleFontSize = 26
		self.dateFontName = "Regular"
		self.dateFontSize = 22
		self.descriptionFontName = "Regular"
		self.descriptionFontSize = 18

		self.imagedir = "/tmp/onDemandImg/"
		self.defaultImg = iconDefault
		
		if not os_path.exists(self.imagedir):
			os_mkdir(self.imagedir)
Ejemplo n.º 31
0
    def __init__(self, session):
        Screen.__init__(self, session)
        self.title = _("Weather Plugin")
        self["actions"] = ActionMap(
            [
                "WizardActions", "DirectionActions", "ColorActions",
                "EPGSelectActions"
            ], {
                "back": self.close,
                "menu": self.config,
                "right": self.nextItem,
                "left": self.previousItem
            }, -1)

        self["statustext"] = StaticText()
        self["caption"] = StaticText()
        self["currentTemp"] = StaticText()
        self["condition"] = StaticText()
        self["wind_condition"] = StaticText()
        self["humidity"] = StaticText()

        i = 1
        while i < 5:
            self["weekday%s" % i] = StaticText()
            self["weekday%s_icon" % i] = WeatherIcon()
            self["weekday%s_temp" % i] = StaticText()
            i += 1
        del i

        self.appdir = eEnv.resolve(
            "${libdir}/enigma2/python/Plugins/Extensions/WeatherPlugin/icons/")
        if not os_path.exists(self.appdir):
            os_mkdir(self.appdir)

        self.weatherPluginEntryIndex = -1
        self.weatherPluginEntryCount = config.plugins.WeatherPlugin.entriescount.value
        if self.weatherPluginEntryCount >= 1:
            self.weatherPluginEntry = config.plugins.WeatherPlugin.Entries[0]
            self.weatherPluginEntryIndex = 1
        else:
            self.weatherPluginEntry = None

        self.onLayoutFinish.append(self.startRun)
Ejemplo n.º 32
0
def create_folder(instance, filename):
    inst_class = instance.__class__
    id_max = inst_class.objects.aggregate(Max('id'))['id__max']
    if id_max:
        id_cur = id_max + 1
    else:
        id_cur = get_last_id(inst_class.__name__) + 1
    name_model = inst_class.__name__.lower()
    path_object = name_model + '/' + str(id_cur)
    path_save = FOLDER_FOR_IMAGE + path_object
    path = MEDIA_ROOT + path_save
    try:
        if not os_path.exists(path):
            os_mkdir(path)
    except OSError:
        return False
    else:
        path_save = path_save + '/' + filename
        return path_save
Ejemplo n.º 33
0
    def __init__(self, iconDefault):
        GUIComponent.__init__(self)
        self.picload = ePicLoad()
        self.l = eListboxPythonMultiContent()
        self.l.setBuildFunc(self.buildEntry)
        self.onSelChanged = []

        self.titleFontName = "Regular"
        self.titleFontSize = 26
        self.dateFontName = "Regular"
        self.dateFontSize = 22
        self.descriptionFontName = "Regular"
        self.descriptionFontSize = 18

        self.imagedir = "/tmp/onDemandImg/"
        self.defaultImg = iconDefault

        if not os_path.exists(self.imagedir):
            os_mkdir(self.imagedir)
Ejemplo n.º 34
0
def find_idx(dpath=None, ftype='.jpg'):
    """
       Scans data directory for last file number and returns next index.
       Creates data directory and returns index 0 if none exists.
    """
    if not dpath: dpath = 'data/'
    if not os_path_exists(dpath):
        os_mkdir(dpath)
        # if new directory start new index
        return 0
    # path/prefix length
    pl = len(dpath)
    # suffix/extension length
    sl = len(ftype)
    # get next index
    idx = 1 + int(max(glob(dpath + '*.jpg'))[pl:-sl]) if glob(dpath + '*' +
                                                              ftype) else 0

    return idx
Ejemplo n.º 35
0
def create_folder(instance, filename):
        inst_class = instance.__class__
        id_max = inst_class.objects.aggregate(Max('id'))['id__max']
        if id_max:
                id_cur = id_max + 1
        else:
                id_cur = get_last_id(inst_class.__name__) + 1
        name_model = inst_class.__name__.lower()
        path_object = name_model + '/' + str(id_cur)
        path_save = FOLDER_FOR_IMAGE + path_object
        path = MEDIA_ROOT + path_save
        try:
                if not os_path.exists(path):
                        os_mkdir(path)
        except OSError:
                return False
        else:
                path_save = path_save + '/' + filename
                return path_save
Ejemplo n.º 36
0
def train_one_model_per_frequency(model_dirname, frequency, num_epochs=DEFAULT_EPOCHS, batch_size=DEFAULT_BATCH_SIZE):
    model_frequency_dirname = os_path_join(model_dirname, 'k_'+str(frequency))
    os_mkdir(model_frequency_dirname)
    print('train_one_model_per_frequency. model_dirname={}, frequency={}'.format(model_dirname, frequency))

    X_all, y_all = get_training_data()
    X_all_frequency, y_all_frequency = X_all[:, frequency, :, :], y_all[:, frequency, :, :]
    print('train_one_model_per_frequency: got data')
    (X_frequency_train, X_frequency_valid, _), (y_frequency_train, y_frequency_valid, _) = split_examples(X_all_frequency, y_all_frequency)
    X_frequency_train = X_frequency_train.reshape(-1, X_frequency_train.shape[-2] * X_frequency_train.shape[-1])
    X_frequency_valid = X_frequency_valid.reshape(-1, X_frequency_valid.shape[-2] * X_frequency_valid.shape[-1])
    y_frequency_train = y_frequency_train.reshape(-1, y_frequency_train.shape[-2] * y_frequency_train.shape[-1])
    y_frequency_valid = y_frequency_valid.reshape(-1, y_frequency_valid.shape[-2] * y_frequency_valid.shape[-1])
    print('X_frequency_train.shape =', X_frequency_train.shape)
    print('y_frequency_train.shape =', y_frequency_train.shape)
    min_max_scaler = MinMaxScaler()
    model = KerasRegressor(build_fn=get_model_keras,
                           epochs=num_epochs,
                           batch_size=batch_size,
                           verbose=1)

    estimators = []
    # estimators.append(('standardize', StandardScaler()))
    estimators.append(('standardize', min_max_scaler))
    estimators.append(('mlp', model))
    pipeline = Pipeline(estimators)
    # kfold = KFold(n_splits=10, random_state=DEFAULT_RANDOM_SEED)

    print('train_one_model_per_frequency: begin training frequency={}'.format(frequency))
    # results = cross_val_score(pipeline, X_frequency_train, y_frequency_train, cv=kfold, verbose=1, error_score='raise')
    # print("Larger: %.4f (%.4f) MSE" % (results.mean(), results.std()))

    # Export the regressor to a file

    pipeline.fit(X_frequency_train, y_frequency_train)

    model_k_save_path = os_path_join(model_frequency_dirname, MODEL_DATA_SAVE_FNAME)
    joblib_dump(pipeline, model_k_save_path)

    prediction = pipeline.predict(X_frequency_valid)
    print('mean_squared_error(y_valid, prediction) =', mean_squared_error(y_frequency_valid, prediction))
Ejemplo n.º 37
0
	def load(self, url = None):
		if url is None:
			self.instance.setPixmap(None)
			return
		url = isinstance(url,unicode) and url.encode('utf-8') or url
		if os_isfile(url):
			self.tmpfile = url
			self.onLoadFinished(None)
			return
		tmpfile = ''.join((self.cachedir, quote_plus(url), '.jpg'))
		if os_path_isdir(self.cachedir) is False:
			print "cachedir not existing, creating it"
			os_mkdir(self.cachedir)
		if os_isfile(tmpfile):
			self.tmpfile = tmpfile
			self.onLoadFinished(None)
		elif url is not None:
			self.tmpfile = tmpfile
			agt = "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.2) Gecko/2008091620 Firefox/3.0.2"
			downloadPage(url,self.tmpfile, agent=agt).addCallback(self.onLoadFinished).addErrback(self.onLoadFailed)
		elif self.default:
			self.picload.startDecode(self.default)
Ejemplo n.º 38
0
	def __init__(self, session):
		Screen.__init__(self, session)
		self.title = _("Weather Plugin")
		self["actions"] = ActionMap(["WizardActions", "DirectionActions", "ColorActions", "EPGSelectActions"],
		{
			"back": self.close,
			"menu": self.config,
			"right": self.nextItem,
			"left": self.previousItem
		}, -1)

		self["statustext"] = StaticText()
		self["caption"] = StaticText()
		self["currentTemp"] = StaticText()
		self["condition"] = StaticText()
		self["wind_condition"] = StaticText()
		self["humidity"] = StaticText()

		i = 1
		while i < 5:
			self["weekday%s" % i] = StaticText()
			self["weekday%s_icon" %i] = WeatherIcon()
			self["weekday%s_temp" % i] = StaticText()
			i += 1
		del i

		self.appdir = eEnv.resolve("${libdir}/enigma2/python/Plugins/Extensions/WeatherPlugin/icons/")
		if not os_path.exists(self.appdir):
			os_mkdir(self.appdir)

		self.weatherPluginEntryIndex = -1
		self.weatherPluginEntryCount = config.plugins.WeatherPlugin.entriescount.value
		if self.weatherPluginEntryCount >= 1:
			self.weatherPluginEntry = config.plugins.WeatherPlugin.Entries[0]
			self.weatherPluginEntryIndex = 1
		else:
			self.weatherPluginEntry = None

		self.onLayoutFinish.append(self.startRun)
Ejemplo n.º 39
0
def write_graph_stats_neig_lists(G, inputs):
    out_comp_nm = inputs['dir_nm'] + inputs['out_comp_nm']
    n_nodes_net = nx.number_of_nodes(G)
    n_edges_net = nx.number_of_edges(G)

    with open(out_comp_nm + '_metrics.out', "a") as fid:
        print("No. of nodes in network = ", n_nodes_net, file=fid)
        print("No. of edges in network = ", n_edges_net, file=fid)

    myGraphdict = nx.to_dict_of_dicts(G)

    folNm = inputs['dir_nm'] + inputs['graph_files_dir'] + "/neig_dicts"
    if not os_path.exists(folNm):
        os_mkdir(folNm)
    neig_lens = []
    for node, val in myGraphdict.items():
        with open(folNm + "/" + node, 'wb') as f:
            joblib_dump(val, f)
        neig_lens.append(len(val))
    with open(out_comp_nm + '_metrics.out', "a") as fid:
        print("Max number of neighbors = ", max(neig_lens), file=fid)
        print("Avg number of neighbors = %.2f " % np_mean(neig_lens), file=fid)
    logging_info("Finished writing neighbor lists.")
Ejemplo n.º 40
0
	def load(self, url = None):
		tmpfile = ''.join((self.cachedir, quote_plus(url), '.jpg'))
		if os_path_isdir(self.cachedir) is False:
			print "cachedir not existing, creating it"
			os_mkdir(self.cachedir)
		if os_isfile(tmpfile):
			self.tmpfile = tmpfile
			self.onLoadFinished(None)
		elif url is not None:
			self.tmpfile = tmpfile
			head = {
				"Accept":"image/png,image/*;q=0.8,*/*;q=0.5",
				"Accept-Language":"de",
				"Accept-Encoding":"gzip,deflate",
				"Accept-Charset":"ISO-8859-1,utf-8;q=0.7,*;q=0.7",
				"Keep-Alive":"300",
				"Referer":"http://maps.google.de/",
				"Cookie:": "khcookie=fzwq1BaIQeBvxLjHsDGOezbBcCBU1T_t0oZKpA; PREF=ID=a9eb9d6fbca69f5f:TM=1219251671:LM=1219251671:S=daYFLkncM3cSOKsF; NID=15=ADVC1mqIWQWyJ0Wz655SirSOMG6pXP2ocdXwdfBZX56SgYaDXNNySnaOav-6_lE8G37iWaD7aBFza-gsX-kujQeH_8WTelqP9PpaEg0A_vZ9G7r50tzRBAZ-8GUwnEfl",
				"Connection":"keep-alive"
			}
			agt = "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.2) Gecko/2008091620 Firefox/3.0.2"
			downloadPage(url,self.tmpfile,headers=head,agent=agt).addCallback(self.onLoadFinished).addErrback(self.onLoadFailed)
		elif self.default:
			self.picload.startDecode(self.default)
Ejemplo n.º 41
0
def configure():
    graph_conf_path='/opt/graphite/conf'
    graph_stor_path = '/opt/graphite/storage'
    apache_avail = '/etc/apache2/sites-available'
    apache_enab = '/etc/apache2/sites-enabled'
    apache_src_conf = '/root/default-graphite'
    apache_dst_conf = "{0}/{1}".format(apache_avail,'default-graphite')
    apache_enab_conf = "{0}/{1}".format(apache_enab,'default-graphite')
    stor_sch_conf = "{0}/{1}".format(graph_conf_path,'storage-schemas.conf')

    with settings(
        show('running',
             'stdout',
             'stderr'),
        warn_only=True, always_use_pty='false'):

        for file in ['carbon.conf','storage-schemas.conf','graphite.wsgi']:

            src = "{0}/{1}.example".format(graph_conf_path,file)
            dst = "{0}/{1}".format(graph_conf_path,file)
            ## Copy from example, template to real file
            copyfile(src,dst)

        ## Generate default-graphite apache config file, based on
        ## template at top of this file.
        make_apache_conf = Template(apache_base_templ)

        ## Write template into the new config file
        ## /etc/apache2/sites-available/default-graphite

        try:
            open(apache_dst_conf,'wt').write(
                make_apache_conf.substitute(port=80,wsgi_sockd='/etc/httpd/wsgi/')
            )
            fab_puts("Wrote apache config for Graphite WebApp.",show_prefix=False)

        except IOError as e:
            fab_abort("Error {0} Failed to open file {1}".format(e.errno,e.filename))

        try:
            open(stor_sch_conf,'at').write(stor_base_templ)
            fab_puts("Updated storage schema config with brickstor elements.",show_prefix=False)

        except IOError as e:
            fab_abort("Error {0} Failed to open file {1}".format(e.errno,e.filename))

        try:
            os_remove('/etc/apache2/sites-enabled/000-default')
        except OSError as e:
            print "Warning: {0} {1}".format(e.filename,e.args)

        ## Create necessary directories for Apache
        for dir in ['/etc/httpd','/etc/httpd/wsgi']:
            try:
                os_mkdir(dir,0755)
                fab_puts("Created directory: {0}".format(dir),show_prefix=False)
            except OSError as e:
                print "Warning: {0} {1}".format(e.filename,e.args)

        try:
            os_symlink(apache_dst_conf, apache_enab_conf)
            fab_puts("Created symbolic link for {0}".format(apache_dst_conf),show_prefix=False)

        except OSError as e:
            print "Warning: {0} {1}".format(e.filename,e.args)

        with fab_lcd('/opt/graphite/webapp/graphite/'):
            fab_local('python manage.py syncdb')

        ## This should really use python os module, will fix later.
        fab_local("chown -R {0} {1}".format('www-data:www-data',graph_stor_path))

        ## Copy local_settings.py.example config into real config file
        src = '/opt/graphite/webapp/graphite/local_settings.py.example'
        dst = '/opt/graphite/webapp/graphite/local_settings.py'
        copyfile(src,dst)

        ## Reload Apache config after all the changes
        fab_local("/etc/init.d/apache2 reload")
import librosa
from poi_detector.src.basic_classes.constants import wav_dir
from os.path import join as ospathjoin
import skimage.io
import numpy as np

base_dir = 'D:/Documents/Thesis/Project Skaterbot/Datasets/Library/'
transform_type = 'cqt'
freq_size = 512
window_size = 10

dataset_dir = os_path_join(base_dir, 'window_size_' + str(window_size))
data_dir = os_path_join(dataset_dir, 'data')

try:
    os_mkdir(data_dir)
except FileExistsError:
    pass

input_handler = InputDatasetHandler(transform_type, window_size)
names, pois_lists = get_data_from_csv(preciser_csv_path)

sample_name = names[randint(0, names.shape[0])]

try:
    print('Trying:', sample_name)

    """ CREATE CQT """
    audio_data, sr = librosa.load(ospathjoin(wav_dir, sample_name), sr=44100)

    spectrogram = Transform.get_bad_spectrogram(audio_data, sr, freq_size, window_size)
Ejemplo n.º 43
0
from flaskext.markdown import Markdown
import pickle
from os import path as os_path, mkdir as os_mkdir, remove as os_remove
from datetime import datetime
import sys, getopt

app = Flask("Champagne")
Markdown(app)

noteList = []

noteDir = "notes"

# create note directory if it doesn't exist
if not os_path.exists(noteDir):
    os_mkdir(noteDir)

noteListFileName = os_path.join(noteDir, "notes.pkl")

# check for existing file with note metadata
if os_path.exists(noteListFileName):
    with open(noteListFileName, 'rb') as notesFile:
        noteList = pickle.load(notesFile)


@app.route("/")
def home():
    return render_template("home.html", notes=noteList)


@app.route("/addNote")
Ejemplo n.º 44
0
	def __init__(self, session, cmd):
		self.skin = """
				<screen position="80,70" size="e-160,e-110" title="">
					<widget name="list" position="0,0" size="e-0,e-0" scrollbarMode="showOnDemand" transparent="1" zPosition="2"/>
					<widget name="thumbnail" position="0,0" size="150,150" alphatest="on" />
					<widget name="chosenletter" position="10,10" size="e-20,150" halign="center" font="Regular;30" foregroundColor="#FFFF00" />
				</screen>"""
		self.session = session
		Screen.__init__(self, session)

		self["thumbnail"] = Pixmap()
		self["thumbnail"].hide()

		self.cbTimer = eTimer()
		self.cbTimer.callback.append(self.timerCallback)

		self.Details = {}
		self.pixmaps_to_load = []
		self.picloads = {}
		self.color = "#33000000"
		
		self.numericalTextInput = NumericalTextInput.NumericalTextInput(mapping=NumericalTextInput.MAP_SEARCH_UPCASE)
		self["chosenletter"] = Label("")
		self["chosenletter"].visible = False 

		self.page = 0
		self.numOfPics = 0
		self.isRtl = False
		self.isRtlBack = False
		self.isSbs = False
		self.channel = ''
		self.level = self.UG_LEVEL_ALL
		self.cmd = cmd
		self.timerCmd = self.TIMER_CMD_START

		self.png = LoadPixmap(resolveFilename(SCOPE_PLUGINS, "Extensions/OpenUitzendingGemist/oe-alliance.png"))

		self.tmplist = []
		self.mediaList = []

		self.imagedir = "/tmp/openUgImg/"
		if (os_path.exists(self.imagedir) != True):
			os_mkdir(self.imagedir)

		self["list"] = MPanelList(list = self.tmplist, selection = 0)
		self.list = self["list"]
		self.updateMenu()
		self["actions"] = ActionMap(["WizardActions", "MovieSelectionActions", "DirectionActions"],
		{
			"up": self.key_up,
			"down": self.key_down,
			"left": self.key_left,
			"right": self.key_right,
			"ok": self.go,
			"back": self.Exit,
		}
		, -1)
		self["NumberActions"] = NumberActionMap(["NumberActions", "InputAsciiActions"],
			{
				"gotAsciiCode": self.keyAsciiCode,
				"0": self.keyNumberGlobal,
				"1": self.keyNumberGlobal,
				"2": self.keyNumberGlobal,
				"3": self.keyNumberGlobal,
				"4": self.keyNumberGlobal,
				"5": self.keyNumberGlobal,
				"6": self.keyNumberGlobal,
				"7": self.keyNumberGlobal,
				"8": self.keyNumberGlobal,
				"9": self.keyNumberGlobal
			}) 
		self.onLayoutFinish.append(self.layoutFinished)
		self.cbTimer.start(10)
Ejemplo n.º 45
0
	def setIconPath(self, iconpath):
		if not os_path.exists(iconpath):
			os_mkdir(iconpath)
		self.iconpath = iconpath