check_config function
This commit is contained in:
parent
dc76c9e6f8
commit
2423a6d942
13
Database.pm
13
Database.pm
@ -1,15 +1,16 @@
|
||||
package Database;
|
||||
|
||||
use DBI;
|
||||
use GPG;
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
|
||||
# Get home dir
|
||||
my $home = $ENV{HOME};
|
||||
my $home = $ENV->{HOME};
|
||||
|
||||
my $self = {
|
||||
_home => $home;
|
||||
_home => $home,
|
||||
};
|
||||
|
||||
bless $self, $class;
|
||||
@ -27,7 +28,7 @@ sub connect {
|
||||
}
|
||||
|
||||
sub mdo {
|
||||
my ($self) = @_;
|
||||
my ($self, $query, $type) = @_;
|
||||
my $dbh = $self->{_dbh};
|
||||
}
|
||||
|
||||
@ -37,7 +38,7 @@ sub create_base {
|
||||
my $pm_dir = $home."/.PM/";
|
||||
|
||||
# Check dir
|
||||
if !(-d $pm_dir) {
|
||||
if (!(-d $pm_dir)) {
|
||||
# Create dirrectory
|
||||
@mkdir_cmd = ("mkdir", "$pm_dir");
|
||||
system(@mkdir_cmd) == 0 or die "Cannot create dir $pm_dir: $!\n";
|
||||
@ -50,6 +51,10 @@ sub create_base {
|
||||
my $dbh = DBI->connect("dbi:SQLite:dbname=$pm_dir/db.sqlite","","");
|
||||
print "Create database schema\n";
|
||||
my $q_table = "create table passwords(name VARCHAR(32), resource TEXT, password TEXT)";
|
||||
$dbh->do($q_table);
|
||||
|
||||
# Encrypt db
|
||||
# TODO: write this
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
27
Password.pm
27
Password.pm
@ -6,15 +6,38 @@ use utf8;
|
||||
|
||||
use Database;
|
||||
|
||||
use PasswordSave;
|
||||
use PasswordShow;
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
|
||||
my $db = Database->new();
|
||||
|
||||
my $p_save = PasswordSave->new();
|
||||
my $p_show = PasswordShow->new();
|
||||
|
||||
my $self = {
|
||||
_home => $home,
|
||||
_db => $db,
|
||||
_p_save => $p_save,
|
||||
_p_show => $p_show,
|
||||
};
|
||||
|
||||
bless $self, $class;
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
||||
# Check configuration. If it doesn't exist create it.
|
||||
sub check_config {
|
||||
my ($self) = @_;
|
||||
if (-e $ENV->{HOME}."/.PM/db.sqlite") {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
my $db = $self->{_db};
|
||||
$db->create_base();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
1;
|
8
pm.pl
8
pm.pl
@ -3,7 +3,7 @@
|
||||
use Password;
|
||||
use Getopt::Std;
|
||||
|
||||
our $VERSION = '0.0.0a';
|
||||
our $VERSION = '0.0.0b';
|
||||
|
||||
# Debug
|
||||
use Data::Dumper;
|
||||
@ -53,4 +53,8 @@ sub init() {
|
||||
}
|
||||
|
||||
# Parse cmd line
|
||||
init();
|
||||
init();
|
||||
|
||||
my $pass = Password->new();
|
||||
# Don't use it's before GPG and Database
|
||||
# $pass->check_config() == 0 or die "$!\n";
|
Loading…
Reference in New Issue
Block a user