Ejemplo n.º 1
0
    def initFiles(self, output_to_file=False):
        self.is_loaded = True
        self.final_style = ""

        dir_self = os.path.dirname(os.path.realpath(__file__))
        self.dir_style = os.path.normpath(os.path.join(dir_self,
                                                       "styles")).replace(
                                                           "\\", "/")
        self.dir_res = os.path.normpath(os.path.join(dir_self,
                                                     "../resources")).replace(
                                                         "\\", "/")

        style = os.path.join(self.dir_style, self.__style_source)
        if os.path.exists(style):
            style_source = ""
            with open(style, 'r') as file:
                style_source = file.read()

            vars = os.path.join(self.dir_style, self.__style_vars)
            style_vars = jsonio.read(vars)
            if style_vars is not None:
                for name, value in style_vars.items():
                    style_source = style_source.replace(name, value)

            self.final_style = style_source.replace(self.__style_res_var,
                                                    str(self.dir_res))

            if output_to_file:
                style_output = os.path.join(self.dir_style, self.__style_comp)
                with open(style_output, 'w') as file:
                    file.write(self.final_style)

            # Fonts
            # QFontDatabase.applicationFontFamilies(i)
            QFontDatabase.addApplicationFont(
                os.path.join(self.dir_res, "fonts", "HelveticaNeue.ttf"))
            QFontDatabase.addApplicationFont(
                os.path.join(self.dir_res, "fonts",
                             "HelveticaNeue-Medium.ttf"))
            QFontDatabase.addApplicationFont(
                os.path.join(self.dir_res, "fonts", "HelveticaNeue-Bold.ttf"))

            self.is_loaded = True
Ejemplo n.º 2
0
	def load_config(self):
		self.log.debug('Loading connection config started...')
		
		self.cfg = jsonio.read(os.path.join(utils.configdir(), '.ula'))
		self.cfg.setdefault('autologin', True)	
		self.cfg.setdefault('remember', True)
		self.cfg.setdefault('lastlogin', None)
		self.cfg.setdefault('accounts', [])

		accs = self.cfg.get('accounts')
		
		for acc in accs:
			if acc.get('psw'):
				try:
					acc["psw"] = utils.string_unicode(base64.b64decode(utils.string_byte(acc["psw"]))[:-len(acc["login"])])
				except Exception:
					acc["psw"] = u''
		

		self.log.debug('Autologin: %s, Remember: %s, Lastlogin: %s', self.cfg.get('autologin'), self.cfg.get('remember'), self.cfg.get('lastlogin')) 
		self.log.debug('Loading connection config has been successfully.')
Ejemplo n.º 3
0
    def clear(self):
        self.netpaths = paths.Paths()

        # Mirada executable path
        self.mirada_path = None
        # Universe config
        self.config_unid = None
        self.config_pool = {}
        localcfg = jsonio.read(
            os.path.join(utils.plugin_dir(), "path_config.json"))
        if localcfg is not None:
            self.set_config("local", localcfg)
        # File names
        self.task_filenames = {}
        # Task -> file config
        self.source_taskfile = "taskfile_config.json"
        self.config_taskfile = {}
        # Defaults
        self.select_config("local")
        self.load_task_file()
        # Compile regex
        self.re_path = re.compile(r"\$\((.+?)(\[-?\d*\:-?\d*\])?\)")
        self.re_path_simple = re.compile(r"\$\((.+?)(?:\[-?\d*\:-?\d*\])?\)")
Ejemplo n.º 4
0
	def state_load(self):
		state = jsonio.read(os.path.join(utils.configdir(), self.state_file))
		if state is not None and len(state) > 0:
			self.cb_version.setChecked(state["current_version"])
