Ejemplo n.º 1
0
 def _add_json_data_files(self):
     local_pyrustic_data_folder = os.path.join(self._target, self._app_pkg,
                                               "pyrustic_data")
     resource_prefix = "manager/default_json/pyrustic_data/"
     # add dev.json
     path = os.path.join(local_pyrustic_data_folder, "dev.json")
     default_resource = resource_prefix + "dev_default.json"
     data = pkgutil.get_data("pyrustic", default_resource)
     if not os.path.exists(path):
         with open(path, "wb") as file:
             file.write(data)
     jasonix = Jasonix(path)
     jasonix.data["hooking_pkg"] = "{}.hooking".format(self._app_pkg)
     jasonix.save()
     # add gui.json
     path = os.path.join(local_pyrustic_data_folder, "gui.json")
     default_resource = resource_prefix + "gui_default.json"
     data = pkgutil.get_data("pyrustic", default_resource)
     if not os.path.exists(path):
         with open(path, "wb") as file:
             file.write(data)
     # add publishing.json
     path = os.path.join(local_pyrustic_data_folder, "publishing.json")
     default_resource = resource_prefix + "publishing_default.json"
     data = pkgutil.get_data("pyrustic", default_resource)
     if not os.path.exists(path):
         with open(path, "wb") as file:
             file.write(data)
     # add hubstore.json
     path = os.path.join(local_pyrustic_data_folder, "hubstore.json")
     default_resource = resource_prefix + "hubstore_default.json"
     data = pkgutil.get_data("pyrustic", default_resource)
     if not os.path.exists(path):
         with open(path, "wb") as file:
             file.write(data)
Ejemplo n.º 2
0
def edit_build_version(app_dir):
    about_json_path = os.path.join(app_dir, "pyrustic_data",
                                   "app.json")
    if not os.path.exists(about_json_path):
        return
    jasonix = Jasonix(about_json_path)
    current_version = jasonix.data.get("version", "0.0.1")
    message = "The current version is {}".format(current_version)
    print(message)
    message = "Set a new version or ignore: "
    new_version = input(message)
    if not new_version:
        return
    jasonix.data["version"] = new_version
    jasonix.save()
Ejemplo n.º 3
0
def get_jasonix(pyrustic_data_path, config_name, readonly):
    if not pyrustic_data_path:
        return None
    config_path = os.path.join(pyrustic_data_path,
                               config_name)
    if not os.path.exists(config_path):
        return None
    jasonix = Jasonix(config_path, readonly=readonly)
    return jasonix
Ejemplo n.º 4
0
 def _get_hooks(self):
     dev_json = os.path.join(self._target, self._app_pkg, "pyrustic_data",
                             "dev.json")
     if not os.path.exists(dev_json):
         return None, None
     jasonix = Jasonix(dev_json)
     hooks_package = jasonix.data.get("hooking_pkg", None)
     if not hooks_package:
         return None, None
     pre_building_hook = "{}.pre_building_hook".format(hooks_package)
     post_building_hook = "{}.post_building_hook".format(hooks_package)
     return pre_building_hook, post_building_hook
Ejemplo n.º 5
0
 def _default_owner_repo(self):
     if not self._target and not self._app_pkg:
         return None
     publishing_json_path = os.path.join(self._target, self._app_pkg,
                                         "pyrustic_data", "publishing.json")
     if not os.path.exists(publishing_json_path):
         return None
     jasonix = Jasonix(publishing_json_path)
     if not jasonix.data:
         return None
     owner = jasonix.data["owner"]
     repo = jasonix.data["repo"]
     if not owner or not repo:
         return None
     return owner, repo
Ejemplo n.º 6
0
 def _process(self, args):
     if args:
         print("Wrong usage of this command")
         return
     jasonix = Jasonix(constant.MANAGER_SHARED_DATA_FILE)
     recent_list = jasonix.data["recent"]
     len_recent_list = len(recent_list)
     if len_recent_list == 0:
         print("- Empty -")
     for i, path in enumerate(reversed(recent_list)):
         print("#{}".format(i))
         print("Name: {}".format(os.path.basename(path)))
         print("Path: {}".format(path))
         if i < len_recent_list - 1:
             print("")
Ejemplo n.º 7
0
 def _publish(self):
     publishing_json_path = os.path.join(self._target, self._app_pkg,
                                         "pyrustic_data", "publishing.json")
     if not os.path.exists(publishing_json_path):
         print(
             "Missing 'publishing.json' in 'pyrustic_data' folder.\nPlease init your app."
         )
         return False
     jasonix = Jasonix(publishing_json_path)
     owner = jasonix.data.get("owner", None)
     repo = jasonix.data.get("repo", None)
     name = jasonix.data.get("name", None)
     tag_name = jasonix.data.get("tag_name", None)
     target_commitish = jasonix.data.get("target_commitish", None)
     description = jasonix.data.get("description", None)
     prerelease = jasonix.data.get("prerelease", None)
     draft = jasonix.data.get("draft", None)
     asset_path = jasonix.data.get("asset_path", None)
     asset_name = jasonix.data.get("asset_name", None)
     asset_label = jasonix.data.get("asset_label", None)
     if (not name or not tag_name or not asset_path or not owner
             or not repo):
         print(
             "Missing mandatory elements in $APP_DIR/pyrustic_data/publishing.json"
         )
         return False
     gurl = create_gurl()
     gurl.token = getpass.getpass("\nYour Github Token: ")
     print("\nProcessing...")
     catapult = Catapult(gurl, owner, repo)
     cache = catapult.publish(name, tag_name, target_commitish, description,
                              prerelease, draft, asset_path, asset_name,
                              asset_label)
     meta_code = cache["meta_code"]
     status_code = cache["status_code"]
     status_text = cache["status_text"]
     if meta_code == 0:
         return True
     if meta_code == 1:
         print("Failed to create release.\n{} {}".format(
             status_code, status_text))
         return False
     if meta_code == 2:
         print("Failed to upload asset.\n{} {}".format(
             status_code, status_text))
         return False
     print("Unknown error")
     return False
