-
Notifications
You must be signed in to change notification settings - Fork 8
/
Package.cc
3106 lines (2599 loc) · 76.7 KB
/
Package.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*---------------------------------------------------------------------\
| |
| __ __ ____ _____ ____ |
| \ \ / /_ _/ ___|_ _|___ \ |
| \ V / _` \___ \ | | __) | |
| | | (_| |___) || | / __/ |
| |_|\__,_|____/ |_| |_____| |
| |
| core system |
| (C) SuSE GmbH |
\----------------------------------------------------------------------/
File: Package.cc
Author: Klaus Kaempf <kkaempf@suse.de>
Maintainer: Klaus Kaempf <kkaempf@suse.de>
Namespace: Pkg
Summary: Access to packagemanager
Purpose: Handles package related Pkg::function (list_of_arguments) calls
from WFMInterpreter.
/-*/
#include "PkgFunctions.h"
#include "log.h"
#include "Callbacks.YCP.h"
#include <ycp/YCPVoid.h>
#include <ycp/YCPBoolean.h>
#include <ycp/YCPInteger.h>
#include <ycp/YCPSymbol.h>
#include <ycp/YCPString.h>
#include <ycp/YCPList.h>
#include <ycp/YCPMap.h>
#include <ycp/Type.h>
#include <zypp/base/Algorithm.h>
#include <zypp/ResFilters.h>
#include <zypp/ResStatus.h>
#include <zypp/ResPool.h>
#include <zypp/target/rpm/RpmDb.h>
#include <zypp/target/TargetException.h>
#include <zypp/ZYppCommit.h>
#include <zypp/base/Regex.h>
#include <zypp/sat/WhatProvides.h>
#include <zypp/ZYppFactory.h>
#include <zypp/repo/PackageProvider.h>
#include <zypp/Locale.h>
#include <fstream>
#include <sstream>
extern "C"
{
// ::stat, ::unlink, ::symlink
#include <unistd.h>
// errno
#include <errno.h>
}
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
/*
Textdomain "pkg-bindings"
*/
///////////////////////////////////////////////////////////////////
namespace zypp {
typedef std::list<PoolItem> PoolItemList;
}
// ------------------------
/**
* @builtin PkgQueryProvides
* @short List all package instances providing 'tag'
* @description
* A package instance is itself a list of three items:
*
* - string name: The package name
*
* - symbol instance: Specifies which instance of the package contains a match.
*
* 'NONE no match
*
* 'INST the installed package
*
* 'CAND the candidate package
*
* 'BOTH both packages
*
* - symbol onSystem: Tells which instance of the package would be available
* on the system, if PkgCommit was called right now. That way you're able to
* tell whether the tag will be available on the system after PkgCommit.
* (e.g. if onSystem != 'NONE && ( onSystem == instance || instance == 'BOTH ))
*
* 'NONE stays uninstalled or is deleted
*
* 'INST the installed one remains untouched
*
* 'CAND the candidate package will be installed
*
* @param string tag
* @return list of all package instances providing 'tag'.
* @usage Pkg::PkgQueryProvides( string tag ) -> [ [string, symbol, symbol], [string, symbol, symbol], ...]
*/
YCPList
PkgFunctions::PkgQueryProvides( const YCPString& tag )
{
YCPList ret;
std::string name = tag->value();
zypp::Capability cap(name, zypp::ResKind::package);
zypp::sat::WhatProvides possibleProviders(cap);
for_(iter, possibleProviders.begin(), possibleProviders.end())
{
zypp::PoolItem provider = zypp::ResPool::instance().find(*iter);
// cast to Package object
zypp::Package::constPtr package = zypp::asKind<zypp::Package>(provider.resolvable());
if (!package)
{
y2internal("Casting to Package failed!");
continue;
}
std::string pkgname = package->name();
// get instance status
bool installed = provider.status().staysInstalled();
std::string instance;
# warning Status `NONE and `INST is not supported
// TODO FIXME the other values??
if (installed)
{
instance = "BOTH";
}
else
{
instance = "CAND";
}
// get status on the system
bool uninstalled = provider.status().staysUninstalled() || provider.status().isToBeUninstalled();
std::string onSystem;
if (uninstalled)
{
onSystem = "NONE";
}
else if (installed)
{
onSystem = "INST";
}
else
{
onSystem = "CAND";
}
// create list item
YCPList item;
item->add(YCPString(pkgname));
item->add(YCPSymbol(instance));
item->add(YCPSymbol(onSystem));
// add the item to the result
ret->add(item);
}
return ret;
}
///////////////////////////////////////////////////////////////////
/******************************************************************
**
**
** FUNCTION NAME : join
** FUNCTION TYPE : string
*/
inline std::string join( const std::list<std::string> & lines_r, const std::string & sep_r = "\n" )
{
std::string ret;
std::list<std::string>::const_iterator it = lines_r.begin();
if ( it != lines_r.end() ) {
ret = *it;
for( ++it; it != lines_r.end(); ++it ) {
ret += sep_r + *it;
}
}
return ret;
}
// ------------------------
/**
* @builtin PkgMediaNames
* @short Return names of sources
* @return list< list<any> > Names and ids of Sources
* @usage Pkg::PkgMediaNames () -> [ ["source_1_name", source_1_id] , ["source_2_name", source_2_id], ...]
*/
YCPValue
PkgFunctions::PkgMediaNames ()
{
YCPList res;
RepoId index = 0;
// for all enabled sources
for( RepoCont::const_iterator repoit = repos.begin();
repoit != repos.end(); ++repoit,++index)
{
if ((*repoit)->repoInfo().enabled() && !(*repoit)->isDeleted())
{
try
{
std::string repo_name = (*repoit)->repoInfo().name();
YCPList src_desc;
if (repo_name.empty())
{
y2warning("Name of repository '%lld' is empty, using URL", index);
// use URL as the product name
std::string name((*repoit)->repoInfo().url().asString());
// use alias if url is unknown
if (name.empty())
{
name = (*repoit)->repoInfo().alias();
}
src_desc->add( YCPString( name ));
src_desc->add( YCPInteger( index ) );
res->add( src_desc );
}
else
{
src_desc->add( YCPString( repo_name ));
src_desc->add( YCPInteger( index ) );
res->add( src_desc );
}
}
catch (...)
{
return res;
}
}
}
y2milestone( "Pkg::PkgMediaNames result: %s", res->toString().c_str());
return res;
}
YCPValue
PkgFunctions::PkgMediaSizesOrCount (bool sizes, bool download_size)
{
// all enabled sources
std::list<RepoId> source_ids;
RepoId index = 0;
for(RepoCont::const_iterator it = repos.begin(); it != repos.end() ; ++it, ++index)
{
// ignore disabled or delted sources
if (!(*it)->repoInfo().enabled() || (*it)->isDeleted())
continue;
source_ids.push_back(index);
}
// map SourceId -> [ number_of_media, total_size ]
std::map<RepoId, std::vector<zypp::ByteCount> > result;
// map alias -> SourceID
std::map<std::string, RepoId> source_map;
// initialize the structures
for( std::list<RepoId>::const_iterator sit = source_ids.begin();
sit != source_ids.end(); ++sit, ++index)
{
RepoId id = *sit;
YRepo_Ptr repo = logFindRepository(id);
if (!repo)
continue;
// we don't know the number of media in advance
// the vector is dynamically resized during package search
result[id] = std::vector<zypp::ByteCount>();
source_map[ repo->repoInfo().alias() ] = id;
}
for (zypp::ResPoolProxy::const_iterator it = zypp_ptr()->poolProxy().byKindBegin(zypp::ResKind::package);
it != zypp_ptr()->poolProxy().byKindEnd(zypp::ResKind::package);
++it)
{
if ((*it)->fate() == zypp::ui::Selectable::TO_INSTALL)
{
zypp::Package::constPtr pkg = zypp::asKind<zypp::Package>((*it)->candidateObj().resolvable());
if (!pkg)
continue;
unsigned int medium = pkg->mediaNr();
if (medium == 0)
{
medium = 1;
}
if (medium > 0)
{
zypp::ByteCount size = sizes ? (download_size ? pkg->downloadSize() : pkg->installSize()) : zypp::ByteCount(1); //count only
// refence to the found media array
std::vector<zypp::ByteCount> &ref = result[source_map[pkg->repoInfo().alias()]];
int add_count = (medium - 1) - ref.size() + 1;
// resize media array - the found index is out of array
if (add_count > 0)
{
ref.insert(ref.end(), add_count, zypp::ByteCount(0));
}
ref[medium - 1] += size ; // media are numbered from 1
}
}
}
YCPList res;
for(std::map<RepoId, std::vector<zypp::ByteCount> >::const_iterator it =
result.begin(); it != result.end() ; ++it)
{
const std::vector<zypp::ByteCount> &values = it->second;
YCPList source;
for( unsigned i = 0 ; i < values.size() ; i++ )
{
source->add( YCPInteger( values[i] ) );
}
res->add( source );
}
y2milestone( "Pkg::%s result: %s", sizes ? (download_size ? "PkgMediaPackageSizes" : "PkgMediaSizes" ): "PkgMediaCount", res->toString().c_str());
return res;
}
// ------------------------
/**
* @builtin PkgMediaSizes
* @short Return size of packages to be installed
* @description
* return cumulated sizes (in bytes !) to be installed from different sources and media
*
* Returns the install size, not the archivesize !!
*
* @return list<list<integer>>
* @usage Pkg::PkgMediaSizes () -> [ [src1_media_1_size, src1_media_2_size, ...], ..]
*/
YCPValue
PkgFunctions::PkgMediaSizes()
{
return PkgMediaSizesOrCount (true);
}
// ------------------------
/**
* @builtin PkgMediaPackageSizes
* @short Return size of packages to be installed
* @description
* return cumulated sizes (in bytes !) to be installed from different sources and media
*
* Returns the archive sizes!
*
* @return list<list<integer>>
* @usage Pkg::PkgMediaPackageSizes () -> [ [src1_media_1_size, src1_media_2_size, ...], ..]
*/
YCPValue
PkgFunctions::PkgMediaPackageSizes()
{
return PkgMediaSizesOrCount (true, true);
}
// ------------------------
/**
* @builtin PkgMediaCount
* @short Return number of packages to be installed
* @description
* return number of packages to be installed from different sources and media
*
* @return list<list<integer>>
* @usage Pkg::PkgMediaCount() -> [ [src1_media_1_count, src1_media_2_count, ...], ...]
*/
YCPValue
PkgFunctions::PkgMediaCount()
{
return PkgMediaSizesOrCount (false);
}
// ------------------------
/**
* @builtin IsProvided
*
* @short returns 'true' if the tag is provided by a package in the installed system
* @description
* tag can be a package name, a string from requires/provides
* or a file name (since a package implictly provides all its files)
*
* @param string tag
* @return boolean
* @usage Pkg::IsProvided ("glibc") -> true
*/
YCPValue
PkgFunctions::IsProvided (const YCPString& tag)
{
std::string name = tag->value ();
if (name.empty())
return YCPBoolean (false);
// look for packages
zypp::Capability cap(name, zypp::ResKind::package);
zypp::sat::WhatProvides possibleProviders(cap);
for_(iter, possibleProviders.begin(), possibleProviders.end())
{
zypp::PoolItem provider = zypp::ResPool::instance().find(*iter);
// is it installed?
if (provider.status().isInstalled())
{
y2milestone("Tag %s is provided by %s", name.c_str(), provider->name().c_str());
return YCPBoolean(true);
}
}
y2milestone("Tag %s is not provided", name.c_str());
return YCPBoolean(false);
}
// ------------------------
/**
* @builtin IsSelected
* @short returns a 'true' if the tag is selected for installation
* @description
*
* tag can be a package name, a string from requires/provides
* or a file name (since a package implictly provides all its files)
* @param string tag
* @return boolean
* @usage Pkg::IsSelected ("yast2") -> true
*/
YCPValue
PkgFunctions::IsSelected (const YCPString& tag)
{
std::string name = tag->value ();
if (name.empty())
return YCPBoolean (false);
// look for packages
zypp::Capability cap(name, zypp::ResKind::package);
zypp::sat::WhatProvides possibleProviders(cap);
for_(iter, possibleProviders.begin(), possibleProviders.end())
{
zypp::PoolItem provider = zypp::ResPool::instance().find(*iter);
// is it installed?
if (provider.status().isToBeInstalled())
{
y2milestone("Tag %s provided by %s is selected to install", name.c_str(), provider->name().c_str());
return YCPBoolean(true);
}
}
y2milestone("Tag %s is not selected to install", name.c_str());
return YCPBoolean(false);
}
// ------------------------
/**
* @builtin IsAvailable
* @short Check if package (tag) is available
* @description
* returns a 'true' if the tag is available on any of the currently
* active installation sources. (i.e. it is installable)
* tag can be a package name, a string from requires/provides
* or a file name (since a package implictly provides all its files)
*
* @param string tag
* @return boolean
* @usage Pkg::IsAvailable ("yast2") -> true
*/
YCPValue
PkgFunctions::IsAvailable (const YCPString& tag)
{
std::string name = tag->value ();
if (name.empty())
return YCPBoolean (false);
// look for packages
zypp::Capability cap(name, zypp::ResKind::package);
zypp::sat::WhatProvides possibleProviders(cap);
for_(iter, possibleProviders.begin(), possibleProviders.end())
{
zypp::PoolItem provider = zypp::ResPool::instance().find(*iter);
// is it installed?
if (!provider.status().isInstalled())
{
y2milestone("Tag %s provided by %s is available to install", name.c_str(), provider->name().c_str());
return YCPBoolean(true);
}
}
y2milestone("Tag %s is not available to install", name.c_str());
return YCPBoolean(false);
}
YCPValue
PkgFunctions::searchPackage(const YCPString &package, bool installed)
{
bool found = false;
std::string pkgname = package->value();
if (pkgname.empty())
{
y2warning("Pkg::%s: Package name is empty", installed ? "PkgInstalled" : "PkgAvailable");
return YCPVoid();
}
try
{
zypp::ui::Selectable::Ptr selectable = zypp::ui::Selectable::get(pkgname);
if (selectable)
{
// search installed or available package
if (installed)
{
found = selectable->hasInstalledObj();
}
else
{
found = selectable->hasCandidateObj();
}
}
}
catch (...)
{
y2error("Error in searchPackage");
return YCPVoid();
}
y2milestone("Package '%s' %s: %s", pkgname.c_str(), installed ? "installed" : "available", found ? "true" : "false");
return YCPBoolean(found);
}
/**
* @builtin PkgInstalled
*
* @short returns 'true' if the package is installed in the system
* @param string package name of the package
* @return boolean
* @usage Pkg::PkgInstalled("glibc") -> true
*/
YCPValue
PkgFunctions::PkgInstalled(const YCPString& package)
{
return searchPackage(package, true);
}
// ------------------------
/**
* @builtin PkgAvailable
* @short Check if package is available
* @description
* returns 'true' if the package is available on any of the currently
* active installation sources. (i.e. it is installable)
*
* @param string package name of the package
* @return boolean
* @usage Pkg::PkgAvailable("yast2") -> true
*/
YCPValue
PkgFunctions::PkgAvailable(const YCPString& package)
{
return searchPackage(package, false);
}
// ------------------------
/**
@builtin DoProvide
@short Install a list of packages to the system
@description
Provides (read: installs) a list of tags to the system
tag is a package name
returns a map of tag,reason pairs if tags could not be provided.
Usually this map should be empty (all required packages are
installed)
If tags could not be provided (due to package install failures or
conflicts), the tag is listed as a key and the value describes
the reason for the failure (as an already translated string).
@param list tags
@return map
*/
YCPValue
PkgFunctions::DoProvide (const YCPList& tags)
{
YCPMap ret;
if (tags->size() > 0)
{
for (int i = 0; i < tags->size(); ++i)
{
if (tags->value(i)->isString())
{
YCPString package_name = tags->value(i)->asString();
zypp::ui::Selectable::Ptr s = zypp::ui::Selectable::get(package_name->value());
if (s)
{
if (!s->setToInstall(whoWantsIt))
{
// error message
ret->add(package_name, YCPString(_("The package cannot be selected to install.")));
}
}
else
{
// error message
ret->add(package_name, YCPString(_("The package is not available.")));
}
}
else
{
y2error ("Pkg::DoProvide not string '%s'", tags->value(i)->toString().c_str());
}
}
}
return ret;
}
// ------------------------
/**
@builtin DoRemove
@short Removes a list of packges from the system
@description
tag is a package name
@param list tags
@return map Result - returns empty map for comaptibility reasons
*/
YCPValue
PkgFunctions::DoRemove (const YCPList& tags)
{
YCPMap ret;
if (tags->size() > 0)
{
for (int i = 0; i < tags->size(); ++i)
{
if (tags->value(i)->isString())
{
zypp::ui::Selectable::Ptr s = zypp::ui::Selectable::get(tags->value(i)->asString()->value());
if (s)
{
s->setToDelete(whoWantsIt);
}
}
else
{
y2error ("Pkg::DoRemove not string at position %d: '%s'", i, tags->value(i)->toString().c_str());
}
}
}
return ret;
}
// ------------------------
struct ItemMatch
{
zypp::PoolItem item;
bool operator() (const zypp::PoolItem i )
{
item = i;
return false;
}
};
static zypp::Package::constPtr find_package(const string &name)
{
if (name.empty())
return NULL;
zypp::ui::Selectable::Ptr s = zypp::ui::Selectable::get(name);
if (s)
{
return zypp::asKind<zypp::Package>(s->theObj().resolvable());
}
return NULL;
}
static zypp::ui::Selectable::Ptr find_selectable_product(const string &name)
{
if (name.empty())
return NULL;
using zypp::ui::Selectable;
Selectable::Ptr selectable = Selectable::get( zypp::ResKind::product, name );
if (!selectable)
y2warning("Product '%s' not found", name.c_str());
return selectable;
}
/**
@builtin PkgSummary
@short Get summary (aka label) of a package
@param string package
@return string Summary
@usage Pkg::PkgSummary (string package) -> "This is a nice package"
*/
YCPValue
PkgFunctions::PkgSummary (const YCPString& p)
{
try
{
zypp::Package::constPtr pkg = find_package(p->value());
if (pkg == NULL)
{
return YCPVoid();
}
return YCPString(pkg->summary());
}
catch (...)
{
}
return YCPVoid();
}
// ------------------------
/**
@builtin PkgVersion
@short Get version (better: edition) of a package
@param string package
@return string
@usage Pkg::PkgVersion (string package) -> "1.42-39"
*/
YCPValue
PkgFunctions::PkgVersion (const YCPString& p)
{
try
{
zypp::Package::constPtr pkg = find_package(p->value());
if (pkg == NULL)
{
return YCPVoid();
}
return YCPString( pkg->edition().asString() );
}
catch (...)
{
}
return YCPVoid();
}
// ------------------------
/**
@builtin PkgSize
@short Get (installed) size of a package
@param string package
@return integer
@usage Pkg::PkgSize (string package) -> 12345678
*/
YCPValue
PkgFunctions::PkgSize (const YCPString& p)
{
try
{
zypp::Package::constPtr pkg = find_package(p->value());
if (pkg == NULL)
{
return YCPVoid();
}
return YCPInteger( pkg->installSize() );
}
catch (...)
{
}
return YCPVoid();
}
// ------------------------
/**
@builtin PkgGroup
@short Get rpm group of a package
@param string package
@return string
@usage Pkg::PkgGroup (string package) -> string
*/
YCPValue
PkgFunctions::PkgGroup (const YCPString& p)
{
try
{
zypp::Package::constPtr pkg = find_package(p->value());
if (pkg == NULL)
{
return YCPVoid();
}
return YCPString( pkg->group() );
}
catch (...)
{
}
return YCPVoid();
}
YCPValue
PkgFunctions::PkgProp(const zypp::PoolItem &item)
{
YCPMap data;
zypp::Package::constPtr pkg = zypp::asKind<zypp::Package>(item.resolvable());
if (pkg == NULL) {
y2error("NULL pkg");
return YCPVoid();
}
data->add( YCPString("arch"), YCPString( pkg->arch().asString() ) );
data->add( YCPString("medianr"), YCPInteger( pkg->mediaNr() ) );
long long sid = logFindAlias(pkg->repoInfo().alias());
y2debug("srcId: %lld", sid );
data->add( YCPString("srcid"), YCPInteger( sid ) );
std::string status("available");
if (item.status().isInstalled())
{
status = "installed";
}
else if (item.status().isToBeInstalled())
{
status = "selected";
}
else if (item.status().isToBeUninstalled())
{
status = "removed";
}
data->add( YCPString("status"), YCPSymbol(status));
data->add(YCPString("on_system_by_user"), YCPBoolean(item.satSolvable().onSystemByUser()));
data->add( YCPString("location"), YCPString( pkg->location().filename().basename() ) );
data->add( YCPString("path"), YCPString( pkg->location().filename().asString() ) );
return data;
}
// ------------------------
/**
* @builtin PkgProperties
* @short Return information about a package
* @description
* Return Data about package location, source, which
* media contains the package and who has installed.
*
* <code>
* $["medianr" :integer
* "arch" :string
* "srcid" :integer
* "status" :symbol
* "on_system_by_user":boolean
* "location" :string
* "path" :string
* ]
* </code>
* @param package name
* @usage Pkg::PkgProperties (string package) -> map
*/
YCPValue
PkgFunctions::PkgProperties (const YCPString& p)
{
if (p.isNull())
{
return YCPVoid();
}
try
{
zypp::ui::Selectable::Ptr s = zypp::ui::Selectable::get(p->value());
if (s)
{
return PkgProp(s->theObj());
}
}
catch (...)
{
}
return YCPVoid();
}
YCPValue
PkgFunctions::PkgPropertiesAll (const YCPString& p)
{
std::string pkgname = p->value();
YCPList data;
if (!pkgname.empty())
{
zypp::ui::Selectable::Ptr s = zypp::ui::Selectable::get(pkgname);
if (s)
{
// iterate over installed packages
for_(inst_it, s->installedBegin(), s->installedEnd())
{
data->add(PkgProp(*inst_it));
}
// iterate over available packages
for_(avail_it, s->availableBegin(), s->availableEnd())
{
data->add(PkgProp(*avail_it));
}
}
}
return data;
}
/* helper function */