Ejemplo n.º 1
0
 def create_new_category(backups_path: str, title: str, color: str):
     id = int(time() * 1000)
     new_category = Category(id, title, color)
     dump = CategoryDump()
     for category in Category.parse_from_config_file(os.path.join(backups_path, "categories.ini")):
         if category.title == title:
             raise Exception(f"Category with title '{title}' already exists")
         dump.add(category)
     dump.add(new_category)
     dump.write_category_file(backups_path)
Ejemplo n.º 2
0
 def create_new_category(cat_title) -> Category:
     from omninotes.cli import CLI
     if not CLI.Instance.options.no_confirm:
         print(f"Category '{cat_title}' does not exists'")
         if input("Type 'y' to create, 'n' to abort exporting: ").strip(
         ).lower() != 'y':
             exit(0)
         color = input("Input color: ")
         if not Category.validate_color(color):
             raise Exception("Provider color is incorrect")
         return Category(int(time() * 1000), cat_title, color)
     return Category(int(time() * 1000), cat_title, "black")
Ejemplo n.º 3
0
    def write_category_file(self, base_dir: str):
        filename = os.path.join(base_dir, "categories.ini")
        categories = []
        for category in self.categories:
            dup_id_cat = list(filter(lambda c: c.id == category.id,
                                     categories))
            if dup_id_cat:
                if dup_id_cat[0].title != category.title or dup_id_cat[
                        0].color != category.color:
                    print(
                        f"Warning: categories {dup_id_cat[0].title}/{dup_id_cat[0].color} and {category.title}/{category.color}"
                        " have the same ID. Latter was not imported")
                continue
            categories.append(category)

        Category.dump_to_file(filename, categories)
Ejemplo n.º 4
0
 def parse_from_json(json):
     alarm = json.get("alarm")
     if alarm: alarm = int(alarm)
     creation = json.get("creation")
     if not creation:
         raise Exception("Note json does not contain 'creation'")
     return Settings(
         json.get("trashed", False), json.get("archived", False), alarm,
         Category.parse_from_backup(json["baseCategory"]) if "baseCategory"
         in json else None, creation, json.get("longitude"),
         json.get("latitude"))
Ejemplo n.º 5
0
 def edit_settings(note_path: str, new_trashed: Optional[bool], new_archived: Optional[bool], new_category: Optional[str]):
     categories = Category.parse_from_config_file(os.path.join(note_path, "..", "categories.ini"))
     categories = { cat.title : cat for cat in categories}
     settings = Settings.parse_from_file(note_path, categories)
     settings.archived = new_archived if new_archived else settings.archived
     settings.trashed = new_trashed if new_trashed else settings.trashed
     if new_category:
         if new_category not in categories:
             raise Exception(f"Category with title [{new_category}] does not exist")
         else:
             settings.category = categories[new_category]
     settings.write_to_file(note_path)
Ejemplo n.º 6
0
 def load_categories(self):
     self.categories = {
         category.title: category
         for category in Category.parse_from_config_file(
             os.path.join(self.source_path, "categories.ini"))
     }
Ejemplo n.º 7
0
 def write_new_category(category, path):
     if os.path.exists(path):
         Category.dump_to_file(path, [category], True)