Lines 3-9
Link Here
|
3 |
# Distributed under the terms of the GNU General Public License v2 |
3 |
# Distributed under the terms of the GNU General Public License v2 |
4 |
# $Id$ |
4 |
# $Id$ |
5 |
|
5 |
|
6 |
|
|
|
7 |
# DEPEND SYNTAX: |
6 |
# DEPEND SYNTAX: |
8 |
# |
7 |
# |
9 |
# 'use?' only affects the immediately following word! |
8 |
# 'use?' only affects the immediately following word! |
Lines 24-30
from itertools import chain
Link Here
|
24 |
import portage.exception |
23 |
import portage.exception |
25 |
from portage.exception import InvalidData, InvalidAtom |
24 |
from portage.exception import InvalidData, InvalidAtom |
26 |
from portage.localization import _ |
25 |
from portage.localization import _ |
27 |
from portage.versions import catpkgsplit, catsplit, pkgcmp, pkgsplit, ververify |
26 |
from portage.versions import catpkgsplit, catsplit, pkgcmp, pkgsplit, ververify, _version |
28 |
import portage.cache.mappings |
27 |
import portage.cache.mappings |
29 |
|
28 |
|
30 |
def cpvequal(cpv1, cpv2): |
29 |
def cpvequal(cpv1, cpv2): |
Lines 309-315
def use_reduce(deparray, uselist=[], masklist=[], matchall=0, excludeall=[]):
Link Here
|
309 |
|
308 |
|
310 |
return rlist |
309 |
return rlist |
311 |
|
310 |
|
312 |
|
|
|
313 |
def dep_opconvert(deplist): |
311 |
def dep_opconvert(deplist): |
314 |
""" |
312 |
""" |
315 |
Iterate recursively through a list of deps, if the |
313 |
Iterate recursively through a list of deps, if the |
Lines 834-927
def dep_getusedeps( depend ):
Link Here
|
834 |
open_bracket = depend.find( '[', open_bracket+1 ) |
832 |
open_bracket = depend.find( '[', open_bracket+1 ) |
835 |
return tuple(use_list) |
833 |
return tuple(use_list) |
836 |
|
834 |
|
837 |
_valid_category = re.compile("^\w[\w-]*") |
835 |
# 2.1.1 A category name may contain any of the characters [A-Za-z0-9+_.-]. |
838 |
_invalid_atom_chars_regexp = re.compile("[()|@]") |
836 |
# It must not begin with a hyphen or a dot. |
839 |
|
837 |
_cat = r'[A-Za-z0-9+_][A-Za-z0-9+_.-]*' |
|
|
838 |
|
839 |
# 2.1.2 A package name may contain any of the characters [A-Za-z0-9+_-]. |
840 |
# It must not begin with a hyphen, |
841 |
# and must not end in a hyphen followed by one or more digits. |
842 |
# FIXME: this regex doesn't check 'must not end in' clause. |
843 |
_pkg = r'[A-Za-z0-9+_][A-Za-z0-9+_-]*' |
844 |
|
845 |
# 2.1.3 A slot name may contain any of the characters [A-Za-z0-9+_.-]. |
846 |
# It must not begin with a hyphen or a dot. |
847 |
_slot = r'(:[A-Za-z0-9+_][A-Za-z0-9+_.-]*)?' |
848 |
|
849 |
_use = r'(\[.*\])?' |
850 |
_op = r'([=><~]|([><]=))' |
851 |
_cp = _cat + '/' + _pkg |
852 |
_cpv = _cp + '-' + _version |
853 |
|
854 |
_atom = re.compile(r'^(' + |
855 |
'(' + _op + _cpv + _slot + _use + ')|' + |
856 |
'(=' + _cpv + r'\*' + _slot + _use + ')|' + |
857 |
'(' + _cp + _slot + _use + ')' + |
858 |
')$') |
840 |
def isvalidatom(atom, allow_blockers=False): |
859 |
def isvalidatom(atom, allow_blockers=False): |
841 |
""" |
860 |
""" |
842 |
Check to see if a depend atom is valid |
861 |
Check to see if a depend atom is valid |
843 |
|
862 |
|
844 |
Example usage: |
863 |
Example usage: |
845 |
>>> isvalidatom('media-libs/test-3.0') |
864 |
>>> isvalidatom('media-libs/test-3.0') |
846 |
0 |
865 |
False |
847 |
>>> isvalidatom('>=media-libs/test-3.0') |
866 |
>>> isvalidatom('>=media-libs/test-3.0') |
848 |
1 |
867 |
True |
849 |
|
868 |
|
850 |
@param atom: The depend atom to check against |
869 |
@param atom: The depend atom to check against |
851 |
@type atom: String |
870 |
@type atom: String or Atom |
852 |
@rtype: Integer |
871 |
@rtype: Boolean |
853 |
@return: One of the following: |
872 |
@return: One of the following: |
854 |
1) 0 if the atom is invalid |
873 |
1) False if the atom is invalid |
855 |
2) 1 if the atom is valid |
874 |
2) True if the atom is valid |
856 |
""" |
875 |
""" |
857 |
existing_atom = Atom._atoms.get(atom) |
876 |
existing_atom = Atom._atoms.get(atom) |
858 |
if existing_atom is not None: |
877 |
if existing_atom is not None: |
859 |
atom = existing_atom |
878 |
atom = existing_atom |
860 |
if isinstance(atom, Atom): |
879 |
if isinstance(atom, Atom): |
861 |
if atom.blocker and not allow_blockers: |
880 |
return allow_blockers or not atom.blocker |
862 |
return 0 |
881 |
if allow_blockers and atom[0] == '!': |
863 |
return 1 |
882 |
if atom[1] == '!': |
864 |
global _invalid_atom_chars_regexp |
|
|
865 |
if _invalid_atom_chars_regexp.search(atom): |
866 |
return 0 |
867 |
if allow_blockers and atom[:1] == "!": |
868 |
if atom[1:2] == "!": |
869 |
atom = atom[2:] |
883 |
atom = atom[2:] |
870 |
else: |
884 |
else: |
871 |
atom = atom[1:] |
885 |
atom = atom[1:] |
872 |
|
886 |
if not _atom.match(atom): |
873 |
if dep_getslot(atom) == "": |
887 |
return False |
874 |
# empty slot is invalid (None is valid) |
|
|
875 |
return 0 |
876 |
|
877 |
try: |
888 |
try: |
878 |
use = dep_getusedeps(atom) |
889 |
use = dep_getusedeps(atom) |
879 |
if use: |
890 |
if use: |
880 |
use = _use_dep(use) |
891 |
use = _use_dep(use) |
|
|
892 |
return True |
881 |
except InvalidAtom: |
893 |
except InvalidAtom: |
882 |
return 0 |
894 |
return False |
883 |
|
|
|
884 |
cpv = dep_getcpv(atom) |
885 |
cpv_catsplit = catsplit(cpv) |
886 |
without_slot = remove_slot(atom) |
887 |
mycpv_cps = None |
888 |
if cpv: |
889 |
if len(cpv_catsplit) == 2: |
890 |
if _valid_category.match(cpv_catsplit[0]) is None: |
891 |
return 0 |
892 |
if cpv_catsplit[0] == "null": |
893 |
# "null" category is valid, missing category is not. |
894 |
mycpv_cps = catpkgsplit(cpv.replace("null/", "cat/", 1)) |
895 |
if mycpv_cps: |
896 |
mycpv_cps = list(mycpv_cps) |
897 |
mycpv_cps[0] = "null" |
898 |
if not mycpv_cps: |
899 |
mycpv_cps = catpkgsplit(cpv) |
900 |
if mycpv_cps is None and cpv != without_slot: |
901 |
return 0 |
902 |
|
903 |
operator = get_operator(atom) |
904 |
if operator: |
905 |
if operator[0] in "<>" and without_slot[-1:] == "*": |
906 |
return 0 |
907 |
if mycpv_cps: |
908 |
if len(cpv_catsplit) == 2: |
909 |
# >=cat/pkg-1.0 |
910 |
return 1 |
911 |
else: |
912 |
return 0 |
913 |
else: |
914 |
# >=cat/pkg or >=pkg-1.0 (no category) |
915 |
return 0 |
916 |
if mycpv_cps: |
917 |
# cat/pkg-1.0 |
918 |
return 0 |
919 |
|
920 |
if len(cpv_catsplit) == 2: |
921 |
# cat/pkg |
922 |
return 1 |
923 |
else: |
924 |
return 0 |
925 |
|
895 |
|
926 |
def isjustname(mypkg): |
896 |
def isjustname(mypkg): |
927 |
""" |
897 |
""" |