Ejemplo n.º 5
0
def make_dirs():
    # Config lookup keys
    path_list = ["version", "publish", "local"]
    try:
        from tentaculo.core import config
        db = connect_db()
        conf = config.Config()

        # Additional config file for browse operations
        browse_cfg = jsonio.read(
            os.path.join(utils.plugin_dir(), "browse_config.json"))
        ts_cfg = []

        for val in browse_cfg.get("task_structure", []):
            try:
                valid = [
                    i for i in val.get("structure", [])
                    if i.get("root", None) in path_list
                    and i.get("dirs", None) is not None
                ]
            except AttributeError as e:
                raise AttributeError(
                    "Invalid structure value for [{0}, {1}]. {2}".format(
                        val.get("folder_path", "{no path}"),
                        val.get("task_activity", "{no activity}"), repr(e)))

            if len(valid) > 0:
                ts_cfg.append({
                    "folder_path": val.get("folder_path", ""),
                    "task_activity": val.get("task_activity", ""),
                    "structure": valid
                })

        # Count number of folders created and errors
        nsuccess, nerror = 0, 0

        cerebro_selected = cerebro.core.selected_tasks()
        for cerebro_task in cerebro_selected:
            # Get active task data from Cerebro
            #cerebro_task = cerebro.core.current_task()
            cerebro_task_data = cerebro_task.data()

            # Query all child tasks
            prj_ids = '{' + str(
                cerebro_task_data[cerebro.aclasses.Task.DATA_PROJECT_ID]) + '}'

            query_text = "t.flags & 0000001 = 0"
            query_text += " and (\"taskFlags\"(t.uid, get_usid()) & 4294967296) = 0"
            query_text += " and (lower(t.cc_url) like lower('%{0}%'))".format(
                cerebro_task.parent_url() + cerebro_task.name())
            tasks_list = [
                t[0] for t in db.db.execute(
                    "select * from \"search_Tasks\"(%s::bigint[], ''::text, %s::text, 1000);",
                    prj_ids, query_text)
            ]

            # Add current task if has not children
            if len(tasks_list) == 0:
                tasks_list.append(
                    cerebro_task_data[cerebro.aclasses.Task.DATA_ID])

            tsks = db.db.tasks(tasks_list)
            db.update_tasks(tsks)

            for t in tasks_list:
                task = db.task(t)
                task_paths = conf.translate(task)
                if task_paths is not None:
                    # Create config-based folder structure
                    for p in path_list:
                        path = task_paths.get(p, None)
                        if path is not None and not os.path.exists(path):
                            os.makedirs(path)
                            nsuccess += 1

                    # Create additional folder structure
                    task_parts = [
                        p for p in (task["path"] + task["name"]).split('/')
                        if len(p) > 0
                    ]
                    task_path = '/'.join(task_parts)
                    # Config specifity
                    spec = {}
                    for val in ts_cfg:
                        activity, folder = val["task_activity"], val[
                            "folder_path"]
                        folder = folder[1:] if folder.startswith(
                            '/') else folder
                        # Path substitute
                        for i, p in enumerate(task_parts):
                            folder = folder.replace(r"$(url[{0}])".format(i),
                                                    p)

                        if (len(folder) == 0 or task_path.startswith(folder)
                            ) and (len(activity) == 0
                                   or task["activity"] == activity):
                            for ts in val["structure"]:
                                if task_paths.get(ts["root"],
                                                  None) is not None:
                                    spec[len([
                                        i for i in folder.replace(
                                            '\\', '/').split('/') if len(i) > 0
                                    ]) + (1 if len(activity) > 0 else 0)] = ts

                    if len(spec) > 0:
                        ts = spec[max(spec)]
                        for p in ts["dirs"] if isinstance(
                                ts["dirs"], list) else [ts["dirs"]]:
                            path = os.path.join(task_paths[ts["root"]], p)
                            if path is not None and not os.path.exists(path):
                                os.makedirs(path)
                                nsuccess += 1
                else:
                    nerror += 1

        if nsuccess > 0:
            cerebro_message(
                "Successfully created {0} task(s) folders. [{1} error(s)]".
                format(nsuccess, nerror))
        else:
            cerebro_message(
                "No task(s) folders created. [{0} error(s)]".format(nerror))

    except Exception as e:
        cerebro_message(repr(e))
Ejemplo n.º 6
0
 def load_task_file(self):
     self.config_taskfile = jsonio.read(
         os.path.join(utils.configdir(), self.source_taskfile))