Ejemplo n.º 8
0
def add_default_shared_data_files():
    resource_prefix = "manager/default_json/PyrusticData/"
    data = (("manager_default.json", constant.MANAGER_SHARED_DATA_FILE),
            ("jupitest_default.json", constant.RUNTEST_SHARED_DATA_FILE),
            ("rustiql_default.json", constant.SQLEDITOR_SHARED_DATA_FILE),
            ("hubway_default.json", constant.HUB_SHARED_DATA_FILE))
    for json_name, path in data:
        data = pkgutil.get_data("pyrustic", resource_prefix + json_name)
        if os.path.exists(path):
            return True
        try:
            Jasonix(path, default=data)
        except Exception as e:
            print("Failed to initialize {}".format(json_name))
            print(e)
    return True
Ejemplo n.º 9
0
 def _set_gui_config(self):
     gui_config_json = None
     gui_config_json_resource = "pyrustic_data/gui.json"
     default_gui_json_resource = \
         "manager/default_json/pyrustic_data/gui_default.json"
     if self._package:
         try:
             gui_config_json = pkgutil.get_data(self._package,
                                                gui_config_json_resource)
         except Exception as e:
             pass
     if not gui_config_json:
         gui_config_json = pkgutil.get_data(__package__,
                                            default_gui_json_resource)
     jasonix = Jasonix(gui_config_json)
     self._gui_config = jasonix.data
     self._config = {"gui": self._gui_config}
Ejemplo n.º 10
0
 def _gen_build_report(self):
     pyrustic_data_path = os.path.join(self._target, self._app_pkg,
                                       "pyrustic_data")
     try:
         os.mkdir(pyrustic_data_path)
     except Exception as e:
         pass
     res = "manager/default_json/pyrustic_data/build_report_default.json"
     default_build_report_json = pkgutil.get_data("pyrustic", res)
     build_report_json = os.path.join(pyrustic_data_path,
                                      "build_report.json")
     jasonix = Jasonix(build_report_json, default=default_build_report_json)
     jasonix.data["timestamp"] = int(time.time())
     jasonix.data["target"] = self._target
     jasonix.data["app_pkg"] = self._app_pkg
     wheels_assets_list = wheels_assets(self._target)
     wheel_asset = None
     if wheels_assets_list:
         wheel_asset = wheels_assets_list[0]
         wheel_asset = os.path.join(self._target, "dist", wheel_asset)
     jasonix.data["app_version"] = self._version
     jasonix.data["wheel_asset"] = wheel_asset
     jasonix.save()
Ejemplo n.º 11
0
 def _process(self, args):
     jasonix = Jasonix(constant.MANAGER_SHARED_DATA_FILE, readonly=True)
     path = jasonix.data["target"]
     if not jasonix.data["recent"]:
         print("- Empty -")
         return
     if len(args) == 1:
         try:
             index = int(args[0])
             path = list(reversed(jasonix.data["recent"]))[index]
         except Exception as e:
             print("Wrong index")
             return
     elif len(args) > 1:
         print("Wrong usage of this command")
         return
     link_handler = LinkHandler(self._target, self._app_pkg, [path])
     self._target = link_handler.target
Ejemplo n.º 12
0
def get_manager_jasonix(readonly=True):
    jasonix = Jasonix(constant.MANAGER_SHARED_DATA_FILE, readonly=readonly)
    return jasonix
Ejemplo n.º 13
0
 def config(self, val):
     """ val is dict, path or file-like object"""
     jasonix = Jasonix(val)
     self._config = jasonix.data
     if self._config:
         self._gui_config = self._config.get("gui", self._gui_config)
Ejemplo n.º 14
0
 def gui_config(self, val):
     jasonix = Jasonix(val)
     self._gui_config = jasonix.data
     if self._gui_config:
         self._config["gui"] = self._gui_config
Ejemplo n.º 15
0
def get_hub_jasonix(readonly=True):
    jasonix = Jasonix(constant.HUB_SHARED_DATA_FILE, readonly=readonly)
    return jasonix
Ejemplo n.º 16
0
def get_runtest_jasonix(readonly=True):
    jasonix = Jasonix(constant.RUNTEST_SHARED_DATA_FILE, readonly=readonly)
    return jasonix
Ejemplo n.º 17
0
def get_sqleditor_jasonix(readonly=True):
    jasonix = Jasonix(constant.SQLEDITOR_SHARED_DATA_FILE, readonly=readonly)
    return jasonix