text
stringlengths
81
112k
Tries to get the link form DAPI or the mirror def _get_from_dapi_or_mirror(link): '''Tries to get the link form DAPI or the mirror''' exception = False try: req = requests.get(_api_url() + link, timeout=5) except requests.exceptions.RequestException: exception = True attempts = 1 ...
Remove the API URL from the link if it is there def _remove_api_url_from_link(link): '''Remove the API URL from the link if it is there''' if link.startswith(_api_url()): link = link[len(_api_url()):] if link.startswith(_api_url(mirror=True)): link = link[len(_api_url(mirror=True)):] re...
Returns a dictionary from requested link def data(link): '''Returns a dictionary from requested link''' link = _remove_api_url_from_link(link) req = _get_from_dapi_or_mirror(link) return _process_req(req)
Returns a dictionary with all <what>, unpaginated def _unpaginated(what): '''Returns a dictionary with all <what>, unpaginated''' page = data(what) results = page['results'] count = page['count'] while page['next']: page = data(page['next']) results += page['results'] count ...
Returns a dictionary with the search results def search(q, **kwargs): '''Returns a dictionary with the search results''' data = {'q': q} for key, value in kwargs.items(): if value: if type(value) == bool: data[key] = 'on' else: data[key] = val...
Formats a list of users available on Dapi def format_users(): '''Formats a list of users available on Dapi''' lines = [] u = users() count = u['count'] if not count: raise DapiCommError('Could not find any users on DAPI.') for user in u['results']: line = user['username'] ...
Formats a list of metadaps available on Dapi def format_daps(simple=False, skip_installed=False): '''Formats a list of metadaps available on Dapi''' lines= [] m = metadaps() if not m['count']: logger.info('Could not find any daps') return for mdap in sorted(m['results'], key=lambda ...
Return data for dap of given or latest version. def _get_metadap_dap(name, version=''): '''Return data for dap of given or latest version.''' m = metadap(name) if not m: raise DapiCommError('DAP {dap} not found.'.format(dap=name)) if not version: d = m['latest_stable'] or m['latest'] ...
Formats information about given DAP from DAPI in a human readable form to list of lines def format_dap_from_dapi(name, version='', full=False): '''Formats information about given DAP from DAPI in a human readable form to list of lines''' lines = [] m, d = _get_metadap_dap(name, version) if d: ...
Formaqts information about the given local DAP in a human readable form to list of lines def format_local_dap(dap, full=False, **kwargs): '''Formaqts information about the given local DAP in a human readable form to list of lines''' lines = [] # Determining label width label_width = dapi.DapFormatter....
Formats information about an installed DAP in a human readable form to list of lines def format_installed_dap(name, full=False): '''Formats information about an installed DAP in a human readable form to list of lines''' dap_data = get_installed_daps_detailed().get(name) if not dap_data: raise DapiL...
Formats all installed DAPs in a human readable form to list of lines def format_installed_dap_list(simple=False): '''Formats all installed DAPs in a human readable form to list of lines''' lines = [] if simple: for pkg in sorted(get_installed_daps()): lines.append(pkg) else: ...
Get Assistants and Snippets for a given DAP name on a given path def _get_assistants_snippets(path, name): '''Get Assistants and Snippets for a given DAP name on a given path''' result = [] subdirs = {'assistants': 2, 'snippets': 1} # Values used for stripping leading path tokens for loc in subdirs: ...
Formats the results of a search def format_search(q, **kwargs): '''Formats the results of a search''' m = search(q, **kwargs) count = m['count'] if not count: raise DapiCommError('Could not find any DAP packages for your query.') return for mdap in m['results']: mdap = mdap[...
Returns a set of all installed daps Either in the given location or in all of them def get_installed_daps(location=None, skip_distro=False): '''Returns a set of all installed daps Either in the given location or in all of them''' if location: locations = [location] else: locations =...
Returns a dictionary with all installed daps and their versions and locations First version and location in the dap's list is the one that is preferred def get_installed_daps_detailed(): '''Returns a dictionary with all installed daps and their versions and locations First version and location in the dap's...
Download a dap to a given or temporary directory Return a path to that file together with information if the directory should be later deleted def download_dap(name, version='', d='', directory=''): '''Download a dap to a given or temporary directory Return a path to that file together with information if ...
Installs a dap from a given path def install_dap_from_path(path, update=False, update_allpaths=False, first=True, force=False, nodeps=False, reinstall=False, __ui__=''): '''Installs a dap from a given path''' will_uninstall = False dap_obj = dapi.Dap(path) name = dap_obj.meta[...
For given dependency string, return only the package name def _strip_version_from_dependency(dep): '''For given dependency string, return only the package name''' usedmark = '' for mark in '< > ='.split(): split = dep.split(mark) if len(split) > 1: usedmark = mark br...
Gets the installed version of the given dap or None if not installed Searches in all dirs by default, otherwise in the given one def get_installed_version_of(name, location=None): '''Gets the installed version of the given dap or None if not installed Searches in all dirs by default, otherwise in the given...
Returns list of first level dependencies of the given installed dap or dap from Dapi if not installed If a location is specified, this only checks for dap installed in that path and return [] if the dap is not located there def _get_dependencies_of(name, location=None): ''' Returns list of first l...
Returns list of dependencies of the given dap from Dapi recursively def _get_all_dependencies_of(name, deps=set(), force=False): '''Returns list of dependencies of the given dap from Dapi recursively''' first_deps = _get_api_dependencies_of(name, force=force) for dep in first_deps: dep = _strip_ver...
Returns list of first level dependencies of the given dap from Dapi def _get_api_dependencies_of(name, version='', force=False): '''Returns list of first level dependencies of the given dap from Dapi''' m, d = _get_metadap_dap(name, version=version) # We need the dependencies to install the dap, # if t...
Install a dap from dapi If update is True, it will remove previously installed daps of the same name def install_dap(name, version='', update=False, update_allpaths=False, first=True, force=False, nodeps=False, reinstall=False, __ui__=''): '''Install a dap from dapi If update is True, it wi...
Returns list of strings with dependency metadata from Dapi def get_dependency_metadata(): '''Returns list of strings with dependency metadata from Dapi''' link = os.path.join(_api_url(), 'meta.txt') return _process_req_txt(requests.get(link)).split('\n')
This function creates a frame def create_frame(self): """ This function creates a frame """ frame = Gtk.Frame() frame.set_shadow_type(Gtk.ShadowType.IN) return frame
Function creates box. Based on orientation it can be either HORIZONTAL or VERTICAL def create_box(self, orientation=Gtk.Orientation.HORIZONTAL, spacing=0): """ Function creates box. Based on orientation it can be either HORIZONTAL or VERTICAL """ h_box = Gtk....
Function creates a button with lave. If assistant is specified then text is aligned def button_with_label(self, description, assistants=None): """ Function creates a button with lave. If assistant is specified then text is aligned """ btn = self.create_button...
The function creates a image from name defined in image_name def create_image(self, image_name=None, scale_ratio=1, window=None): """ The function creates a image from name defined in image_name """ size = 48 * scale_ratio pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(ima...
The function creates a button with image def button_with_image(self, description, image=None, sensitive=True): """ The function creates a button with image """ btn = self.create_button() btn.set_sensitive(sensitive) h_box = self.create_box() try: ...
The function creates a checkbutton with label def checkbutton_with_label(self, description): """ The function creates a checkbutton with label """ act_btn = Gtk.CheckButton(description) align = self.create_alignment() act_btn.add(align) return align
Function creates a checkbox with his name def create_checkbox(self, name, margin=10): """ Function creates a checkbox with his name """ chk_btn = Gtk.CheckButton(name) chk_btn.set_margin_right(margin) return chk_btn
Function creates an Entry with corresponding text def create_entry(self, text="", sensitive="False"): """ Function creates an Entry with corresponding text """ text_entry = Gtk.Entry() text_entry.set_sensitive(sensitive) text_entry.set_text(text) return text_entr...
Function creates a link button with corresponding text and URI reference def create_link_button(self, text="None", uri="None"): """ Function creates a link button with corresponding text and URI reference """ link_btn = Gtk.LinkButton(uri, text) return link_btn
This is generalized method for creating Gtk.Button def create_button(self, style=Gtk.ReliefStyle.NORMAL): """ This is generalized method for creating Gtk.Button """ btn = Gtk.Button() btn.set_relief(style) return btn
Function creates a menu item with an image def create_image_menu_item(self, text, image_name): """ Function creates a menu item with an image """ menu_item = Gtk.ImageMenuItem(text) img = self.create_image(image_name) menu_item.set_image(img) return menu_item
The function is used for creating lable with HTML text def create_label(self, name, justify=Gtk.Justification.CENTER, wrap_mode=True, tooltip=None): """ The function is used for creating lable with HTML text """ label = Gtk.Label() name = name.replace('|', '\n') label.se...
The function is used for creating button with all features like signal on tooltip and signal on clicked The function does not have any menu. Button is add to the Gtk.Grid on specific row and column def add_button(self, grid_lang, ass, row, column): """ The function is used for c...
Add button that opens the window for installing more assistants def add_install_button(self, grid_lang, row, column): """ Add button that opens the window for installing more assistants """ btn = self.button_with_label('<b>Install more...</b>') if row == 0 and column == 0: ...
The function creates a menu item and assigns signal like select and button-press-event for manipulation with menu_item. sub_assistant and path def menu_item(self, sub_assistant, path): """ The function creates a menu item and assigns signal like select and button-press-event for...
Function generates menu from based on ass parameter def generate_menu(self, ass, text, path=None, level=0): """ Function generates menu from based on ass parameter """ menu = self.create_menu() for index, sub in enumerate(sorted(ass[1], key=lambda y: y[0].fullname.lower())): ...
The function is used for creating button with menu and submenu. Also signal on tooltip and signal on clicked are specified Button is add to the Gtk.Grid def add_submenu(self, grid_lang, ass, row, column): """ The function is used for creating button with menu and submenu. Also s...
Function creates a scrolled window with layout manager def create_scrolled_window(self, layout_manager, horizontal=Gtk.PolicyType.NEVER, vertical=Gtk.PolicyType.ALWAYS): """ Function creates a scrolled window with layout manager """ scrolled_window = Gtk.ScrolledWindow() scrolle...
Function creates a Gtk Grid with spacing and homogeous tags def create_gtk_grid(self, row_spacing=6, col_spacing=6, row_homogenous=False, col_homogenous=True): """ Function creates a Gtk Grid with spacing and homogeous tags """ grid_lang = Gtk.Grid() grid_lang.se...
Function creates a notebook def create_notebook(self, position=Gtk.PositionType.TOP): """ Function creates a notebook """ notebook = Gtk.Notebook() notebook.set_tab_pos(position) notebook.set_show_border(True) return notebook
Function creates a message dialog with text and relevant buttons def create_message_dialog(self, text, buttons=Gtk.ButtonsType.CLOSE, icon=Gtk.MessageType.WARNING): """ Function creates a message dialog with text and relevant buttons """ dialog = Gtk.MessageDialog(None, ...
Function creates a question dialog with title text and second_text def create_question_dialog(self, text, second_text): """ Function creates a question dialog with title text and second_text """ dialog = self.create_message_dialog( text, buttons=Gtk.ButtonsTy...
Function executes a dialog def execute_dialog(self, title): """ Function executes a dialog """ msg_dlg = self.create_message_dialog(title) msg_dlg.run() msg_dlg.destroy() return
Function creates a file chooser dialog with title text def create_file_chooser_dialog(self, text, parent, name=Gtk.STOCK_OPEN): """ Function creates a file chooser dialog with title text """ text = None dialog = Gtk.FileChooserDialog( text, parent, Gtk.Fi...
Function creates an alignment def create_alignment(self, x_align=0, y_align=0, x_scale=0, y_scale=0): """ Function creates an alignment """ align = Gtk.Alignment() align.set(x_align, y_align, x_scale, y_scale) return align
Function creates a text view with wrap_mode and justification def create_textview(self, wrap_mode=Gtk.WrapMode.WORD_CHAR, justify=Gtk.Justification.LEFT, visible=True, editable=True): """ Function creates a text view with wrap_mode and justification """ text_view = Gtk.T...
Function creates a tree_view with model def create_tree_view(self, model=None): """ Function creates a tree_view with model """ tree_view = Gtk.TreeView() if model is not None: tree_view.set_model(model) return tree_view
Function creates a CellRendererText with title def create_cell_renderer_text(self, tree_view, title="title", assign=0, editable=False): """ Function creates a CellRendererText with title """ renderer = Gtk.CellRendererText() renderer.set_property('editable', editable) co...
Function creates a CellRendererCombo with title, model def create_cell_renderer_combo(self, tree_view, title="title", assign=0, editable=False, model=None, function=None): """' Function creates a CellRendererCombo with title, model """ renderer_combo = Gtk.CellRendererCombo() re...
Function creates a clipboard def create_clipboard(self, text, selection=Gdk.SELECTION_CLIPBOARD): """ Function creates a clipboard """ clipboard = Gtk.Clipboard.get(selection) clipboard.set_text('\n'.join(text), -1) clipboard.store() return clipboard
Runs a command from string, e.g. "cp foo bar" Args: cmd_str: the command to run as string log_level: level at which to log command output (DEBUG by default) ignore_sigint: should we ignore sigint during this command (False by default) output_callback: function tha...
Returns the password typed by user as a string or None if user cancels the request (e.g. presses Ctrl + D on commandline or presses Cancel in GUI. def ask_for_password(cls, ui, prompt='Provide your password:', **options): """Returns the password typed by user as a string or None if user cancels the req...
Returns True if user agrees, False otherwise def ask_for_confirm_with_message(cls, ui, prompt='Do you agree?', message='', **options): """Returns True if user agrees, False otherwise""" return cls.get_appropriate_helper(ui).ask_for_confirm_with_message(prompt, message)
Ask user for written input with prompt def ask_for_input_with_prompt(cls, ui, prompt='', **options): """Ask user for written input with prompt""" return cls.get_appropriate_helper(ui).ask_for_input_with_prompt(prompt=prompt, **options)
Used by cli to add this as an argument to argparse parser. Args: parser: parser to add this argument to def add_argument_to(self, parser): """Used by cli to add this as an argument to argparse parser. Args: parser: parser to add this argument to """ fro...
Returns the value for specified gui hint (or a sensible default value, if this argument doesn't specify the hint). Args: hint: name of the hint to get value for Returns: value of the hint specified in yaml or a sensible default def get_gui_hint(self, hint): """R...
Construct an argument from name, and params (dict loaded from assistant/snippet). def construct_arg(cls, name, params): """Construct an argument from name, and params (dict loaded from assistant/snippet). """ use_snippet = params.pop('use', None) if use_snippet: # if snippet...
Return list of instantiated subassistants. Usually, this needs not be overriden in subclasses, you should just override get_subassistant_classes Returns: list of instantiated subassistants def get_subassistants(self): """Return list of instantiated subassistants. ...
Returns a tree-like structure representing the assistant hierarchy going down from this assistant to leaf assistants. For example: [(<This Assistant>, [(<Subassistant 1>, [...]), (<Subassistant 2>, [...])] )] Returns: ...
Recursively searches self._tree - has format of (Assistant: [list_of_subassistants]) - for specific path from first to last selected subassistants. Args: kwargs: arguments containing names of the given assistants in form of subassistant_0 = 'name', subassistant_1 = 'another_name...
Returns True if this assistant was run as last in path, False otherwise. def is_run_as_leaf(self, **kwargs): """Returns True if this assistant was run as last in path, False otherwise.""" # find the last subassistant_N i = 0 while i < len(kwargs): # len(kwargs) is maximum of subassista...
Loads yaml files from all given directories. Args: directories: list of directories to search Returns: dict of {fullpath: loaded_yaml_structure} def load_all_yamls(cls, directories): """Loads yaml files from all given directories. Args: directories:...
Load a yaml file with path that is relative to one of given directories. Args: directories: list of directories to search name: relative path of the yaml file to load log_debug: log all messages as debug Returns: tuple (fullpath, loaded yaml structure) or...
Load a yaml file that is at given path, if the path is not a string, it is assumed it's a file-like object def load_yaml_by_path(cls, path, log_debug=False): """Load a yaml file that is at given path, if the path is not a string, it is assumed it's a file-like object""" try: ...
Installs dependencies from the leaf assistant. Raises: devassistant.exceptions.DependencyException with a cause if something goes wrong def _run_path_dependencies(self, parsed_args): """Installs dependencies from the leaf assistant. Raises: devassistant.exceptions.Depend...
Runs all errors, dependencies and run methods of all *Assistant objects in self.path. Raises: devassistant.exceptions.ExecutionException with a cause if something goes wrong def run(self): """Runs all errors, dependencies and run methods of all *Assistant objects in self.path. Raise...
Return the maximum length of the provided strings that have a nice variant in DapFormatter._nice_strings def calculate_offset(cls, labels): '''Return the maximum length of the provided strings that have a nice variant in DapFormatter._nice_strings''' used_strings = set(cls._nice_strings...
Format the line with DAPI user rating and number of votes def format_dapi_score(cls, meta, offset): '''Format the line with DAPI user rating and number of votes''' if 'average_rank' and 'rank_count' in meta: label = (cls._nice_strings['average_rank'] + ':').ljust(offset + 2) sco...
Return all information from a given meta dictionary in a list of lines def format_meta_lines(cls, meta, labels, offset, **kwargs): '''Return all information from a given meta dictionary in a list of lines''' lines = [] # Name and underline name = meta['package_name'] if 'versio...
Format the list of files (e. g. assistants or snippets def _format_files(cls, files, kind): '''Format the list of files (e. g. assistants or snippets''' lines = [] if files: lines.append('The following {kind} are contained in this DAP:'.format(kind=kind.title())) for f i...
Return formatted assistants from the given list in human readable form. def format_assistants_lines(cls, assistants): '''Return formatted assistants from the given list in human readable form.''' lines = cls._format_files(assistants, 'assistants') # Assistant help if assistants: ...
Formats supported platforms in human readable form def format_platforms(cls, platforms): '''Formats supported platforms in human readable form''' lines = [] if platforms: lines.append('This DAP is only supported on the following platforms:') lines.extend([' * ' + platfor...
Checks if the dap is valid, reports problems Parameters: network -- whether to run checks that requires network connection output -- where to write() problems, might be None raises -- whether to raise an exception immediately after problem is detected def check(cls, dap, ne...
Check the meta.yaml in the dap. Return a list of DapProblems. def check_meta(cls, dap): '''Check the meta.yaml in the dap. Return a list of DapProblems.''' problems = list() # Check for non array-like metadata for datatype in (Dap._required_meta | Dap._optional_meta) ...
Check that everything is in the correct top-level directory. Return a list of DapProblems def check_topdir(cls, dap): '''Check that everything is in the correct top-level directory. Return a list of DapProblems''' problems = list() dirname = os.path.dirname(dap._meta_location)...
Check that the package does not depend on itself. Return a list of problems. def check_no_self_dependency(cls, dap): '''Check that the package does not depend on itself. Return a list of problems.''' problems = list() if 'package_name' in dap.meta and 'dependencies' in dap.me...
Check that the package_name is not registered on Dapi. Return list of problems. def check_name_not_on_dapi(cls, dap): '''Check that the package_name is not registered on Dapi. Return list of problems.''' problems = list() if dap.meta['package_name']: from . import...
Check that there are only those files the standard accepts. Return list of DapProblems. def check_files(cls, dap): '''Check that there are only those files the standard accepts. Return list of DapProblems.''' problems = list() dirname = os.path.dirname(dap._meta_location) ...
Check that all assistants and snippets are valid. Return list of DapProblems. def check_yamls(cls, dap): '''Check that all assistants and snippets are valid. Return list of DapProblems.''' problems = list() for yaml in dap.assistants_and_snippets: path = yaml + '....
Strip leading directory name from the given path def _strip_leading_dirname(self, path): '''Strip leading directory name from the given path''' return os.path.sep.join(path.split(os.path.sep)[1:])
Get all assistants in this DAP def assistants(self): '''Get all assistants in this DAP''' return [strip_suffix(f, '.yaml') for f in self._stripped_files if self._assistants_pattern.match(f)]
Get all snippets in this DAP def snippets(self): '''Get all snippets in this DAP''' return [strip_suffix(f, '.yaml') for f in self._stripped_files if self._snippets_pattern.match(f)]
Get all icons in this DAP, optionally strip extensions def icons(self, strip_ext=False): '''Get all icons in this DAP, optionally strip extensions''' result = [f for f in self._stripped_files if self._icons_pattern.match(f)] if strip_ext: result = [strip_suffix(f, '\.({ext})'.forma...
Fill self._badmeta with meta datatypes that are invalid def _find_bad_meta(self): '''Fill self._badmeta with meta datatypes that are invalid''' self._badmeta = dict() for datatype in self.meta: for item in self.meta[datatype]: if not Dap._meta_valid[datatype].match(...
Extracts a file from dap to a file-like object def _get_file(self, path, prepend=False): '''Extracts a file from dap to a file-like object''' if prepend: path = os.path.join(self._dirname(), path) extracted = self._tar.extractfile(path) if extracted: return extra...
Load data from meta.yaml to a dictionary def _load_meta(self, meta): '''Load data from meta.yaml to a dictionary''' meta = yaml.load(meta, Loader=Loader) # Versions are often specified in a format that is convertible to an # int or a float, so we want to make sure it is interpreted as ...
Report a given problem def _report_problem(self, problem, level=logging.ERROR): '''Report a given problem''' problem = self.basename + ': ' + problem if self._logger.isEnabledFor(level): self._problematic = True if self._check_raises: raise DapInvalid(problem) ...
Checks if the given datatype is valid in meta def _isvalid(self, datatype): '''Checks if the given datatype is valid in meta''' if datatype in self.meta: return bool(Dap._meta_valid[datatype].match(self.meta[datatype])) else: return datatype in Dap._optional_meta
Checks if the given datatype is valid in meta (for array-like types) def _arevalid(self, datatype): '''Checks if the given datatype is valid in meta (for array-like types)''' # Datatype not specified if datatype not in self.meta: return datatype in Dap._optional_meta, [] # ...
Check if the given in-dap file is a directory def _is_dir(self, f): '''Check if the given in-dap file is a directory''' return self._tar.getmember(f).type == tarfile.DIRTYPE
Find empty directories and return them Only works for actual files in dap def _get_emptydirs(self, files): '''Find empty directories and return them Only works for actual files in dap''' emptydirs = [] for f in files: if self._is_dir(f): empty = True ...
Load all configuration from file def load_configuration_file(self): """ Load all configuration from file """ if not os.path.exists(self.config_file): return try: with open(self.config_file, 'r') as file: csvreader = csv.reader(file, delimi...
Save all configuration into file Only if config file does not yet exist or configuration was changed def save_configuration_file(self): """ Save all configuration into file Only if config file does not yet exist or configuration was changed """ if os.path.exists(self.con...
Set configuration value with given name. Value can be string or boolean type. def set_config_value(self, name, value): """ Set configuration value with given name. Value can be string or boolean type. """ if value is True: value = "True" elif value is...
The function is used for setting tooltip on menus and submenus def tooltip_queries(self, item, x_coord, y_coord, key_mode, tooltip, text): """ The function is used for setting tooltip on menus and submenus """ tooltip.set_text(text) return True